Skip to content

Commit

Permalink
Add follow and favorite methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Radt committed Nov 1, 2017
1 parent b64b597 commit 6b1e153
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/DeezerAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,34 @@ public function getAlbumTracks($albumId)

return $this->client->apiRequest('GET', 'album/'.$albumId.'/tracks');
}

/**
* Add an artist to the user's favorites.
* @param string|int $artistId
* @return array|object
* @throws DeezerAPIException
*/
public function addArtistToFavorites($artistId)
{
if (empty($artistId)) {
throw new DeezerAPIException('Favorite artist: invalid artistId');
}

return $this->client->apiRequest('POST', 'user/me/artists', [], sprintf('artist_id=%s', $artistId));
}

/**
* Follow user.
* @param string|int $userId
* @return array|object
* @throws DeezerAPIException
*/
public function followUser($userId)
{
if (empty($userId)) {
throw new DeezerAPIException('Follow user: invalid userId');
}

return $this->client->apiRequest('POST', 'user/me/following', [], sprintf('user_id=%s', $userId));
}
}
44 changes: 44 additions & 0 deletions tests/DeezerAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,48 @@ public function testAlbumTracks()

self::assertEquals('{}', $this->deezerApi->getAlbumTracks(1234));
}

/**
* @expectedException \PouleR\DeezerAPI\DeezerAPIException
* @expectedExceptionMessage Favorite artist: invalid artistId
*/
public function testArtistToFavoritesEmptyArtist()
{
$this->deezerApi->addArtistToFavorites('');
}

/**
*
*/
public function testArtistToFavorites()
{
$this->client->expects(static::once())
->method('apiRequest')
->with('POST', 'user/me/artists', [], 'artist_id=artist')
->willReturn('{}');

self::assertEquals('{}', $this->deezerApi->addArtistToFavorites('artist'));
}

/**
* @expectedException \PouleR\DeezerAPI\DeezerAPIException
* @expectedExceptionMessage Follow user: invalid userId
*/
public function testFollowUserEmptyUser()
{
$this->deezerApi->followUser(null);
}

/**
*
*/
public function testFollowUser()
{
$this->client->expects(static::once())
->method('apiRequest')
->with('POST', 'user/me/following', [], 'user_id=user')
->willReturn('{}');

self::assertEquals('{}', $this->deezerApi->followUser('user'));
}
}

0 comments on commit 6b1e153

Please sign in to comment.