joedawson / amazon-ecs

With Laravel, search and lookup Amazon products easily.
MIT License
52 stars 26 forks source link

Add page attribute to search #14

Closed robertem128 closed 7 years ago

robertem128 commented 7 years ago

Hi,

I needed to include the ability to add pagination to my Amazon search results, I'm not sure my method is the best way but it is working for my use case (basically just submitting an optional "page" attribute with the request). I can submit a pull request, but this might be too much of a "quick and dirty" approach (code below).

Thanks for your work on this package btw, it was really helpful in my project.

public function search($query, $page = 1)
    {
        $query      = rawurlencode($query);
        if ($page == 1) {
            $params     = $this->params(['Keywords' => $query, 'SearchIndex' => 'All', 'ResponseGroup' => $this->response_group]);
        } else {
            $params     = $this->params(['Keywords' => $query, 'SearchIndex' => 'All', 'ResponseGroup' => $this->response_group, 'ItemPage'=>$page]);
        }
        $string     = $this->buildString($params);
        $signature  = $this->signString($string);
        $url        = $this->url($params, $signature);

        try {
            $this->response = $this->client->get($url)->getBody();
            return $this;
        } catch(ClientException $e) {
            return $e->getResponse();
        }
    }
joedawson commented 7 years ago

Could you submit a PR if you have the time? Thanks @robertem128.