├── .env.dist ├── .env.enc ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml ├── src ├── API.php ├── Entity │ ├── Album.php │ ├── AlbumCollection.php │ ├── AlbumPagination.php │ ├── Artist.php │ ├── ArtistCollection.php │ ├── Error.php │ ├── Image.php │ ├── ImageCollection.php │ ├── Pagination.php │ ├── Playlist.php │ ├── PlaylistCollection.php │ ├── PlaylistPagination.php │ ├── PlaylistTrack.php │ ├── PlaylistTrackCollection.php │ ├── PlaylistTrackPagination.php │ ├── Track.php │ ├── TrackCollection.php │ ├── TrackPagination.php │ ├── Tracks.php │ └── User.php ├── Exception │ ├── AccessTokenException.php │ └── SpotifyException.php ├── Hydrator │ ├── AlbumAwareHydrator.php │ ├── AlbumCollectionHydrator.php │ ├── AlbumHydrator.php │ ├── ArtistCollectionAwareHydrator.php │ ├── ArtistCollectionHydrator.php │ ├── ArtistHydrator.php │ ├── ErrorHydrator.php │ ├── ImageCollectionAwareHydrator.php │ ├── OwnerAwareHydrator.php │ ├── PaginatedAlbumCollectionHydrator.php │ ├── PaginatedPlaylistCollectionHydrator.php │ ├── PaginatedPlaylistTrackCollectionAwareHydrator.php │ ├── PaginatedPlaylistTrackCollectionHydrator.php │ ├── PaginatedTrackCollectionAwareHydrator.php │ ├── PaginatedTrackCollectionHydrator.php │ ├── PaginationHydrator.php │ ├── PlaylistHydrator.php │ ├── TrackAwareHydrator.php │ ├── TrackCollectionHydrator.php │ ├── TrackHydrator.php │ ├── TracksAwareHydrator.php │ └── UserHydrator.php └── Oauth2 │ └── Client │ └── Provider │ └── Spotify.php └── tests ├── Audeio └── Spotify │ └── APITest.php └── Bootstrap.php /.env.dist: -------------------------------------------------------------------------------- 1 | SPOTIFY_CLIENT_ID= 2 | SPOTIFY_CLIENT_SECRET= 3 | SPOTIFY_REFRESH_TOKEN= 4 | -------------------------------------------------------------------------------- /.env.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonjomckay/spotify-web-api/1efff48b22b94fac67e901944b145e66b5633912/.env.enc -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /composer.lock 3 | /vendor 4 | /atlassian-ide-plugin.xml 5 | /.env 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - 5.4 4 | - 5.5 5 | - 5.6 6 | - hhvm 7 | 8 | before_install: 9 | - openssl aes-256-cbc -K $encrypted_8f1e276d8d98_key -iv $encrypted_8f1e276d8d98_iv 10 | -in .env.enc -out .env -d 11 | 12 | install: 13 | - composer install -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jonjo McKay 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Spotify Web API 2 | =============== 3 | 4 | [![Build Status](https://travis-ci.org/jonjomckay/spotify-web-api.png?branch=develop)](https://travis-ci.org/jonjomckay/spotify-web-api) 5 | 6 | ## Requirements 7 | 8 | * PHP 5.4+ 9 | * An OAuth 2 client ([league/oauth2-client](https://github.com/thephpleague/oauth2-client) works well) 10 | 11 | ## Installation 12 | 13 | 1. Add `"audeio/spotify-web-api": "0.*"` to your `composer.json` 14 | 2. Run `composer update` to update your application with the new dependency 15 | 3. That's all! 16 | 17 | ### Usage 18 | 19 | 1. Instantiate a new instance of `Audeio\Spotify\API` and set the access token retrieved by your OAuth 2 client (a provider for `league/oauth2-client` is included under `Audeio\Spotify\ 20 | Oauth2\Client\Provider\Spotify`): 21 | 22 | ```php 23 | $api = new \Audeio\Spotify\API(); 24 | $api->setAccessToken('BAWSDOJWEO984yt34y35YgdsnhlreGERH56u45htrH54y'); 25 | ``` 26 | 27 | 2. Call all the methods you need! 28 | 29 | ```php 30 | $api->getAlbum('id'); 31 | $api->getAlbums(array('id-1', 'id-2', 'id-3')); 32 | $api->getAlbumTracks('id'); 33 | $api->getArtist('id'); 34 | $api->getArtists(array('id-1', 'id-2', 'id-3')); 35 | $api->getArtistAlbums('id', 'country'); 36 | $api->getArtistRelatedArtists('id'); 37 | $api->getTrack('id'); 38 | $api->getTracks(array('id-1', 'id-2', 'id-3')); 39 | $api->getUserProfile('id'); 40 | $api->getCurrentUser(); 41 | $api->getUserPlaylist('userId', 'id'); 42 | $api->getUserPlaylistTracks('userId', 'id'); 43 | $api->getUserPlaylists('id'); 44 | ``` 45 | 46 | ## License 47 | The MIT License; please see [LICENSE](LICENSE) for more information. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "audeio/spotify-web-api", 3 | "description": "PHP library for the Spotify Web API", 4 | "license": "MIT", 5 | "homepage": "https://github.com/jonjomckay/spotify-web-api", 6 | "prefer-stable": true, 7 | "autoload": { 8 | "psr-4": { 9 | "Audeio\\Spotify\\": "src/" 10 | } 11 | }, 12 | "require": { 13 | "php": ">=5.4", 14 | "guzzle/guzzle": "3.*", 15 | "league/oauth2-client": "~0.6", 16 | "zendframework/zend-filter": "2.*", 17 | "zendframework/zend-eventmanager": "2.*", 18 | "zendframework/zend-servicemanager": "2.*", 19 | "zendframework/zend-stdlib": "2.*", 20 | "doctrine/collections": "1.*" 21 | }, 22 | "require-dev": { 23 | "vlucas/phpdotenv": "1.*", 24 | "phpunit/phpunit": "4.*" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ./tests 4 | 5 | 6 | 7 | 8 | 9 | 10 | ./src 11 | 12 | 13 | ./tests 14 | 15 | 16 | ./vendor 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/API.php: -------------------------------------------------------------------------------- 1 | guzzleClient = new Guzzle\Http\Client(static::$baseUrl); 43 | $this->guzzleClient->setConfig(array( 44 | 'defaults' => array( 45 | 'headers' => array( 46 | 'Content-Type' => 'application/json', 47 | 'Authorization' => sprintf('Bearer %s', $this->accessToken) 48 | ) 49 | ) 50 | )); 51 | } 52 | 53 | /** 54 | * @param string $accessToken 55 | */ 56 | public function setAccessToken($accessToken) 57 | { 58 | $this->accessToken = $accessToken; 59 | 60 | $this->guzzleClient->setDefaultOption( 61 | 'headers/Authorization', 62 | $accessToken ? sprintf('Bearer %s', $accessToken) : null 63 | ); 64 | } 65 | 66 | /** 67 | * @param string $id 68 | * @return Entity\Album 69 | */ 70 | public function getAlbum($id) 71 | { 72 | $response = $this->sendRequest( 73 | $this->guzzleClient->createRequest('GET', sprintf('/v1/albums/%s', $id)) 74 | )->json(); 75 | 76 | $hydrators = new AggregateHydrator(); 77 | $hydrators->add(new Hydrator\AlbumHydrator()); 78 | $hydrators->add(new Hydrator\ArtistCollectionAwareHydrator()); 79 | $hydrators->add(new Hydrator\ImageCollectionAwareHydrator()); 80 | $hydrators->add(new Hydrator\PaginatedTrackCollectionAwareHydrator()); 81 | 82 | return $hydrators->hydrate($response, new Entity\Album()); 83 | } 84 | 85 | /** 86 | * @param array $ids 87 | * @return Entity\AlbumCollection 88 | */ 89 | public function getAlbums(array $ids) 90 | { 91 | $request = $this->guzzleClient->createRequest('GET', '/v1/albums'); 92 | $request->getQuery()->add('ids', implode(',', $ids)); 93 | 94 | $response = $this->sendRequest($request)->json(); 95 | 96 | $hydrators = new AggregateHydrator(); 97 | $hydrators->add(new Hydrator\AlbumCollectionHydrator()); 98 | 99 | return $hydrators->hydrate($response, new Entity\AlbumCollection()); 100 | } 101 | 102 | /** 103 | * @param string $id 104 | * @param int $limit 105 | * @param int $offset 106 | * @return Entity\TrackPagination 107 | */ 108 | public function getAlbumTracks($id, $limit = 20, $offset = 0) 109 | { 110 | $request = $this->guzzleClient->createRequest('GET', sprintf('/v1/albums/%s/tracks', $id)); 111 | $request->getQuery()->add('limit', $limit); 112 | $request->getQuery()->add('offset', $offset); 113 | 114 | $response = $this->sendRequest($request)->json(); 115 | 116 | $hydrators = new AggregateHydrator(); 117 | $hydrators->add(new Hydrator\PaginationHydrator()); 118 | $hydrators->add(new Hydrator\PaginatedTrackCollectionHydrator()); 119 | 120 | return $hydrators->hydrate($response, new Entity\TrackPagination()); 121 | } 122 | 123 | /** 124 | * @param string $id 125 | * @return Entity\Artist 126 | */ 127 | public function getArtist($id) 128 | { 129 | $response = $this->sendRequest( 130 | $this->guzzleClient->createRequest('GET', sprintf('/v1/artists/%s', $id)) 131 | )->json(); 132 | 133 | $hydrators = new AggregateHydrator(); 134 | $hydrators->add(new Hydrator\ArtistHydrator()); 135 | $hydrators->add(new Hydrator\ImageCollectionAwareHydrator()); 136 | 137 | return $hydrators->hydrate($response, new Entity\Artist()); 138 | } 139 | 140 | /** 141 | * @param array $ids 142 | * @return Entity\ArtistCollection 143 | */ 144 | public function getArtists(array $ids) 145 | { 146 | $request = $this->guzzleClient->createRequest('GET', '/v1/artists'); 147 | $request->getQuery()->add('ids', implode(',', $ids)); 148 | 149 | $response = $this->sendRequest($request)->json(); 150 | 151 | $hydrators = new AggregateHydrator(); 152 | $hydrators->add(new Hydrator\ArtistCollectionHydrator()); 153 | 154 | return $hydrators->hydrate($response, new Entity\ArtistCollection()); 155 | } 156 | 157 | /** 158 | * @param string $id 159 | * @param string|null $country 160 | * @param array $albumTypes 161 | * @param int $limit 162 | * @param int $offset 163 | * @return Entity\AlbumPagination 164 | */ 165 | public function getArtistAlbums($id, $country = null, array $albumTypes = array(), $limit = 20, $offset = 0) 166 | { 167 | $request = $this->guzzleClient->createRequest('GET', sprintf('/v1/artists/%s/albums', $id)); 168 | $request->getQuery()->add('album_type', implode(',', $albumTypes)); 169 | $request->getQuery()->add('country', $country); 170 | $request->getQuery()->add('limit', $limit); 171 | $request->getQuery()->add('offset', $offset); 172 | 173 | $response = $this->sendRequest($request)->json(); 174 | 175 | $hydrators = new AggregateHydrator(); 176 | $hydrators->add(new Hydrator\PaginationHydrator()); 177 | $hydrators->add(new Hydrator\PaginatedAlbumCollectionHydrator()); 178 | 179 | return $hydrators->hydrate($response, new Entity\AlbumPagination()); 180 | } 181 | 182 | /** 183 | * @param string $id 184 | * @param string $country 185 | * @return Entity\TrackCollection 186 | */ 187 | public function getArtistTopTracks($id, $country) 188 | { 189 | $request = $this->guzzleClient->createRequest('GET', sprintf('/v1/artists/%s/top-tracks', $id)); 190 | $request->getQuery()->add('country', $country); 191 | 192 | $response = $this->sendRequest($request)->json(); 193 | 194 | $hydrators = new AggregateHydrator(); 195 | $hydrators->add(new Hydrator\TrackCollectionHydrator()); 196 | 197 | return $hydrators->hydrate($response, new Entity\TrackCollection()); 198 | } 199 | 200 | /** 201 | * @param string $id 202 | * @return Entity\ArtistCollection 203 | */ 204 | public function getArtistRelatedArtists($id) 205 | { 206 | $response = $this->sendRequest( 207 | $this->guzzleClient->createRequest('GET', sprintf('/v1/artists/%s/related-artists', $id)) 208 | )->json(); 209 | 210 | $hydrators = new AggregateHydrator(); 211 | $hydrators->add(new Hydrator\ArtistCollectionHydrator()); 212 | 213 | return $hydrators->hydrate($response, new Entity\ArtistCollection()); 214 | } 215 | 216 | /** 217 | * @param string $id 218 | * @return Entity\Track 219 | */ 220 | public function getTrack($id) 221 | { 222 | $response = $this->sendRequest( 223 | $this->guzzleClient->createRequest('GET', sprintf('/v1/tracks/%s', $id)) 224 | )->json(); 225 | 226 | $hydrators = new AggregateHydrator(); 227 | $hydrators->add(new Hydrator\TrackHydrator()); 228 | $hydrators->add(new Hydrator\AlbumAwareHydrator()); 229 | $hydrators->add(new Hydrator\ArtistCollectionAwareHydrator()); 230 | 231 | return $hydrators->hydrate($response, new Entity\Track()); 232 | } 233 | 234 | /** 235 | * @param array $ids 236 | * @return Entity\TrackCollection 237 | */ 238 | public function getTracks(array $ids) 239 | { 240 | $request = $this->guzzleClient->createRequest('GET', '/v1/tracks'); 241 | $request->getQuery()->add('ids', implode(',', $ids)); 242 | 243 | $response = $this->sendRequest($request)->json(); 244 | 245 | $hydrators = new AggregateHydrator(); 246 | $hydrators->add(new Hydrator\TrackCollectionHydrator()); 247 | 248 | return $hydrators->hydrate($response, new Entity\TrackCollection()); 249 | } 250 | 251 | /** 252 | * @param string $id 253 | * @return Entity\User 254 | */ 255 | public function getUserProfile($id) 256 | { 257 | $response = $this->sendRequest( 258 | $this->guzzleClient->createRequest('GET', sprintf('/v1/users/%s', $id)) 259 | )->json(); 260 | 261 | $hydrators = new AggregateHydrator(); 262 | $hydrators->add(new Hydrator\UserHydrator()); 263 | 264 | return $hydrators->hydrate($response, new Entity\User()); 265 | } 266 | 267 | /** 268 | * @return Entity\User 269 | */ 270 | public function getCurrentUser() 271 | { 272 | $response = $this->sendRequest($this->guzzleClient->createRequest('GET', '/v1/me'))->json(); 273 | 274 | $hydrators = new AggregateHydrator(); 275 | $hydrators->add(new Hydrator\UserHydrator()); 276 | $hydrators->add(new Hydrator\ImageCollectionAwareHydrator()); 277 | 278 | return $hydrators->hydrate($response, new Entity\User()); 279 | } 280 | 281 | /** 282 | * @param string $userId 283 | * @param string $id 284 | * @param array $fields 285 | * @return Entity\Playlist 286 | */ 287 | public function getUserPlaylist($userId, $id, array $fields = array()) 288 | { 289 | $request = $this->guzzleClient->createRequest('GET', sprintf('/v1/users/%s/playlists/%s', $userId, $id)); 290 | $request->getQuery()->add( 291 | 'fields', 292 | implode(',', empty($fields) ? $fields : array_merge($this->paginationFields, $fields)) 293 | ); 294 | 295 | $response = $this->sendRequest($request)->json(); 296 | 297 | $hydrators = new AggregateHydrator(); 298 | $hydrators->add(new Hydrator\PlaylistHydrator()); 299 | $hydrators->add(new Hydrator\ImageCollectionAwareHydrator()); 300 | $hydrators->add(new Hydrator\OwnerAwareHydrator()); 301 | $hydrators->add(new Hydrator\PaginatedPlaylistTrackCollectionAwareHydrator()); 302 | 303 | return $hydrators->hydrate($response, new Entity\Playlist()); 304 | } 305 | 306 | /** 307 | * @param string $userId 308 | * @param string $id 309 | * @param array $fields 310 | * @return Entity\PlaylistTrackPagination 311 | */ 312 | public function getUserPlaylistTracks($userId, $id, array $fields = array()) 313 | { 314 | $request = $this->guzzleClient->createRequest('GET', sprintf('/v1/users/%s/playlists/%s/tracks', $userId, $id)); 315 | $request->getQuery()->add( 316 | 'fields', 317 | implode(',', empty($fields) ? $fields : array_merge($this->paginationFields, $fields)) 318 | ); 319 | 320 | $response = $this->sendRequest($request)->json(); 321 | 322 | $hydrators = new AggregateHydrator(); 323 | $hydrators->add(new Hydrator\PaginationHydrator()); 324 | $hydrators->add(new Hydrator\PaginatedPlaylistTrackCollectionHydrator()); 325 | 326 | return $hydrators->hydrate($response, new Entity\PlaylistTrackPagination()); 327 | } 328 | 329 | /** 330 | * @param string $id 331 | * @return Entity\PlaylistPagination 332 | */ 333 | public function getUserPlaylists($id) 334 | { 335 | $request = $this->guzzleClient->createRequest('GET', sprintf('/v1/users/%s/playlists', $id)); 336 | 337 | $response = $this->sendRequest($request)->json(); 338 | 339 | $hydrators = new AggregateHydrator(); 340 | $hydrators->add(new Hydrator\PaginationHydrator()); 341 | $hydrators->add(new Hydrator\PaginatedPlaylistCollectionHydrator()); 342 | 343 | return $hydrators->hydrate($response, new Entity\PlaylistPagination()); 344 | } 345 | 346 | /** 347 | * @param Guzzle\Http\Message\RequestInterface $request 348 | * @return Guzzle\Http\Message\Response|null 349 | * @throws Exception\AccessTokenException 350 | * @throws \Exception 351 | */ 352 | private function sendRequest(Guzzle\Http\Message\RequestInterface $request) 353 | { 354 | // Clean the query string of any null valued parameters 355 | $request->getQuery()->replace(array_filter($request->getQuery()->toArray())); 356 | 357 | try { 358 | return $this->guzzleClient->send($request); 359 | } catch (Guzzle\Http\Exception\ClientErrorResponseException $e) { 360 | switch ($e->getResponse()->getStatusCode()) { 361 | case 401: 362 | throw new Exception\AccessTokenException(); 363 | break; 364 | default: 365 | $hydrator = new Hydrator\ErrorHydrator(); 366 | $error = $hydrator->hydrate($e->getResponse()->json(), new Entity\Error()); 367 | throw new Exception\SpotifyException($error); 368 | break; 369 | } 370 | } 371 | } 372 | } 373 | -------------------------------------------------------------------------------- /src/Entity/Album.php: -------------------------------------------------------------------------------- 1 | albumType; 99 | } 100 | 101 | /** 102 | * @param string $albumType 103 | */ 104 | public function setAlbumType($albumType) 105 | { 106 | $this->albumType = $albumType; 107 | } 108 | 109 | /** 110 | * @return ArtistCollection 111 | */ 112 | public function getArtists() 113 | { 114 | return $this->artists; 115 | } 116 | 117 | /** 118 | * @param ArtistCollection $artists 119 | */ 120 | public function setArtists($artists) 121 | { 122 | $this->artists = $artists; 123 | } 124 | 125 | /** 126 | * @return array 127 | */ 128 | public function getAvailableMarkets() 129 | { 130 | return $this->availableMarkets; 131 | } 132 | 133 | /** 134 | * @param array $availableMarkets 135 | */ 136 | public function setAvailableMarkets($availableMarkets) 137 | { 138 | $this->availableMarkets = $availableMarkets; 139 | } 140 | 141 | /** 142 | * @return array 143 | */ 144 | public function getExternalIds() 145 | { 146 | return $this->externalIds; 147 | } 148 | 149 | /** 150 | * @param array $externalIds 151 | */ 152 | public function setExternalIds($externalIds) 153 | { 154 | $this->externalIds = $externalIds; 155 | } 156 | 157 | /** 158 | * @return array 159 | */ 160 | public function getExternalUrls() 161 | { 162 | return $this->externalUrls; 163 | } 164 | 165 | /** 166 | * @param array $externalUrls 167 | */ 168 | public function setExternalUrls($externalUrls) 169 | { 170 | $this->externalUrls = $externalUrls; 171 | } 172 | 173 | /** 174 | * @return array 175 | */ 176 | public function getGenres() 177 | { 178 | return $this->genres; 179 | } 180 | 181 | /** 182 | * @param array $genres 183 | */ 184 | public function setGenres($genres) 185 | { 186 | $this->genres = $genres; 187 | } 188 | 189 | /** 190 | * @return string 191 | */ 192 | public function getHref() 193 | { 194 | return $this->href; 195 | } 196 | 197 | /** 198 | * @param string $href 199 | */ 200 | public function setHref($href) 201 | { 202 | $this->href = $href; 203 | } 204 | 205 | /** 206 | * @return string 207 | */ 208 | public function getId() 209 | { 210 | return $this->id; 211 | } 212 | 213 | /** 214 | * @param string $id 215 | */ 216 | public function setId($id) 217 | { 218 | $this->id = $id; 219 | } 220 | 221 | /** 222 | * @return ImageCollection 223 | */ 224 | public function getImages() 225 | { 226 | return $this->images; 227 | } 228 | 229 | /** 230 | * @param ImageCollection $images 231 | */ 232 | public function setImages($images) 233 | { 234 | $this->images = $images; 235 | } 236 | 237 | /** 238 | * @return string 239 | */ 240 | public function getName() 241 | { 242 | return $this->name; 243 | } 244 | 245 | /** 246 | * @param string $name 247 | */ 248 | public function setName($name) 249 | { 250 | $this->name = $name; 251 | } 252 | 253 | /** 254 | * @return int 255 | */ 256 | public function getPopularity() 257 | { 258 | return $this->popularity; 259 | } 260 | 261 | /** 262 | * @param int $popularity 263 | */ 264 | public function setPopularity($popularity) 265 | { 266 | $this->popularity = $popularity; 267 | } 268 | 269 | /** 270 | * @return string 271 | */ 272 | public function getReleaseDate() 273 | { 274 | return $this->releaseDate; 275 | } 276 | 277 | /** 278 | * @param string $releaseDate 279 | */ 280 | public function setReleaseDate($releaseDate) 281 | { 282 | $this->releaseDate = $releaseDate; 283 | } 284 | 285 | /** 286 | * @return string 287 | */ 288 | public function getReleaseDatePrecision() 289 | { 290 | return $this->releaseDatePrecision; 291 | } 292 | 293 | /** 294 | * @param string $releaseDatePrecision 295 | */ 296 | public function setReleaseDatePrecision($releaseDatePrecision) 297 | { 298 | $this->releaseDatePrecision = $releaseDatePrecision; 299 | } 300 | 301 | /** 302 | * @return TrackCollection 303 | */ 304 | public function getTracks() 305 | { 306 | return $this->tracks; 307 | } 308 | 309 | /** 310 | * @param TrackCollection $tracks 311 | */ 312 | public function setTracks($tracks) 313 | { 314 | $this->tracks = $tracks; 315 | } 316 | 317 | /** 318 | * @return string 319 | */ 320 | public function getType() 321 | { 322 | return $this->type; 323 | } 324 | 325 | /** 326 | * @param string $type 327 | */ 328 | public function setType($type) 329 | { 330 | $this->type = $type; 331 | } 332 | 333 | /** 334 | * @return string 335 | */ 336 | public function getUri() 337 | { 338 | return $this->uri; 339 | } 340 | 341 | /** 342 | * @param string $uri 343 | */ 344 | public function setUri($uri) 345 | { 346 | $this->uri = $uri; 347 | } 348 | 349 | /** 350 | * @return string 351 | */ 352 | public function __toString() 353 | { 354 | return $this->name; 355 | } 356 | } -------------------------------------------------------------------------------- /src/Entity/AlbumCollection.php: -------------------------------------------------------------------------------- 1 | externalUrls; 64 | } 65 | 66 | /** 67 | * @param array $externalUrls 68 | */ 69 | public function setExternalUrls($externalUrls) 70 | { 71 | $this->externalUrls = $externalUrls; 72 | } 73 | 74 | /** 75 | * @return array 76 | */ 77 | public function getGenres() 78 | { 79 | return $this->genres; 80 | } 81 | 82 | /** 83 | * @param array $genres 84 | */ 85 | public function setGenres($genres) 86 | { 87 | $this->genres = $genres; 88 | } 89 | 90 | /** 91 | * @return string 92 | */ 93 | public function getHref() 94 | { 95 | return $this->href; 96 | } 97 | 98 | /** 99 | * @param string $href 100 | */ 101 | public function setHref($href) 102 | { 103 | $this->href = $href; 104 | } 105 | 106 | /** 107 | * @return string 108 | */ 109 | public function getId() 110 | { 111 | return $this->id; 112 | } 113 | 114 | /** 115 | * @param string $id 116 | */ 117 | public function setId($id) 118 | { 119 | $this->id = $id; 120 | } 121 | 122 | /** 123 | * @return ImageCollection 124 | */ 125 | public function getImages() 126 | { 127 | return $this->images; 128 | } 129 | 130 | /** 131 | * @param ImageCollection $images 132 | */ 133 | public function setImages($images) 134 | { 135 | $this->images = $images; 136 | } 137 | 138 | /** 139 | * @return string 140 | */ 141 | public function getName() 142 | { 143 | return $this->name; 144 | } 145 | 146 | /** 147 | * @param string $name 148 | */ 149 | public function setName($name) 150 | { 151 | $this->name = $name; 152 | } 153 | 154 | /** 155 | * @return int 156 | */ 157 | public function getPopularity() 158 | { 159 | return $this->popularity; 160 | } 161 | 162 | /** 163 | * @param int $popularity 164 | */ 165 | public function setPopularity($popularity) 166 | { 167 | $this->popularity = $popularity; 168 | } 169 | 170 | /** 171 | * @return string 172 | */ 173 | public function getType() 174 | { 175 | return $this->type; 176 | } 177 | 178 | /** 179 | * @param string $type 180 | */ 181 | public function setType($type) 182 | { 183 | $this->type = $type; 184 | } 185 | 186 | /** 187 | * @return string 188 | */ 189 | public function getUri() 190 | { 191 | return $this->uri; 192 | } 193 | 194 | /** 195 | * @param string $uri 196 | */ 197 | public function setUri($uri) 198 | { 199 | $this->uri = $uri; 200 | } 201 | 202 | /** 203 | * @return string 204 | */ 205 | public function __toString() 206 | { 207 | return $this->name; 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/Entity/ArtistCollection.php: -------------------------------------------------------------------------------- 1 | message; 29 | } 30 | 31 | /** 32 | * @param string $message 33 | */ 34 | public function setMessage($message) 35 | { 36 | $this->message = $message; 37 | } 38 | 39 | /** 40 | * @return int 41 | */ 42 | public function getStatus() 43 | { 44 | return $this->status; 45 | } 46 | 47 | /** 48 | * @param int $status 49 | */ 50 | public function setStatus($status) 51 | { 52 | $this->status = $status; 53 | } 54 | } -------------------------------------------------------------------------------- /src/Entity/Image.php: -------------------------------------------------------------------------------- 1 | height; 34 | } 35 | 36 | /** 37 | * @param int $height 38 | */ 39 | public function setHeight($height) 40 | { 41 | $this->height = $height; 42 | } 43 | 44 | /** 45 | * @return string 46 | */ 47 | public function getUrl() 48 | { 49 | return $this->url; 50 | } 51 | 52 | /** 53 | * @param string $url 54 | */ 55 | public function setUrl($url) 56 | { 57 | $this->url = $url; 58 | } 59 | 60 | /** 61 | * @return int 62 | */ 63 | public function getWidth() 64 | { 65 | return $this->width; 66 | } 67 | 68 | /** 69 | * @param int $width 70 | */ 71 | public function setWidth($width) 72 | { 73 | $this->width = $width; 74 | } 75 | 76 | /** 77 | * @return string 78 | */ 79 | public function __toString() 80 | { 81 | return $this->url; 82 | } 83 | } -------------------------------------------------------------------------------- /src/Entity/ImageCollection.php: -------------------------------------------------------------------------------- 1 | href; 50 | } 51 | 52 | /** 53 | * @param string $href 54 | */ 55 | public function setHref($href) 56 | { 57 | $this->href = $href; 58 | } 59 | 60 | /** 61 | * @return ArrayCollection 62 | */ 63 | public function getItems() 64 | { 65 | return $this->items; 66 | } 67 | 68 | /** 69 | * @return bool 70 | */ 71 | public function hasItems() 72 | { 73 | return !empty($this->items); 74 | } 75 | 76 | /** 77 | * @param ArrayCollection $items 78 | */ 79 | public function setItems($items) 80 | { 81 | $this->items = $items; 82 | } 83 | 84 | /** 85 | * @return int 86 | */ 87 | public function getLimit() 88 | { 89 | return $this->limit; 90 | } 91 | 92 | /** 93 | * @param int $limit 94 | */ 95 | public function setLimit($limit) 96 | { 97 | $this->limit = $limit; 98 | } 99 | 100 | /** 101 | * @return string 102 | */ 103 | public function getNext() 104 | { 105 | return $this->next; 106 | } 107 | 108 | /** 109 | * @param string $next 110 | */ 111 | public function setNext($next) 112 | { 113 | $this->next = $next; 114 | } 115 | 116 | /** 117 | * @return int 118 | */ 119 | public function getOffset() 120 | { 121 | return $this->offset; 122 | } 123 | 124 | /** 125 | * @param int $offset 126 | */ 127 | public function setOffset($offset) 128 | { 129 | $this->offset = $offset; 130 | } 131 | 132 | /** 133 | * @return string 134 | */ 135 | public function getPrevious() 136 | { 137 | return $this->previous; 138 | } 139 | 140 | /** 141 | * @param string $previous 142 | */ 143 | public function setPrevious($previous) 144 | { 145 | $this->previous = $previous; 146 | } 147 | 148 | /** 149 | * @return int 150 | */ 151 | public function getTotal() 152 | { 153 | return $this->total; 154 | } 155 | 156 | /** 157 | * @param int $total 158 | */ 159 | public function setTotal($total) 160 | { 161 | $this->total = $total; 162 | } 163 | } -------------------------------------------------------------------------------- /src/Entity/Playlist.php: -------------------------------------------------------------------------------- 1 | collaborative; 84 | } 85 | 86 | /** 87 | * @param boolean $collaborative 88 | */ 89 | public function setCollaborative($collaborative) 90 | { 91 | $this->collaborative = $collaborative; 92 | } 93 | 94 | /** 95 | * @return string 96 | */ 97 | public function getDescription() 98 | { 99 | return $this->description; 100 | } 101 | 102 | /** 103 | * @param string $description 104 | */ 105 | public function setDescription($description) 106 | { 107 | $this->description = $description; 108 | } 109 | 110 | /** 111 | * @return array 112 | */ 113 | public function getExternalUrls() 114 | { 115 | return $this->externalUrls; 116 | } 117 | 118 | /** 119 | * @param array $externalUrls 120 | */ 121 | public function setExternalUrls($externalUrls) 122 | { 123 | $this->externalUrls = $externalUrls; 124 | } 125 | 126 | /** 127 | * @return array 128 | */ 129 | public function getFollowers() 130 | { 131 | return $this->followers; 132 | } 133 | 134 | /** 135 | * @param array $followers 136 | */ 137 | public function setFollowers($followers) 138 | { 139 | $this->followers = $followers; 140 | } 141 | 142 | /** 143 | * @return string 144 | */ 145 | public function getHref() 146 | { 147 | return $this->href; 148 | } 149 | 150 | /** 151 | * @param string $href 152 | */ 153 | public function setHref($href) 154 | { 155 | $this->href = $href; 156 | } 157 | 158 | /** 159 | * @return string 160 | */ 161 | public function getId() 162 | { 163 | return $this->id; 164 | } 165 | 166 | /** 167 | * @param string $id 168 | */ 169 | public function setId($id) 170 | { 171 | $this->id = $id; 172 | } 173 | 174 | /** 175 | * @return ImageCollection 176 | */ 177 | public function getImages() 178 | { 179 | return $this->images; 180 | } 181 | 182 | /** 183 | * @param ImageCollection $images 184 | */ 185 | public function setImages($images) 186 | { 187 | $this->images = $images; 188 | } 189 | 190 | /** 191 | * @return string 192 | */ 193 | public function getName() 194 | { 195 | return $this->name; 196 | } 197 | 198 | /** 199 | * @param string $name 200 | */ 201 | public function setName($name) 202 | { 203 | $this->name = $name; 204 | } 205 | 206 | /** 207 | * @return User 208 | */ 209 | public function getOwner() 210 | { 211 | return $this->owner; 212 | } 213 | 214 | /** 215 | * @param User $owner 216 | */ 217 | public function setOwner($owner) 218 | { 219 | $this->owner = $owner; 220 | } 221 | 222 | /** 223 | * @return boolean 224 | */ 225 | public function isPublic() 226 | { 227 | return $this->public; 228 | } 229 | 230 | /** 231 | * @param boolean $public 232 | */ 233 | public function setPublic($public) 234 | { 235 | $this->public = $public; 236 | } 237 | 238 | /** 239 | * @return PlaylistTrackPagination 240 | */ 241 | public function getTracks() 242 | { 243 | return $this->tracks; 244 | } 245 | 246 | /** 247 | * @param PlaylistTrackPagination $tracks 248 | */ 249 | public function setTracks($tracks) 250 | { 251 | $this->tracks = $tracks; 252 | } 253 | 254 | /** 255 | * @return string 256 | */ 257 | public function getType() 258 | { 259 | return $this->type; 260 | } 261 | 262 | /** 263 | * @param string $type 264 | */ 265 | public function setType($type) 266 | { 267 | $this->type = $type; 268 | } 269 | 270 | /** 271 | * @return string 272 | */ 273 | public function getUri() 274 | { 275 | return $this->uri; 276 | } 277 | 278 | /** 279 | * @param string $uri 280 | */ 281 | public function setUri($uri) 282 | { 283 | $this->uri = $uri; 284 | } 285 | 286 | /** 287 | * @return string 288 | */ 289 | public function __toString() 290 | { 291 | return $this->name; 292 | } 293 | } -------------------------------------------------------------------------------- /src/Entity/PlaylistCollection.php: -------------------------------------------------------------------------------- 1 | addedAt; 34 | } 35 | 36 | /** 37 | * @param \DateTime $addedAt 38 | */ 39 | public function setAddedAt($addedAt) 40 | { 41 | $this->addedAt = $addedAt; 42 | } 43 | 44 | /** 45 | * @return User 46 | */ 47 | public function getAddedBy() 48 | { 49 | return $this->addedBy; 50 | } 51 | 52 | /** 53 | * @param User $addedBy 54 | */ 55 | public function setAddedBy($addedBy) 56 | { 57 | $this->addedBy = $addedBy; 58 | } 59 | 60 | /** 61 | * @return Track 62 | */ 63 | public function getTrack() 64 | { 65 | return $this->track; 66 | } 67 | 68 | /** 69 | * @param Track $track 70 | */ 71 | public function setTrack($track) 72 | { 73 | $this->track = $track; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Entity/PlaylistTrackCollection.php: -------------------------------------------------------------------------------- 1 | album; 99 | } 100 | 101 | /** 102 | * @param Album $album 103 | */ 104 | public function setAlbum($album) 105 | { 106 | $this->album = $album; 107 | } 108 | 109 | /** 110 | * @return ArtistCollection 111 | */ 112 | public function getArtists() 113 | { 114 | return $this->artists; 115 | } 116 | 117 | /** 118 | * @param ArtistCollection $artists 119 | */ 120 | public function setArtists($artists) 121 | { 122 | $this->artists = $artists; 123 | } 124 | 125 | /** 126 | * @return array 127 | */ 128 | public function getAvailableMarkets() 129 | { 130 | return $this->availableMarkets; 131 | } 132 | 133 | /** 134 | * @param array $availableMarkets 135 | */ 136 | public function setAvailableMarkets($availableMarkets) 137 | { 138 | $this->availableMarkets = $availableMarkets; 139 | } 140 | 141 | /** 142 | * @return int 143 | */ 144 | public function getDiscNumber() 145 | { 146 | return $this->discNumber; 147 | } 148 | 149 | /** 150 | * @param int $discNumber 151 | */ 152 | public function setDiscNumber($discNumber) 153 | { 154 | $this->discNumber = $discNumber; 155 | } 156 | 157 | /** 158 | * @return int 159 | */ 160 | public function getDurationMs() 161 | { 162 | return $this->durationMs; 163 | } 164 | 165 | /** 166 | * @param int $durationMs 167 | */ 168 | public function setDurationMs($durationMs) 169 | { 170 | $this->durationMs = $durationMs; 171 | } 172 | 173 | /** 174 | * @return boolean 175 | */ 176 | public function isExplicit() 177 | { 178 | return $this->explicit; 179 | } 180 | 181 | /** 182 | * @param boolean $explicit 183 | */ 184 | public function setExplicit($explicit) 185 | { 186 | $this->explicit = $explicit; 187 | } 188 | 189 | /** 190 | * @return array 191 | */ 192 | public function getExternalIds() 193 | { 194 | return $this->externalIds; 195 | } 196 | 197 | /** 198 | * @param array $externalIds 199 | */ 200 | public function setExternalIds($externalIds) 201 | { 202 | $this->externalIds = $externalIds; 203 | } 204 | 205 | /** 206 | * @return array 207 | */ 208 | public function getExternalUrls() 209 | { 210 | return $this->externalUrls; 211 | } 212 | 213 | /** 214 | * @param array $externalUrls 215 | */ 216 | public function setExternalUrls($externalUrls) 217 | { 218 | $this->externalUrls = $externalUrls; 219 | } 220 | 221 | /** 222 | * @return string 223 | */ 224 | public function getHref() 225 | { 226 | return $this->href; 227 | } 228 | 229 | /** 230 | * @param string $href 231 | */ 232 | public function setHref($href) 233 | { 234 | $this->href = $href; 235 | } 236 | 237 | /** 238 | * @return string 239 | */ 240 | public function getId() 241 | { 242 | return $this->id; 243 | } 244 | 245 | /** 246 | * @param string $id 247 | */ 248 | public function setId($id) 249 | { 250 | $this->id = $id; 251 | } 252 | 253 | /** 254 | * @return string 255 | */ 256 | public function getName() 257 | { 258 | return $this->name; 259 | } 260 | 261 | /** 262 | * @param string $name 263 | */ 264 | public function setName($name) 265 | { 266 | $this->name = $name; 267 | } 268 | 269 | /** 270 | * @return int 271 | */ 272 | public function getPopularity() 273 | { 274 | return $this->popularity; 275 | } 276 | 277 | /** 278 | * @param int $popularity 279 | */ 280 | public function setPopularity($popularity) 281 | { 282 | $this->popularity = $popularity; 283 | } 284 | 285 | /** 286 | * @return string 287 | */ 288 | public function getPreviewUrl() 289 | { 290 | return $this->previewUrl; 291 | } 292 | 293 | /** 294 | * @param string $previewUrl 295 | */ 296 | public function setPreviewUrl($previewUrl) 297 | { 298 | $this->previewUrl = $previewUrl; 299 | } 300 | 301 | /** 302 | * @return int 303 | */ 304 | public function getTrackNumber() 305 | { 306 | return $this->trackNumber; 307 | } 308 | 309 | /** 310 | * @param int $trackNumber 311 | */ 312 | public function setTrackNumber($trackNumber) 313 | { 314 | $this->trackNumber = $trackNumber; 315 | } 316 | 317 | /** 318 | * @return string 319 | */ 320 | public function getType() 321 | { 322 | return $this->type; 323 | } 324 | 325 | /** 326 | * @param string $type 327 | */ 328 | public function setType($type) 329 | { 330 | $this->type = $type; 331 | } 332 | 333 | /** 334 | * @return string 335 | */ 336 | public function getUri() 337 | { 338 | return $this->uri; 339 | } 340 | 341 | /** 342 | * @param string $uri 343 | */ 344 | public function setUri($uri) 345 | { 346 | $this->uri = $uri; 347 | } 348 | 349 | /** 350 | * @return string 351 | */ 352 | public function __toString() 353 | { 354 | return $this->name; 355 | } 356 | } 357 | -------------------------------------------------------------------------------- /src/Entity/TrackCollection.php: -------------------------------------------------------------------------------- 1 | href; 29 | } 30 | 31 | /** 32 | * @param string $href 33 | */ 34 | public function setHref($href) 35 | { 36 | $this->href = $href; 37 | } 38 | 39 | /** 40 | * @return int 41 | */ 42 | public function getTotal() 43 | { 44 | return $this->total; 45 | } 46 | 47 | /** 48 | * @param int $total 49 | */ 50 | public function setTotal($total) 51 | { 52 | $this->total = $total; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Entity/User.php: -------------------------------------------------------------------------------- 1 | country; 69 | } 70 | 71 | /** 72 | * @param string $country 73 | */ 74 | public function setCountry($country) 75 | { 76 | $this->country = $country; 77 | } 78 | 79 | /** 80 | * @return string 81 | */ 82 | public function getDisplayName() 83 | { 84 | return $this->displayName; 85 | } 86 | 87 | /** 88 | * @param string $displayName 89 | */ 90 | public function setDisplayName($displayName) 91 | { 92 | $this->displayName = $displayName; 93 | } 94 | 95 | /** 96 | * @return string 97 | */ 98 | public function getEmail() 99 | { 100 | return $this->email; 101 | } 102 | 103 | /** 104 | * @param string $email 105 | */ 106 | public function setEmail($email) 107 | { 108 | $this->email = $email; 109 | } 110 | 111 | /** 112 | * @return array 113 | */ 114 | public function getExternalUrls() 115 | { 116 | return $this->externalUrls; 117 | } 118 | 119 | /** 120 | * @param array $externalUrls 121 | */ 122 | public function setExternalUrls($externalUrls) 123 | { 124 | $this->externalUrls = $externalUrls; 125 | } 126 | 127 | /** 128 | * @return string 129 | */ 130 | public function getHref() 131 | { 132 | return $this->href; 133 | } 134 | 135 | /** 136 | * @param string $href 137 | */ 138 | public function setHref($href) 139 | { 140 | $this->href = $href; 141 | } 142 | 143 | /** 144 | * @return string 145 | */ 146 | public function getId() 147 | { 148 | return $this->id; 149 | } 150 | 151 | /** 152 | * @param string $id 153 | */ 154 | public function setId($id) 155 | { 156 | $this->id = $id; 157 | } 158 | 159 | /** 160 | * @return Image[] 161 | */ 162 | public function getImages() 163 | { 164 | return $this->images; 165 | } 166 | 167 | /** 168 | * @param Image[] $images 169 | */ 170 | public function setImages($images) 171 | { 172 | $this->images = $images; 173 | } 174 | 175 | /** 176 | * @return string 177 | */ 178 | public function getProduct() 179 | { 180 | return $this->product; 181 | } 182 | 183 | /** 184 | * @param string $product 185 | */ 186 | public function setProduct($product) 187 | { 188 | $this->product = $product; 189 | } 190 | 191 | /** 192 | * @return string 193 | */ 194 | public function getType() 195 | { 196 | return $this->type; 197 | } 198 | 199 | /** 200 | * @param string $type 201 | */ 202 | public function setType($type) 203 | { 204 | $this->type = $type; 205 | } 206 | 207 | /** 208 | * @return string 209 | */ 210 | public function getUri() 211 | { 212 | return $this->uri; 213 | } 214 | 215 | /** 216 | * @param string $uri 217 | */ 218 | public function setUri($uri) 219 | { 220 | $this->uri = $uri; 221 | } 222 | 223 | /** 224 | * @return string 225 | */ 226 | public function __toString() 227 | { 228 | return sprintf('%s (%s)', $this->displayName, $this->id); 229 | } 230 | } -------------------------------------------------------------------------------- /src/Exception/AccessTokenException.php: -------------------------------------------------------------------------------- 1 | error = $error; 24 | 25 | parent::__construct($error->getMessage(), $error->getStatus()); 26 | } 27 | 28 | /** 29 | * @return Error 30 | */ 31 | public function getError() 32 | { 33 | return $this->error; 34 | } 35 | } -------------------------------------------------------------------------------- /src/Hydrator/AlbumAwareHydrator.php: -------------------------------------------------------------------------------- 1 | add(new AlbumHydrator()); 30 | $hydrators->add(new ImageCollectionAwareHydrator()); 31 | 32 | $object->setAlbum($hydrators->hydrate($data['album'], new Album())); 33 | 34 | return $object; 35 | } 36 | } -------------------------------------------------------------------------------- /src/Hydrator/AlbumCollectionHydrator.php: -------------------------------------------------------------------------------- 1 | add(new AlbumHydrator()); 30 | $hydrators->add(new ArtistCollectionAwareHydrator()); 31 | $hydrators->add(new ImageCollectionAwareHydrator()); 32 | $hydrators->add(new PaginatedTrackCollectionAwareHydrator()); 33 | 34 | $object->add($hydrators->hydrate($album, new Album())); 35 | } 36 | 37 | return $object; 38 | } 39 | } -------------------------------------------------------------------------------- /src/Hydrator/AlbumHydrator.php: -------------------------------------------------------------------------------- 1 | add(new Artist($artist)); 30 | } 31 | 32 | $object->setArtists($artistCollection); 33 | 34 | return $object; 35 | } 36 | } -------------------------------------------------------------------------------- /src/Hydrator/ArtistCollectionHydrator.php: -------------------------------------------------------------------------------- 1 | add(new ArtistHydrator()); 30 | $hydrators->add(new ImageCollectionAwareHydrator()); 31 | 32 | $object->add($hydrators->hydrate($artist, new Artist())); 33 | } 34 | 35 | return $object; 36 | } 37 | } -------------------------------------------------------------------------------- /src/Hydrator/ArtistHydrator.php: -------------------------------------------------------------------------------- 1 | add(new Image($image)); 30 | } 31 | 32 | $object->setImages($imageCollection); 33 | 34 | return $object; 35 | } 36 | } -------------------------------------------------------------------------------- /src/Hydrator/OwnerAwareHydrator.php: -------------------------------------------------------------------------------- 1 | add(new UserHydrator()); 30 | $hydrators->add(new ImageCollectionAwareHydrator()); 31 | 32 | $object->setOwner($hydrators->hydrate($data['owner'], new User())); 33 | 34 | return $object; 35 | } 36 | } -------------------------------------------------------------------------------- /src/Hydrator/PaginatedAlbumCollectionHydrator.php: -------------------------------------------------------------------------------- 1 | add(new AlbumHydrator()); 33 | $hydrators->add(new ImageCollectionAwareHydrator()); 34 | 35 | $albumCollection->add($hydrators->hydrate($album, new Album())); 36 | } 37 | 38 | $object->setItems($albumCollection); 39 | 40 | return $object; 41 | } 42 | } -------------------------------------------------------------------------------- /src/Hydrator/PaginatedPlaylistCollectionHydrator.php: -------------------------------------------------------------------------------- 1 | add(new PlaylistHydrator()); 33 | $hydrators->add(new OwnerAwareHydrator()); 34 | $hydrators->add(new TracksAwareHydrator()); 35 | 36 | $playlistCollection->add($hydrators->hydrate($playlist, new Playlist())); 37 | } 38 | 39 | $object->setItems($playlistCollection); 40 | 41 | return $object; 42 | } 43 | } -------------------------------------------------------------------------------- /src/Hydrator/PaginatedPlaylistTrackCollectionAwareHydrator.php: -------------------------------------------------------------------------------- 1 | getItems() as $track) { 33 | $hydrators = new AggregateHydrator(); 34 | $hydrators->add(new TrackAwareHydrator()); 35 | 36 | $playlistTrackCollection->add($hydrators->hydrate($track, new PlaylistTrack())); 37 | } 38 | 39 | $paginatedTrackCollection->setItems($playlistTrackCollection); 40 | 41 | $object->setTracks($paginatedTrackCollection); 42 | 43 | return $object; 44 | } 45 | } -------------------------------------------------------------------------------- /src/Hydrator/PaginatedPlaylistTrackCollectionHydrator.php: -------------------------------------------------------------------------------- 1 | add(new TrackAwareHydrator()); 33 | 34 | $playlistTrackCollection->add($hydrators->hydrate($playlistTrack, new PlaylistTrack())); 35 | } 36 | 37 | $object->setItems($playlistTrackCollection); 38 | 39 | return $object; 40 | } 41 | } -------------------------------------------------------------------------------- /src/Hydrator/PaginatedTrackCollectionAwareHydrator.php: -------------------------------------------------------------------------------- 1 | getItems() as $track) { 32 | $trackCollection->add(new Track($track)); 33 | } 34 | 35 | $paginatedTrackCollection->setItems($trackCollection); 36 | 37 | $object->setTracks($paginatedTrackCollection); 38 | 39 | return $object; 40 | } 41 | } -------------------------------------------------------------------------------- /src/Hydrator/PaginatedTrackCollectionHydrator.php: -------------------------------------------------------------------------------- 1 | add(new Track($track)); 31 | } 32 | 33 | $object->setItems($trackCollection); 34 | 35 | return $object; 36 | } 37 | } -------------------------------------------------------------------------------- /src/Hydrator/PaginationHydrator.php: -------------------------------------------------------------------------------- 1 | add(new TrackHydrator()); 30 | $hydrators->add(new AlbumAwareHydrator()); 31 | $hydrators->add(new ArtistCollectionAwareHydrator()); 32 | $hydrators->add(new ImageCollectionAwareHydrator()); 33 | 34 | $object->setTrack($hydrators->hydrate($data['track'], new Track())); 35 | 36 | return $object; 37 | } 38 | } -------------------------------------------------------------------------------- /src/Hydrator/TrackCollectionHydrator.php: -------------------------------------------------------------------------------- 1 | add(new TrackHydrator()); 30 | $hydrators->add(new AlbumAwareHydrator()); 31 | $hydrators->add(new ArtistCollectionAwareHydrator()); 32 | $hydrators->add(new ImageCollectionAwareHydrator()); 33 | 34 | $object->add($hydrators->hydrate($track, new Track())); 35 | } 36 | 37 | return $object; 38 | } 39 | } -------------------------------------------------------------------------------- /src/Hydrator/TrackHydrator.php: -------------------------------------------------------------------------------- 1 | setTracks(new Tracks($data['tracks'])); 28 | 29 | return $object; 30 | } 31 | } -------------------------------------------------------------------------------- /src/Hydrator/UserHydrator.php: -------------------------------------------------------------------------------- 1 | headers = array( 40 | 'Authorization' => sprintf('Bearer %s', $token->accessToken) 41 | ); 42 | 43 | return 'https://api.spotify.com/v1/me'; 44 | } 45 | 46 | /** 47 | * @param $response 48 | * @param AccessToken $token 49 | * @return User 50 | */ 51 | public function userDetails($response, AccessToken $token) 52 | { 53 | $this->headers = array( 54 | 'Authorization' => sprintf('Bearer %s', $token->accessToken) 55 | ); 56 | 57 | $response = json_decode(json_encode($response), true); 58 | $user = new User(); 59 | $user->uid = $response['id']; 60 | $user->name = $response['display_name']; 61 | $user->email = !empty($response['email']) ? $response['email'] : null; 62 | $user->imageUrl = isset($response['images'][0]['url']) ?: null; 63 | $user->urls = $response['external_urls']; 64 | 65 | return $user; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/Audeio/Spotify/APITest.php: -------------------------------------------------------------------------------- 1 | getenv('SPOTIFY_CLIENT_ID'), 28 | 'clientSecret' => getenv('SPOTIFY_CLIENT_SECRET'), 29 | 'redirectUri' => 'http://localhost:8000' 30 | )); 31 | 32 | self::$accessToken = $oauthProvider->getAccessToken(new RefreshToken(), array( 33 | 'refresh_token' => getenv('SPOTIFY_REFRESH_TOKEN') 34 | ))->accessToken; 35 | } 36 | 37 | public function setUp() 38 | { 39 | $this->api = new API(); 40 | $this->api->setAccessToken(self::$accessToken); 41 | } 42 | 43 | public function testGetAlbum() 44 | { 45 | $response = $this->api->getAlbum('4lFDt4sVpCni9DRHRmDjgG'); 46 | 47 | $this->assertInstanceOf('Audeio\Spotify\Entity\Album', $response); 48 | $this->assertNotNull($response->getAlbumType()); 49 | $this->assertInstanceOf('Audeio\Spotify\Entity\ArtistCollection', $response->getArtists()); 50 | $this->assertNotEmpty($response->getAvailableMarkets()); 51 | $this->assertNotEmpty($response->getExternalIds()); 52 | $this->assertNotEmpty($response->getExternalUrls()); 53 | $this->assertNotNull($response->getHref()); 54 | $this->assertNotNull($response->getId()); 55 | $this->assertInstanceOf('Audeio\Spotify\Entity\ImageCollection', $response->getImages()); 56 | $this->assertNotNull($response->getName()); 57 | $this->assertNotNull($response->getPopularity()); 58 | $this->assertNotNull($response->getReleaseDate()); 59 | $this->assertNotNull($response->getReleaseDatePrecision()); 60 | $this->assertInstanceOf('Audeio\Spotify\Entity\TrackPagination', $response->getTracks()); 61 | $this->assertSame('album', $response->getType()); 62 | $this->assertNotNull($response->getUri()); 63 | } 64 | 65 | public function testGetAlbumThatDoesNotExist() 66 | { 67 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'invalid id'); 68 | 69 | $this->api->getAlbum('fake-album'); 70 | } 71 | 72 | public function testGetAlbums() 73 | { 74 | $response = $this->api->getAlbums( 75 | array('41MnTivkwTO3UUJ8DrqEJJ', '6JWc4iAiJ9FjyK0B59ABb4', '6UXCm6bOO4gFlDQZV5yL37') 76 | ); 77 | 78 | $this->assertInstanceOf('Audeio\Spotify\Entity\AlbumCollection', $response); 79 | } 80 | 81 | public function testGetAlbumsThatDoNotExist() 82 | { 83 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'invalid id'); 84 | 85 | $this->api->getAlbums(array('fake-album-1', 'fake-album-2')); 86 | } 87 | 88 | public function testGetAlbumTracks() 89 | { 90 | $response = $this->api->getAlbumTracks('6akEvsycLGftJxYudPjmqK'); 91 | 92 | $this->assertInstanceOf('Audeio\Spotify\Entity\TrackPagination', $response); 93 | $this->assertNotNull($response->getHref()); 94 | $this->assertNotNull($response->getLimit()); 95 | $this->assertNotNull($response->getOffset()); 96 | $this->assertNotNull($response->getTotal()); 97 | } 98 | 99 | public function testGetAlbumTracksWithLimit() 100 | { 101 | $response = $this->api->getAlbumTracks('6akEvsycLGftJxYudPjmqK', 5); 102 | 103 | $this->assertInstanceOf('Audeio\Spotify\Entity\TrackPagination', $response); 104 | $this->assertEquals(5, $response->getItems()->count()); 105 | $this->assertNotNull($response->getHref()); 106 | $this->assertNotNull(5); 107 | $this->assertNotNull($response->getOffset()); 108 | $this->assertNotNull($response->getTotal()); 109 | } 110 | 111 | public function testGetAlbumTracksWhenAlbumDoesNotExist() 112 | { 113 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'invalid id'); 114 | 115 | $this->api->getAlbumTracks('fake-album'); 116 | } 117 | 118 | public function testGetArtist() 119 | { 120 | $response = $this->api->getArtist('6jJ0s89eD6GaHleKKya26X'); 121 | 122 | $this->assertInstanceOf('Audeio\Spotify\Entity\Artist', $response); 123 | $this->assertNotEmpty($response->getExternalUrls()); 124 | $this->assertNotEmpty($response->getGenres()); 125 | $this->assertNotNull($response->getHref()); 126 | $this->assertNotNull($response->getId()); 127 | $this->assertInstanceOf('Audeio\Spotify\Entity\ImageCollection', $response->getImages()); 128 | $this->assertNotNull($response->getName()); 129 | $this->assertNotNull($response->getPopularity()); 130 | $this->assertSame('artist', $response->getType()); 131 | $this->assertNotNull($response->getUri()); 132 | } 133 | 134 | public function testGetArtistThatDoesNotExist() 135 | { 136 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'invalid id'); 137 | 138 | $this->api->getArtist('fake-artist'); 139 | } 140 | 141 | public function testGetArtists() 142 | { 143 | $response = $this->api->getArtists(array('0oSGxfWSnnOXhD2fKuz2Gy', '3dBVyJ7JuOMt4GE9607Qin')); 144 | 145 | $this->assertInstanceOf('Audeio\Spotify\Entity\ArtistCollection', $response); 146 | } 147 | 148 | public function testGetArtistsWhereArtistDoesNotExist() 149 | { 150 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'invalid id'); 151 | 152 | $this->api->getArtists(array('fake-artist', '3dBVyJ7JuOMt4GE9607Qin')); 153 | } 154 | 155 | public function testGetArtistAlbums() 156 | { 157 | $response = $this->api->getArtistAlbums('0LcJLqbBmaGUft1e9Mm8HV'); 158 | 159 | $this->assertInstanceOf('Audeio\Spotify\Entity\AlbumPagination', $response); 160 | $this->assertNotNull($response->getHref()); 161 | $this->assertNotNull($response->getLimit()); 162 | $this->assertNotNull($response->getOffset()); 163 | $this->assertNotNull($response->getTotal()); 164 | } 165 | 166 | public function testGetArtistAlbumsWhenArtistDoesNotExist() 167 | { 168 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'invalid id'); 169 | 170 | $this->api->getArtistAlbums('fake-artist'); 171 | } 172 | 173 | public function testGetArtistAlbumsWithCountry() 174 | { 175 | $response = $this->api->getArtistAlbums('0LcJLqbBmaGUft1e9Mm8HV', 'GB'); 176 | 177 | $this->assertInstanceOf('Audeio\Spotify\Entity\AlbumPagination', $response); 178 | $this->assertNotNull($response->getHref()); 179 | $this->assertNotNull($response->getLimit()); 180 | $this->assertNotNull($response->getOffset()); 181 | $this->assertNotNull($response->getTotal()); 182 | } 183 | 184 | public function testGetArtistAlbumsWithCountryAndAlbumTypes() 185 | { 186 | $response = $this->api->getArtistAlbums('0LcJLqbBmaGUft1e9Mm8HV', 'GB', array('single', 'compilation')); 187 | 188 | $this->assertInstanceOf('Audeio\Spotify\Entity\AlbumPagination', $response); 189 | $this->assertContains('album_type=single,compilation', $response->getHref()); 190 | $this->assertNotNull($response->getLimit()); 191 | $this->assertNotNull($response->getOffset()); 192 | $this->assertNotNull($response->getTotal()); 193 | } 194 | 195 | public function testGetArtistAlbumsWithCountryAlbumTypesAndLimit() 196 | { 197 | $response = $this->api->getArtistAlbums('0LcJLqbBmaGUft1e9Mm8HV', 'GB', array('single', 'compilation'), 2); 198 | 199 | $this->assertInstanceOf('Audeio\Spotify\Entity\AlbumPagination', $response); 200 | $this->assertContains('album_type=single,compilation', $response->getHref()); 201 | $this->assertEquals(2, $response->getLimit()); 202 | $this->assertNotNull($response->getOffset()); 203 | $this->assertNotNull($response->getTotal()); 204 | $this->assertLessThanOrEqual(2, $response->getItems()->count()); 205 | } 206 | 207 | public function testGetArtistTopTracks() 208 | { 209 | $response = $this->api->getArtistTopTracks('43ZHCT0cAZBISjO8DG9PnE', 'SE'); 210 | 211 | $this->assertInstanceOf('Audeio\Spotify\Entity\TrackCollection', $response); 212 | } 213 | 214 | public function testGetArtistTopTracksWhereArtistDoesNotExist() 215 | { 216 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'invalid id'); 217 | 218 | $this->api->getArtistTopTracks('fake-artist', 'SE'); 219 | } 220 | 221 | public function testGetArtistTopTracksWhereCountryDoesNotExist() 222 | { 223 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'Invalid country code'); 224 | 225 | $this->api->getArtistTopTracks('43ZHCT0cAZBISjO8DG9PnE', 'NOPE'); 226 | } 227 | 228 | public function testGetArtistRelatedArtists() 229 | { 230 | $response = $this->api->getArtistRelatedArtists('43ZHCT0cAZBISjO8DG9PnE'); 231 | 232 | $this->assertInstanceOf('Audeio\Spotify\Entity\ArtistCollection', $response); 233 | } 234 | 235 | public function testGetArtistRelatedArtistsWhereArtistDoesNotExist() 236 | { 237 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'invalid id'); 238 | 239 | $this->api->getArtistRelatedArtists('fake-artist'); 240 | } 241 | 242 | public function testGetTrack() 243 | { 244 | $response = $this->api->getTrack('0eGsygTp906u18L0Oimnem'); 245 | 246 | $this->assertInstanceOf('Audeio\Spotify\Entity\Track', $response); 247 | } 248 | 249 | public function testGetTrackWhereTrackDoesNotExist() 250 | { 251 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'invalid id'); 252 | 253 | $this->api->getTrack('fake-track'); 254 | } 255 | 256 | public function testGetTracks() 257 | { 258 | $response = $this->api->getTracks(array('0eGsygTp906u18L0Oimnem', '1lDWb6b6ieDQ2xT7ewTC3G')); 259 | 260 | $this->assertInstanceOf('Audeio\Spotify\Entity\TrackCollection', $response); 261 | } 262 | 263 | public function testGetTracksWhereTrackDoesNotExist() 264 | { 265 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'invalid id'); 266 | 267 | $this->api->getTracks(array('fake-track', '1lDWb6b6ieDQ2xT7ewTC3G')); 268 | } 269 | 270 | public function testGetUserProfile() 271 | { 272 | $response = $this->api->getUserProfile('wizzler'); 273 | 274 | $this->assertInstanceOf('Audeio\Spotify\Entity\User', $response); 275 | } 276 | 277 | public function testGetUserProfileWhereUserDoesNotExist() 278 | { 279 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'No such user'); 280 | 281 | $this->api->getUserProfile('fake-user-made-up-by-me-for-testing-93874123'); 282 | } 283 | 284 | public function testGetCurrentUser() 285 | { 286 | $response = $this->api->getCurrentUser(); 287 | 288 | $this->assertInstanceOf('Audeio\Spotify\Entity\User', $response); 289 | } 290 | 291 | public function testGetCurrentUserWithNoAuthorization() 292 | { 293 | $this->setExpectedException('Audeio\Spotify\Exception\AccessTokenException'); 294 | 295 | $this->api->setAccessToken(null); 296 | $this->api->getCurrentUser(); 297 | } 298 | 299 | public function testGetUserPlaylist() 300 | { 301 | $response = $this->api->getUserPlaylist('beefkidney', '2YT3S2z4Q7qKbiPTIUiE2q'); 302 | 303 | $this->assertInstanceOf('Audeio\Spotify\Entity\Playlist', $response); 304 | } 305 | 306 | public function testGetUserPlaylistWithSelectFields() 307 | { 308 | $response = $this->api->getUserPlaylist('beefkidney', '2YT3S2z4Q7qKbiPTIUiE2q', array('id', 'name')); 309 | 310 | $this->assertInstanceOf('Audeio\Spotify\Entity\Playlist', $response); 311 | $this->assertNull($response->isCollaborative()); 312 | $this->assertNull($response->getDescription()); 313 | $this->assertNull($response->getExternalUrls()); 314 | $this->assertNull($response->getFollowers()); 315 | $this->assertNotNull($response->getHref()); 316 | $this->assertNotNull($response->getId()); 317 | $this->assertNull($response->getImages()); 318 | $this->assertNotNull($response->getName()); 319 | $this->assertNull($response->getOwner()); 320 | $this->assertNull($response->isPublic()); 321 | $this->assertNull($response->getTracks()); 322 | $this->assertNull($response->getType()); 323 | $this->assertNull($response->getUri()); 324 | } 325 | 326 | public function testGetUserPlaylistWhereUserDoesNotExist() 327 | { 328 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'Not found'); 329 | 330 | $this->api->getUserPlaylist('fake-user-made-up-by-me-for-testing-93874123', '2YT3S2z4Q7qKbiPTIUiE2q'); 331 | } 332 | 333 | public function testGetUserPlaylistWherePlaylistDoesNotExist() 334 | { 335 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'Not found'); 336 | 337 | $this->api->getUserPlaylist('beefkidney', 'fake-playlist'); 338 | } 339 | 340 | public function testGetUserPlaylistTracks() 341 | { 342 | $response = $this->api->getUserPlaylistTracks('beefkidney', '2YT3S2z4Q7qKbiPTIUiE2q'); 343 | 344 | $this->assertInstanceOf('Audeio\Spotify\Entity\PlaylistTrackPagination', $response); 345 | $this->assertNotNull($response->getHref()); 346 | $this->assertNotNull($response->getLimit()); 347 | $this->assertNotNull($response->getOffset()); 348 | $this->assertNotNull($response->getTotal()); 349 | } 350 | 351 | public function testGetUserPlaylistTracksWithSelectFields() 352 | { 353 | $response = $this->api->getUserPlaylistTracks( 354 | 'beefkidney', 355 | '2YT3S2z4Q7qKbiPTIUiE2q', 356 | array('href', 'items.track.name', 'items.track.uri') 357 | ); 358 | 359 | $this->assertInstanceOf('Audeio\Spotify\Entity\PlaylistTrackPagination', $response); 360 | $this->assertNotNull($response->getHref()); 361 | $this->assertNotNull($response->getLimit()); 362 | $this->assertNotNull($response->getOffset()); 363 | $this->assertNotNull($response->getTotal()); 364 | $this->assertNull($response->getItems()->first()->getTrack()->getId()); 365 | $this->assertNotNull($response->getItems()->first()->getTrack()->getName()); 366 | $this->assertNotNull($response->getItems()->first()->getTrack()->getUri()); 367 | } 368 | 369 | public function testGetUserPlaylistTracksWhereUserDoesNotExist() 370 | { 371 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'Not found'); 372 | 373 | $this->api->getUserPlaylistTracks('fake-user-made-up-by-me-for-testing-93874123', '2YT3S2z4Q7qKbiPTIUiE2q'); 374 | } 375 | 376 | public function testGetUserPlaylistTracksWherePlaylistDoesNotExist() 377 | { 378 | $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'Not found'); 379 | 380 | $this->api->getUserPlaylistTracks('beefkidney', 'fake-playlist'); 381 | } 382 | 383 | public function testGetUserPlaylists() 384 | { 385 | $response = $this->api->getUserPlaylists('beefkidney'); 386 | 387 | $this->assertInstanceOf('Audeio\Spotify\Entity\PlaylistPagination', $response); 388 | $this->assertNotNull($response->getHref()); 389 | $this->assertNotNull($response->getLimit()); 390 | $this->assertNotNull($response->getOffset()); 391 | $this->assertNotNull($response->getTotal()); 392 | } 393 | 394 | public function testGetUserPlaylistsWhereUserDoesNotExist() 395 | { 396 | // TODO: Check with Spotify is this is really meant to return an empty Pagination object 397 | // $this->setExpectedException('Audeio\Spotify\Exception\SpotifyException', 'No such user'); 398 | 399 | $response = $this->api->getUserPlaylists('fake-user-made-up-by-me-for-testing-93874123'); 400 | 401 | $this->assertInstanceOf('Audeio\Spotify\Entity\PlaylistPagination', $response); 402 | $this->assertNotNull($response->getHref()); 403 | $this->assertSame(0, $response->getItems()->count()); 404 | $this->assertSame(20, $response->getLimit()); 405 | $this->assertNotNull($response->getOffset()); 406 | $this->assertNotNull($response->getTotal()); 407 | } 408 | } 409 | -------------------------------------------------------------------------------- /tests/Bootstrap.php: -------------------------------------------------------------------------------- 1 |