Skip to content

Commit

Permalink
Added method to check if user follows a playlist #16
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemoore committed Mar 19, 2015
1 parent 116ef9b commit 6cee025
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ Spotify.reorderPlaylistTracks('1176458919', '2TkWjGCu8jurholsfdWtG4', {
range_start: 8,
range_length: 5,
insert_before: 0
}).then(function (data) {
console.log(data);
});
```

Expand Down Expand Up @@ -477,6 +479,21 @@ Spotify.unfollowPlaylist('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT').then(function
});
```

####Check if Users Follow a Playlist
Check to see if one or more Spotify users are following a specified playlist.Following a playlist can be done publicly or privately. Checking if a user publicly follows a playlist doesn't require any scopes; if the user is publicly following the playlist, this endpoint returns true.

Checking if the user is privately following a playlist is only possible for the current user when that user has granted access to the ```playlist-read-private``` scope.
```javascript
Spotify.playlistFollowingContains('owner_id', 'playlist_id', 'comma separated string or array of user ids');
```
Example:
```javascript
Spotify.playlistFollowingContains('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT', 'possan,elogain').then(function (data) {
console.log(data);
});
```


###User Profiles
User needs to be logged in to gain access to user profiles

Expand Down
2 changes: 1 addition & 1 deletion dist/angular-spotify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/angular-spotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,14 @@
});
};

NgSpotify.prototype.playlistFollowingContains = function(userId, playlistId, ids) {
return this.api('/users/' + userId + '/playlists/' + playlistId + '/followers/contains', 'GET', {
ids: ids.toString()
}, null, {
'Authorization': 'Bearer ' + this.authToken
});
};

/**
====================== Login =====================
*/
Expand Down
36 changes: 36 additions & 0 deletions test/spec/angular-spotify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ describe('angular-spotify', function () {
expect(Spotify.unfollowPlaylist).toBeDefined();
});

it('should have a method playlistFollowingContains()', function () {
expect(Spotify.playlistFollowingContains).toBeDefined();
});


describe('Spotify.api', function () {
var $httpBackend;
Expand Down Expand Up @@ -1655,6 +1659,38 @@ describe('angular-spotify', function () {
});
});
});

describe('Spotify.playlistFollowingContains', function () {
it('should call the correct URL', function () {
spyOn(Spotify, 'api');

Spotify.setAuthToken('TESTING');

Spotify.playlistFollowingContains('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT', 'possan,elogain');

expect(Spotify.api).toHaveBeenCalled();
expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers/contains', 'GET', {
ids: 'possan,elogain'
}, null, {
'Authorization': 'Bearer TESTING'
});
});

it('should be able to be called with an array of users', function () {
spyOn(Spotify, 'api');

Spotify.setAuthToken('TESTING');

Spotify.playlistFollowingContains('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT', ['possan','elogain']);

expect(Spotify.api).toHaveBeenCalled();
expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers/contains', 'GET', {
ids: 'possan,elogain'
}, null, {
'Authorization': 'Bearer TESTING'
});
});
});
});

});
Expand Down

0 comments on commit 6cee025

Please sign in to comment.