/**
  * Get the messages list.
  *
  * @param Request $request HTTP Request object
  *
  * @internal param int $page The pagenumber assigned by MAL.
  *
  * @return View
  */
 public function getAction(Request $request)
 {
     // http://myanimelist.net/mymessages.php?go=&show=#{page}
     $downloader = $this->get('atarashii_api.communicator');
     $page = (int) $request->query->get('page');
     if ($page <= 0) {
         $page = 1;
     }
     //get the credentials we received
     $username = $this->getRequest()->server->get('PHP_AUTH_USER');
     $password = $this->getRequest()->server->get('PHP_AUTH_PW');
     try {
         if (!$downloader->cookieLogin($username, $password)) {
             $view = $this->view(array('error' => 'unauthorized'), 401);
             $view->setHeader('WWW-Authenticate', 'Basic realm="myanimelist.net"');
             return $view;
         }
         Date::setTimeZone($downloader->fetch('/editprofile.php'));
         $messagesdetails = $downloader->fetch('/mymessages.php?go=&show=' . ($page * 20 - 20));
     } catch (Exception\CurlException $e) {
         return $this->view(array('error' => 'network-error'), 500);
     }
     if (strpos($messagesdetails, 'You have 0 messages') !== false) {
         return $this->view(array('error' => 'No messages found.'), 404);
     } else {
         $messages = MessagesParser::parse($messagesdetails);
         $response = new Response();
         $view = $this->view($messages);
         $view->setResponse($response);
         $view->setStatusCode(200);
         return $view;
     }
 }
예제 #2
0
 public function testTZ()
 {
     $editProfileContents = file_get_contents(__DIR__ . '/../InputSamples/editprofile.html');
     Date::setTimeZone($editProfileContents);
     $expected = 'Asia/Tokyo';
     $this->assertEquals($expected, Date::$timeZone);
 }
 /**
  * Get the watching history of an anime or manga.
  *
  * @param int    $id          The ID of the anime or manga as assigned by MyAnimeList
  * @param string $requestType The anime or manga request string
  *
  * @return View
  */
 public function getHistoryAction($id, $requestType)
 {
     // http://myanimelist.net/ajaxtb.php?detailedaid=#{id}
     // http://myanimelist.net/ajaxtb.php?detailedmid=#{id}
     $downloader = $this->get('atarashii_api.communicator');
     //get the credentials we received
     $username = $this->getRequest()->server->get('PHP_AUTH_USER');
     $password = $this->getRequest()->server->get('PHP_AUTH_PW');
     //Don't bother making a request if the user didn't send any authentication
     if ($username === null || $password === null || $username === '' || $password === '') {
         $view = $this->view(array('error' => 'unauthorized'), 401);
         $view->setHeader('WWW-Authenticate', 'Basic realm="myanimelist.net"');
         return $view;
     }
     try {
         if (!$downloader->cookieLogin($username, $password)) {
             $view = $this->view(array('error' => 'unauthorized'), 401);
             $view->setHeader('WWW-Authenticate', 'Basic realm="myanimelist.net"');
             return $view;
         }
     } catch (Exception\CurlException $e) {
         return $this->view(array('error' => 'network-error'), 500);
     }
     try {
         if ($requestType === 'anime') {
             $content = $downloader->fetch('/ajaxtb.php?detailedaid=' . $id);
         } else {
             $content = $downloader->fetch('/ajaxtb.php?detailedmid=' . $id);
         }
         Date::setTimeZone($downloader->fetch('/editprofile.php'));
     } catch (Exception\CurlException $e) {
         return $this->view(array('error' => 'network-error'), 500);
     } catch (Exception\ClientErrorResponseException $e) {
         $content = $e->getResponse();
     }
     if (strpos($content, 'Not logged in') !== false) {
         $view = $this->view(array('error' => 'unauthorized'), 401);
         $view->setHeader('WWW-Authenticate', 'Basic realm="myanimelist.net"');
         return $view;
     } else {
         $result = HistoryParser::parse($content, $id, $requestType);
         $view = $this->view($result);
         $view->setResponse(new Response());
         $view->setStatusCode(200);
     }
     return $view;
 }