diff --git a/readme.md b/readme.md index da5d06e..688597c 100644 --- a/readme.md +++ b/readme.md @@ -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(); ``` diff --git a/src/Spotify.php b/src/Spotify.php index 1435f59..94f0de4 100644 --- a/src/Spotify.php +++ b/src/Spotify.php @@ -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. * @@ -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. * diff --git a/tests/Unit/SearchTest.php b/tests/Unit/SearchTest.php index 7e54221..d7ced27 100644 --- a/tests/Unit/SearchTest.php +++ b/tests/Unit/SearchTest.php @@ -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'; @@ -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';