/**
  * Get the forum board of MAL.
  *
  * @return View
  */
 public function getForumBoardAction()
 {
     // http://myanimelist.net/forum/
     $downloader = $this->get('atarashii_api.communicator');
     try {
         $forumcontent = $downloader->fetch('/forum/index.php');
     } catch (Exception\CurlException $e) {
         return $this->view(array('error' => 'network-error'), 500);
     }
     $forumboard = ForumParser::parseBoard($forumcontent);
     $response = new Response();
     $response->setPublic();
     $response->setMaxAge(86400);
     //One day
     $response->headers->addCacheControlDirective('must-revalidate', true);
     $response->setEtag('forum/board');
     //Also, set "expires" header for caches that don't understand Cache-Control
     $date = new \DateTime();
     $date->modify('+86400 seconds');
     //One day
     $response->setExpires($date);
     $view = $this->view($forumboard);
     $view->setResponse($response);
     $view->setStatusCode(200);
     return $view;
 }
Esempio n. 2
0
 public function testParseBoard()
 {
     $forumIndexContent = file_get_contents(__DIR__ . '/../InputSamples/forum-index.html');
     $forumIndex = ForumParser::parseBoard($forumIndexContent);
     $this->assertInternalType('array', $forumIndex);
     //Sections are indexed by name, not integer
     //Pick the "MyAnimeList" section, which should be safe for long-term use.
     $forumCategory = $forumIndex['MyAnimeList'];
     $this->assertInternalType('array', $forumCategory);
     foreach ($forumCategory as $forumBoard) {
         $this->assertInstanceOf('Atarashii\\APIBundle\\Model\\Forum', $forumBoard);
         if ($forumBoard->getId() == 5) {
             //The main "Updates and Announcements" Board
             $board1 = $forumBoard;
         } elseif ($forumBoard->getId() === null) {
             //A board that has children doesn't have its own ID.
             $board2 = $forumBoard;
         }
     }
     //Do some sanity checking on the main board
     $this->assertInternalType('int', $board1->getId());
     $this->assertInternalType('string', $board1->getName());
     $this->assertInternalType('string', $board1->getDescription());
     //Some sanity checking on the board with kids
     $this->assertNull($board2->getId());
     $this->assertInternalType('string', $board2->getName());
     $this->assertInternalType('string', $board2->getDescription());
     $this->assertInternalType('array', $board2->getChildren());
     foreach ($board2->getChildren() as $boardChild) {
         $this->assertInstanceOf('Atarashii\\APIBundle\\Model\\Forum', $boardChild);
     }
 }