Skip to content

Commit

Permalink
Adds filters for images
Browse files Browse the repository at this point in the history
  • Loading branch information
odannyc committed Aug 24, 2016
1 parent b0041f9 commit d752804
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ public function __construct($config)
$this->client = new Client();
}

public function query($query)
public function query($query, $filters)
{
return $this->client->get($this->config->baseUrl, ['query' => [
$query = [
'q' => $query,
'cx' => $this->config->cx(),
'key' =>$this->config->apiKey(),
'searchType' => 'image'
]])->getBody();
];

foreach ($filters as $key => $filter) {
$query[$key] = $filter;
}

return $this->client->get($this->config->baseUrl, ['query' => $query])->getBody();
}
}
9 changes: 7 additions & 2 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
*/
class Image
{
public static function search($query)
/**
* @param $query
* @param array $filters
* @return mixed
*/
public static function search($query, $filters = [])
{
$http = new Http(Config::instance());

return json_decode((string) $http->query($query), true);
return json_decode((string) $http->query($query, $filters), true);
}
}
5 changes: 3 additions & 2 deletions src/ImageSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ class ImageSearch
* Used to search for images.
*
* @param $query
* @param $filters
* @return mixed
*/
public static function search($query)
public static function search($query, $filters = [])
{
return Image::search($query);
return Image::search($query, $filters);
}

/**
Expand Down

0 comments on commit d752804

Please sign in to comment.