示例#1
0
 /**
  * Search for a track and build the response objects
  *
  * @param string $string
  *
  * @return Track
  */
 public function findTrack(string $string)
 {
     $result = $this->spotifyWebApi->search($string, 'track');
     if (count($result->tracks->items) === 0) {
         throw NoTracksFoundException::emptyResult();
     }
     $firstItem = $result->tracks->items[0];
     $images = $this->valueObjectBuilder->buildImages($firstItem->album->images);
     $album = $this->valueObjectBuilder->buildAlbumSimplified($firstItem->album, $images);
     $artists = $this->valueObjectBuilder->buildArtistsSimplified($firstItem->artists);
     $track = $this->valueObjectBuilder->buildTrack($firstItem, $album, $artists);
     return $track;
 }
 public function testBuildUserPlaylistResponse()
 {
     $responseMock = json_decode(file_get_contents(__DIR__ . '/response_test_data/user_playlists.json'));
     $result = $this->valueObjectBuilder->buildUserPlaylistResponse($responseMock);
     $this->assertValueObjectPropertyEquals('href', $responseMock, $result);
     $this->assertValueObjectPropertyEquals('limit', $responseMock, $result);
     $this->assertValueObjectPropertyEquals('next', $responseMock, $result);
     $this->assertValueObjectPropertyEquals('offset', $responseMock, $result);
     $this->assertValueObjectPropertyEquals('previous', $responseMock, $result);
     $this->assertTrue(is_array($result->getItems()), 'Response items should be an array');
     $this->assertTrue($result->getItems()[0] instanceof Playlist, 'First response item should be a Playlist');
 }
示例#3
0
 /**
  * Creates a new playlist
  *
  * @param string $name The playlist name
  * @param bool $public
  *
  * @return ValueObject\Playlist
  * @throws SpotifyWebAPIException
  */
 public function createPlaylist($name, $public = true)
 {
     $rawResponse = $this->spotifyWebApi->createUserPlaylist($this->spotifyWebApi->getSpotifyUserId(), ['name' => $name, 'public' => $public]);
     $response = $this->valueObjectBuilder->buildPlaylist($rawResponse);
     return $response;
 }