Skip to content

Commit

Permalink
Update Search API with Episodes and Shows
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni committed May 14, 2020
1 parent 15a085d commit eb5aeea
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,15 @@ Spotify::searchAlbums('query')->get();
// Search artists by query.
Spotify::searchArtists('query')->get();

// Search episodes by query.
Spotify::searchEpisodes('query')->get();

// Search playlists by query.
Spotify::searchPlaylists('query')->get();

// Search shows by query.
Spotify::searchShows('query')->get();

// Search tracks by query.
Spotify::searchTracks('query')->get();
```
Expand Down
44 changes: 44 additions & 0 deletions src/Spotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,28 @@ public function searchArtists(string $query): PendingRequest
return new PendingRequest($endpoint, $acceptedParams);
}

/**
* Get Spotify Catalog information about episodes that match a keyword string.
*
* @param string $query
* @return PendingRequest
*/
public function searchEpisodes(string $query): PendingRequest
{
$endpoint = '/search/';

$acceptedParams = [
'q' => $query,
'type' => 'episode',
'market' => $this->defaultConfig['market'],
'limit' => null,
'offset' => null,
'include_external' => null,
];

return new PendingRequest($endpoint, $acceptedParams);
}

/**
* Get Spotify Catalog information about playlists that match a keyword string.
*
Expand All @@ -446,6 +468,28 @@ public function searchPlaylists(string $query): PendingRequest
return new PendingRequest($endpoint, $acceptedParams);
}

/**
* Get Spotify Catalog information about shows that match a keyword string.
*
* @param string $query
* @return PendingRequest
*/
public function searchShows(string $query): PendingRequest
{
$endpoint = '/search/';

$acceptedParams = [
'q' => $query,
'type' => 'show',
'market' => $this->defaultConfig['market'],
'limit' => null,
'offset' => null,
'include_external' => null,
];

return new PendingRequest($endpoint, $acceptedParams);
}

/**
* Get Spotify Catalog information about tracks that match a keyword string.
*
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ public function test_can_search_for_artists(): void
$this->assertEquals(20, $artists['artists']['offset']);
}

public function test_can_search_for_episodes(): void
{
$query = 'Worship';

$episodes = Spotify::searchEpisodes($query)->limit(10)->offset(20)->get();
$episodeName = $episodes['episodes']['items'][0]['name'];

$this->assertStringContainsStringIgnoringCase($query, $episodeName);
$this->assertCount(10, $episodes['episodes']['items']);
$this->assertEquals(20, $episodes['episodes']['offset']);
}

public function test_can_search_for_playlists(): void
{
$query = 'Worship';
Expand All @@ -77,6 +89,18 @@ public function test_can_search_for_playlists(): void
$this->assertEquals(5, $playlists['playlists']['offset']);
}

public function test_can_search_for_shows(): void
{
$query = 'Worship';

$shows = Spotify::searchShows($query)->limit(10)->offset(20)->get();
$showName = $shows['shows']['items'][0]['name'];

$this->assertStringContainsStringIgnoringCase($query, $showName);
$this->assertCount(10, $shows['shows']['items']);
$this->assertEquals(20, $shows['shows']['offset']);
}

public function test_can_search_for_tracks(): void
{
$query = 'Tremble';
Expand Down

0 comments on commit eb5aeea

Please sign in to comment.