function testLinkParsing()
 {
     $firstPage = 2;
     $lastPage = 10;
     $linkHeaders = ['<https://api.github.com/repositories/448045/tags?page=2>; rel="next", <https://api.github.com/repositories/448045/tags?page=10>; rel="last"'];
     $paginator = new GithubPaginator($linkHeaders);
     $this->assertEquals("https://api.github.com/repositories/448045/tags?page={$firstPage}", $paginator->nextLink->url);
     $this->assertEquals("https://api.github.com/repositories/448045/tags?page={$lastPage}", $paginator->lastLink->url);
     $pageRange = $paginator->getPageRange();
     $this->assertCount(2, $pageRange);
     $this->assertEquals($firstPage, $pageRange[0]);
     $this->assertEquals($lastPage, $pageRange[1]);
 }
 public function createFromResponse(Response $response, Operation $operation, $class)
 {
     $data = $this->extractData($response);
     if (array_key_exists('error_description', $data) === true) {
         throw new GithubArtaxServiceException($response, "Error in response: " . $data['error_description']);
     }
     $instance = $this->instantiateClass($class, $data);
     //Header based information needs to be added after the array
     //Some of the data is embedded in a header.
     // X-OAuth-Scopes lists the scopes your token has authorized.
     // X-Accepted-OAuth-Scopes lists the scopes that the action checks for.
     if ($response->hasHeader('X-OAuth-Scopes')) {
         $oauthHeaderValues = $response->getHeader('X-OAuth-Scopes');
         $oauthScopes = [];
         foreach ($oauthHeaderValues as $oauthHeaderValue) {
             $oauthScopes = explode(', ', $oauthHeaderValue);
         }
         $instance->oauthScopes = $oauthScopes;
     }
     $pager = GithubPaginator::constructFromResponse($response);
     if ($pager) {
         $instance->pager = $pager;
     }
     return $instance;
 }
 public function displayAndSaveLinks(\ArtaxServiceBuilder\Service\GithubPaginator $pager)
 {
     $links = $pager->getLinks();
     foreach ($links as $link) {
         $storedLink = new StoredLink($link);
         printf("<a href='/github/index.php?action=showMoreResults&resultKey=%s'>%s</a><br/>", $storedLink->getKey(), $link->description);
     }
 }