Skip to content

Commit

Permalink
Merge pull request #5 from Martin1982/filter-search
Browse files Browse the repository at this point in the history
Allow searching through specific object types
  • Loading branch information
PouleR authored Dec 8, 2022
2 parents 1fd5d6b + 18fab14 commit 690b6cd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/DeezerAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,13 @@ public function addPlaylistToFavorites($playlistId)
* @param string $query
* @param bool $strict
* @param string|null $order
* @param string|null $type
*
* @return array|object
*
* @throws DeezerAPIException
*/
public function search(string $query, bool $strict = false, string $order = null): object|array
public function search(string $query, bool $strict = false, string $order = null, ?string $type = null): object|array
{
if (empty($query)) {
throw new DeezerAPIException('A query parameter is mandatory');
Expand All @@ -250,6 +251,11 @@ public function search(string $query, bool $strict = false, string $order = null
$apiQuery['order'] = $order;
}

return $this->client->apiRequest('GET', 'search', [], null, $apiQuery);
$endpoint = 'search';
if (null !== $type) {
$endpoint.= '/'.urlencode($type);
}

return $this->client->apiRequest('GET', $endpoint, [], null, $apiQuery);
}
}
12 changes: 12 additions & 0 deletions tests/DeezerAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,16 @@ public function testSearch(): void
->willReturn([]);
$this->deezerApi->search('bohemian', true, 'RANKING');
}

/**
* @throws DeezerAPIException
*/
public function testSearchArtist(): void
{
$this->client->expects(static::once())
->method('apiRequest')
->with('GET', 'search/artist', [], null, ['q' => 'bohemian', 'strict' => 'on', 'order' => 'RANKING'])
->willReturn([]);
$this->deezerApi->search('bohemian', true, 'RANKING', 'artist');
}
}

0 comments on commit 690b6cd

Please sign in to comment.