/**
  * Helper function to call the Google Books API directly and return results.
  * This is used for tests written for the VolumeLookupManager.
  *
  * @param VolumeSearchQuery $query
  */
 private function callApi(VolumeSearchQuery $query)
 {
     /** @var Response $response */
     $response = $this->volume_search->volumesList($query);
     $this->assertEquals(200, $response->getStatusCode());
     $json = (string) $response->getBody();
     return json_decode($json, true);
 }
 /**
  * Lookup volumes based on the provided parameters. Returns a Volumes object.
  * Function calls the API recursively to retrieve all volumes based on the query parameters.
  *
  * The recursiveness of the function depend on the $count parameter as API only returns a maximum of 40 results
  * at once, for ex: using a 80 as $count would recursively call the API twice. Therefore the value of the
  * $count variable contribute to how long this function would run.
  *
  * @param VolumeSearchQuery        $query
  * @param int                      $start_index
  * @param int                      $count
  * @param OrderByEnum|null         $order_by
  * @param bool                     $downloadable
  * @param VolumeFilterEnum|null    $filter
  * @param string                   $language
  * @param PublicationTypeEnum|null $print_type
  * @param ProjectionEnum|null      $projection
  * @param Volumes                  $volumes
  *
  * @return Volumes
  * @throws \Nerdstorm\GoogleBooks\Exception\InvalidJsonException
  */
 public function lookup(VolumeSearchQuery $query, $start_index = 0, $count = VolumesSearch::MAX_RESULTS, OrderByEnum $order_by = null, $downloadable = null, VolumeFilterEnum $filter = null, $language = null, PublicationTypeEnum $print_type = null, ProjectionEnum $projection = null, Volumes $volumes = null)
 {
     if (null === $volumes) {
         $volumes = new Volumes();
     } elseif (count($volumes->getItems()) >= $count) {
         $volumes->setItems(array_slice($volumes->getItems(), 0, $count))->setTotalItems(count($volumes->getItems()));
         return $volumes;
     }
     /** @var Response $response */
     $response = $this->volume_search->volumesList($query, $downloadable, $filter, $language, $start_index, VolumesSearch::MAX_RESULTS, $order_by, $print_type, $projection);
     $json_object = json_decode((string) $response->getBody(), true);
     /** @var Volumes $results */
     $_volumes = $this->annotation_mapper->resolveEntity($json_object);
     $volumes->addItems($_volumes->getItems());
     $start_index += (int) VolumesSearch::MAX_RESULTS;
     if (count($_volumes->getItems()) < VolumesSearch::MAX_RESULTS) {
         $volumes->setItems(array_slice($volumes->getItems(), 0, $count))->setTotalItems(count($volumes->getItems()));
         return $volumes;
     }
     return $this->lookup($query, (int) $start_index, (int) $count, $order_by, $downloadable, $filter, $language, $print_type, $projection, $volumes);
 }