예제 #1
0
 public function testVolumeGetByIdAndProjection()
 {
     // Volume: Systems Analysis and Design
     $volume_id = '2kjxBQAAQBAJ';
     /** @var Response $response */
     // Projection: FULL
     $response = $this->volume_search->volumeGet($volume_id, ProjectionEnum::FULL());
     $this->assertEquals(200, $response->getStatusCode());
     $json = (string) $response->getBody();
     $data = json_decode($json, true);
     $this->assertEquals('application/json; charset=UTF-8', $response->getHeader('Content-Type')[0]);
     $this->assertEquals($data['kind'], 'books#volume');
     $this->assertEquals($data['id'], $volume_id);
     $this->assertArrayHasKey('pageCount', $data['volumeInfo']);
     $this->assertArrayHasKey('categories', $data['volumeInfo']);
     /** @var Response $response */
     // Projection: LITE
     $response = $this->volume_search->volumeGet($volume_id, ProjectionEnum::LITE());
     $this->assertEquals(200, $response->getStatusCode());
     $json = (string) $response->getBody();
     $data = json_decode($json, true);
     $this->assertEquals('application/json; charset=UTF-8', $response->getHeader('Content-Type')[0]);
     $this->assertEquals($data['kind'], 'books#volume');
     $this->assertEquals($data['id'], $volume_id);
     $this->assertArrayNotHasKey('pageCount', $data['volumeInfo']);
     $this->assertArrayNotHasKey('categories', $data['volumeInfo']);
 }
예제 #2
0
 /**
  * Retrieves a Volume resource based on ID.
  *
  * Unique strings given to each volume that Google Books knows about. An example of a volume ID is _LettPDhwR0C.
  * You can use the API to get the volume ID by making a request that returns a Volume resource; you can find the
  * volume ID in its id field.
  *
  * @param string              $volume_id
  * @param ProjectionEnum|null $projection
  * @param string              $source
  *
  * @throws InvalidVolumeIdException
  * @return Volume
  */
 public function volumeGet($volume_id, ProjectionEnum $projection = null, $source = null)
 {
     $query = [];
     if (!$volume_id) {
         throw new InvalidVolumeIdException('Volume ID cannot be empty');
     }
     // Set projection
     if (null !== $projection) {
         $query['projection'] = $projection->value();
     }
     // If restricted by book source
     if (!empty($source)) {
         $query['source'] = $source;
     }
     $api_method = 'volumes/' . urlencode($volume_id);
     return $this->send('get', $api_method, ['query' => $query]);
 }