hnhdigital-os / php-google-books-api

An interface to the Google Books API
MIT License
3 stars 1 forks source link

title() and author() methods overwrite each other in the q param #2

Open andosteinmetz opened 5 years ago

andosteinmetz commented 5 years ago

Hi. I'm evaluating this library for use in a project and I've noticed that the title() and author() methods, rather than appending the value of the q parameter – as per the comments – seem to replace the q parameter entirely with the new key/value pair.

example:

public function searchByKeywords($phrase) {
  $client = new GoogleBooksApi(array('key' => API_KEY));
  $client->author($phrase)->title($phrase)->order('relevance')->take(MAX_RESULTS);
  return $client->get()
}

And the results with "gertrude stein" as the $phrase argument:

...
{
  "paramaters": {
    "country": "US",
    "q": {
      "intitle": "gertrude stein"
    },
    "download": "",
    "filter": "",
    "startIndex": 0,
    "maxResults": 40,
    "printType": "",
    "projection": "",
    "orderBy": "relevance"
  }
}

The results only show books about Gertrude Stein, not those by Gertrude Stein. I would expect the parameters property to look like {"intitle": "gertrude stein", "inauthor: "gertrude stein"} and to get results for both title and author.

Is this the intended behavior or a bug? Or am I missing something?

I can see a work-around by using string concatenation and the search() method, but the interface as described in the comments looks much cleaner.

RoccoHoward commented 5 years ago

Hello!

Sounds like a bug by all accounts. It's been awhile since I've looked at or used this package.

Are you able to make a pull request to fix this or did you need me to have a look?

andosteinmetz commented 5 years ago

I'll make a PR when I find a minute to fix it : )