/** * Output JSON info about the video. * * @param Request $request PSR-7 request * @param Response $response PSR-7 response * * @return Response HTTP response */ public function json(Request $request, Response $response) { $params = $request->getQueryParams(); if (isset($params['url'])) { try { $video = $this->download->getJSON($params['url']); return $response->withJson($video); } catch (\Exception $e) { return $response->withJson(['success' => false, 'error' => $e->getMessage()]); } } }
/** * Test getJSON function errors. * * @param string $url URL * * @return void * @expectedException Exception * @dataProvider ErrorURLProvider */ public function testGetJSONError($url) { $videoURL = $this->download->getJSON($url); }
/** * Output JSON info about the video * @return void */ static function json() { global $app; if (isset($_GET["url"])) { $app->response->headers->set('Content-Type', 'application/json'); try { $video = VideoDownload::getJSON($_GET["url"]); echo json_encode($video); } catch (\Exception $e) { echo json_encode(array('success' => false, 'error' => $e->getMessage())); } } }
/** * Test getJSON function errors * * @param string $url URL * * @return void * @expectedException Exception * @dataProvider ErrorURLProvider */ public function testGetJSONError($url) { $videoURL = VideoDownload::getJSON($url); }