plex.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="plex"
  5. * )
  6. */
  7. /**
  8. * @OA\Schema(
  9. * schema="plexRegister",
  10. * type="object",
  11. * @OA\Property(
  12. * property="username",
  13. * type="string",
  14. * example="causefx"
  15. * ),@OA\Property(
  16. * property="email",
  17. * type="string",
  18. * example="causefx@organizr.app"
  19. * ),@OA\Property(
  20. * property="password",
  21. * type="string",
  22. * example="iCanHazPa$$w0Rd"
  23. * ),
  24. * )
  25. */
  26. $app->post('/plex/register', function ($request, $response, $args) {
  27. /**
  28. * @OA\Post(
  29. * tags={"plex"},
  30. * path="/api/v2/plex/register",
  31. * summary="Register a user using Plex API",
  32. * @OA\RequestBody(
  33. * description="Success",
  34. * required=true,
  35. * @OA\JsonContent(ref="#/components/schemas/plexRegister"),
  36. * ),
  37. * @OA\Response(
  38. * response="200",
  39. * description="Success",
  40. * @OA\JsonContent(ref="#/components/schemas/status"),
  41. * ),
  42. * @OA\Response(response="401",description="Unauthorized")
  43. * )
  44. */
  45. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  46. if ($Organizr->checkRoute($request)) {
  47. $Organizr->plexJoinAPI($Organizr->apiData($request));
  48. }
  49. $response->getBody()->write(jsonE($GLOBALS['api']));
  50. return $response
  51. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  52. ->withStatus($GLOBALS['responseCode']);
  53. });
  54. $app->get('/plex/servers', function ($request, $response, $args) {
  55. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  56. if ($Organizr->checkRoute($request)) {
  57. if ($Organizr->qualifyRequest(1, true)) {
  58. $Organizr->getPlexServers();
  59. }
  60. }
  61. $response->getBody()->write(jsonE($GLOBALS['api']));
  62. return $response
  63. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  64. ->withStatus($GLOBALS['responseCode']);
  65. });