Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit d077b47

Browse files
authored
Added Artist follow!, unfollow! and following= methods (#40)
* added tests * Added follow! and unfollow! methods * Added following= alias * Added code sample for session.rb
1 parent d51bfb1 commit d077b47

File tree

4 files changed

+158
-62
lines changed

4 files changed

+158
-62
lines changed

COVERAGE.md

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@ This covers all the Spotify API endpoints that are covered.
66

77
| Endpoint | Description | Coverage Status |
88
| -------------------------- | --------------------- | --------------- |
9-
| GET /v1/albums | Get Several Albums | × |
10-
| GET /v1/albums/{id}/tracks | Get an Album's Tracks | × |
9+
| GET /v1/albums | Get Several Albums | × Not Started |
10+
| GET /v1/albums/{id}/tracks | Get an Album's Tracks | × Not Started |
1111

1212
### Artists Endpoints
1313

1414
| Endpoint | Description | Coverage Status |
1515
| ------------------------------------ | ------------------------------- | --------------- |
16-
| GET /v1/artists | Get Several Artists | × |
17-
| GET /v1/artists/{id}/albums | Get an Artist's Albums | × |
18-
| GET /v1/artists/{id}/top-tracks | Get an Artist's Top Tracks | × |
19-
| GET /v1/artists/{id}/related-artists | Get an Artist's Related Artists | × |
16+
| GET /v1/artists | Get Several Artists | × Not Started |
17+
| GET /v1/artists/{id}/albums | Get an Artist's Albums | × Not Started |
18+
| GET /v1/artists/{id}/top-tracks | Get an Artist's Top Tracks | × Not Started |
19+
| GET /v1/artists/{id}/related-artists | Get an Artist's Related Artists | × Not Started |
2020

2121
### Tracks Endpoints
2222

2323
| Endpoint | Description | Coverage Status |
2424
| -------------- | ------------------ | --------------- |
25-
| GET /v1/tracks | Get Several Tracks | × |
25+
| GET /v1/tracks | Get Several Tracks | × Not Started |
2626

2727
### Audio Features Endpoints
2828

2929
| Endpoint | Description | Coverage Status |
3030
| --------------------------- | ------------------------------------- | --------------- |
31-
| GET /v1/audio-features/{id} | Get Audio Features for a Track | × |
32-
| GET /v1/audio-features | Get Audio Features for Several Tracks | × |
31+
| GET /v1/audio-features/{id} | Get Audio Features for a Track | × Not Started |
32+
| GET /v1/audio-features | Get Audio Features for Several Tracks | × Not Started |
3333

3434
### Analysis Endpoints
3535

3636
| Endpoint | Description | Coverage Status |
3737
| --------------------------- | ------------------------------ | --------------- |
38-
| GET /v1/audio-analysis/{id} | Get Audio Analysis for a Track | × |
38+
| GET /v1/audio-analysis/{id} | Get Audio Analysis for a Track | × Not Started |
3939

4040
### Search Endpoints
4141

4242
| Endpoint | Description | Coverage Status |
4343
| -------------- | ------------------ | --------------- |
44-
| GET /v1/search | Search for an Item | × |
44+
| GET /v1/search | Search for an Item | × Not Started |
4545

4646
### Users Endpoints
4747

@@ -54,94 +54,95 @@ This covers all the Spotify API endpoints that are covered.
5454

5555
| Endpoint | Description | Coverage Status |
5656
| -------------------------- | --------------------------------- | --------------- |
57-
| GET /v1/me/tracks | Get Current User's Saved Tracks | × |
58-
| GET /v1/me/tracks/contains | Check Current User's Saved Tracks | × |
59-
| PUT /v1/me/tracks | Save Tracks for Current User | × |
60-
| DELETE /v1/me/tracks | Remove Tracks for Current User | × |
61-
| GET /v1/me/albums | Get Current User's Saved Albums | × |
62-
| GET /v1/me/albums/contains | Check Current User's Saved Albums | × |
63-
| PUT /v1/me/albums | Save Albums for Current User | × |
64-
| DELETE /v1/me/albums | Remove Albums for Current User | × |
57+
| GET /v1/me/tracks | Get Current User's Saved Tracks | × Not Started |
58+
| GET /v1/me/tracks/contains | Check Current User's Saved Tracks | × Not Started |
59+
| PUT /v1/me/tracks | Save Tracks for Current User | × Not Started |
60+
| DELETE /v1/me/tracks | Remove Tracks for Current User | × Not Started |
61+
| GET /v1/me/albums | Get Current User's Saved Albums | × Not Started |
62+
| GET /v1/me/albums/contains | Check Current User's Saved Albums | × Not Started |
63+
| PUT /v1/me/albums | Save Albums for Current User | × Not Started |
64+
| DELETE /v1/me/albums | Remove Albums for Current User | × Not Started |
6565

6666
### Discovery Endpoints
6767

6868
| Endpoint | Description | Coverage Status |
6969
| --------------------------------- | -------------------------------- | --------------- |
70-
| GET /v1/browse/new-releases | Get a List of New Releases | × |
71-
| GET /v1/browse/featured-playlists | Get a List of Featured Playlists | × |
70+
| GET /v1/browse/new-releases | Get a List of New Releases | × Not Started |
71+
| GET /v1/browse/featured-playlists | Get a List of Featured Playlists | × Not Started |
7272

7373
### Categories Endpoints
7474

7575
| Endpoint | Description | Coverage Status |
7676
| ------------------------------------------------- | ------------------------------- | --------------- |
77-
| GET /v1/browse/categories | Get a List of Browse Categories | × |
78-
| GET /v1/browse/categories/{category_id} | Get a Single Browse Category | × |
79-
| GET /v1/browse/categories/{category_id}/playlists | Get a Category's playlists | × |
77+
| GET /v1/browse/categories | Get a List of Browse Categories | × Not Started |
78+
| GET /v1/browse/categories/{category_id} | Get a Single Browse Category | × Not Started |
79+
| GET /v1/browse/categories/{category_id}/playlists | Get a Category's playlists | × Not Started |
8080

8181
### Recommendation Endpoints
8282

8383
| Endpoint | Description | Coverage Status |
8484
| --------------------------------------------- | ---------------------------------- | --------------- |
85-
| GET /v1/recommendations | Get Recommendations Based on Seeds | × |
86-
| GET /v1/recommendations/available-genre-seeds | Get Available Genre Seeds | × |
85+
| GET /v1/recommendations | Get Recommendations Based on Seeds | × Not Started |
86+
| GET /v1/recommendations/available-genre-seeds | Get Available Genre Seeds | × Not Started |
8787

8888
### Follow Endpoints
8989

90-
| Endpoint | Description | Coverage Status |
91-
| ------------------------------------------------------------------ | ---------------------------------------------- | --------------- |
92-
| GET /v1/me/following | Get Followed Artists | [me.rb] |
93-
| GET /v1/me/following/contains | Check if Current User Follows Artists or Users | [me.rb] |
94-
| PUT /v1/me/following | Follow Artists or Users | × |
95-
| DELETE /v1/me/following | Unfollow Artists or Users | × |
96-
| GET /v1/users/{user_id}/playlists/{playlist_id}/followers/contains | Check if Users Follow a Playlist | × |
97-
| PUT /v1/users/{user_id}/playlists/{playlist_id}/followers | Follow a Playlist | × |
98-
| DELETE /v1/users/{user_id}/playlists/{playlist_id}/followers | Unfollow a Playlist | × |
90+
| Endpoint | Description | Coverage Status |
91+
| ------------------------------------------------------------------ | ---------------------------------------------- | ---------------------------------------------------------------------- |
92+
| GET /v1/me/following | Get Followed Artists | [me.rb] |
93+
| GET /v1/me/following/contains | Check if Current User Follows Artists or Users | [me.rb] |
94+
| PUT /v1/me/following | Follow Artists or Users | [🔘 Partial Support][artist.rb] (Following multiple isn't supported) |
95+
| DELETE /v1/me/following | Unfollow Artists or Users | [🔘 Partial Support][artist.rb] (Unfollowing multiple isn't supported) |
96+
| GET /v1/users/{user_id}/playlists/{playlist_id}/followers/contains | Check if Users Follow a Playlist | × Not Started |
97+
| PUT /v1/users/{user_id}/playlists/{playlist_id}/followers | Follow a Playlist | × Not Started |
98+
| DELETE /v1/users/{user_id}/playlists/{playlist_id}/followers | Unfollow a Playlist | × Not Started |
9999

100100
### Playlists Endpoints
101101

102102
| Endpoint | Description | Coverage Status |
103103
| --------------------------------------------------------- | -------------------------------------- | --------------- |
104-
| GET /v1/users/{user_id}/playlists | Get a List of a User's Playlists | × |
105-
| GET /v1/me/playlists | Get a List of Current User's Playlists | × |
106-
| GET /v1/users/{user_id}/playlists/{playlist_id} | Get a Playlist | × |
107-
| GET /v1/users/{user_id}/playlists/{playlist_id}/tracks | Get a Playlist's Tracks | × |
108-
| POST /v1/users/{user_id}/playlists | Create a Playlist | × |
109-
| POST /v1/users/{user_id}/playlists/{playlist_id}/tracks | Add Tracks to a Playlist | × |
110-
| DELETE /v1/users/{user_id}/playlists/{playlist_id}/tracks | Remove Tracks from a Playlist | × |
111-
| PUT /v1/users/{user_id}/playlists/{playlist_id}/tracks | Reorder or replace a Playlist's Tracks | × |
112-
| PUT /v1/users/{user_id}/playlists/{playlist_id} | Change a Playlist's Details | × |
104+
| GET /v1/users/{user_id}/playlists | Get a List of a User's Playlists | × Not Started |
105+
| GET /v1/me/playlists | Get a List of Current User's Playlists | × Not Started |
106+
| GET /v1/users/{user_id}/playlists/{playlist_id} | Get a Playlist | × Not Started |
107+
| GET /v1/users/{user_id}/playlists/{playlist_id}/tracks | Get a Playlist's Tracks | × Not Started |
108+
| POST /v1/users/{user_id}/playlists | Create a Playlist | × Not Started |
109+
| POST /v1/users/{user_id}/playlists/{playlist_id}/tracks | Add Tracks to a Playlist | × Not Started |
110+
| DELETE /v1/users/{user_id}/playlists/{playlist_id}/tracks | Remove Tracks from a Playlist | × Not Started |
111+
| PUT /v1/users/{user_id}/playlists/{playlist_id}/tracks | Reorder or replace a Playlist's Tracks | × Not Started |
112+
| PUT /v1/users/{user_id}/playlists/{playlist_id} | Change a Playlist's Details | × Not Started |
113113

114114
### History Endpoints
115115

116116
| Endpoint | Description | Coverage Status |
117117
| --------------------------------- | --------------------------------------------- | --------------- |
118-
| GET /v1/me/top/{type} | Get User's Top Artists and Tracks | × |
119-
| GET /v1/me/player/recently-played | Get the Current User's Recently Played Tracks | × |
118+
| GET /v1/me/top/{type} | Get User's Top Artists and Tracks | × Not Started |
119+
| GET /v1/me/player/recently-played | Get the Current User's Recently Played Tracks | × Not Started |
120120

121121
### Connect Endpoints
122122

123-
| Endpoint | Description | Coverage Status |
124-
| ------------------------- | ------------------------------------------------- | ------------------------------ |
125-
| GET /v1/me/player | Get Information About The User's Current Playback | [][connect/playback_state.rb] |
126-
| GET /v1/me/player/devices | Get a User's Available Devices | [][connect.rb] |
127-
| PUT /v1/me/player | Transfer a User's Playback | [][connect/device.rb] |
123+
| Endpoint | Description | Coverage Status |
124+
| ------------------------- | ------------------------------------------------- | ------------------------------------------- |
125+
| GET /v1/me/player | Get Information About The User's Current Playback | [Full support ][connect/playback_state.rb] |
126+
| GET /v1/me/player/devices | Get a User's Available Devices | [Full support ][connect.rb] |
127+
| PUT /v1/me/player | Transfer a User's Playback | [Full support ][connect/device.rb] |
128128

129129
### Player Endpoints
130130

131-
| Endpoint | Description | Coverage Status |
132-
| ----------------------------------- | ------------------------------------------- | ---------------------- |
133-
| GET /v1/me/player/currently-playing | Get the User's Currently Playing Track | Unused |
134-
| PUT /v1/me/player/play | Start/Resume a User's Playback | [][connect/device.rb] |
135-
| PUT /v1/me/player/pause | Pause a User's Playback | [][connect/device.rb] |
136-
| POST /v1/me/player/next | Skip User's Playback To Next Track | [][connect/device.rb] |
137-
| POST /v1/me/player/previous | Skip User's Playback To Previous Track | [][connect/device.rb] |
138-
| PUT /v1/me/player/seek | Seek To Position In Currently Playing Track | [][connect/device.rb] |
139-
| PUT /v1/me/player/repeat | Set Repeat Mode On User's Playback | [][connect/device.rb] |
140-
| PUT /v1/me/player/volume | Set Volume For User's Playback | [][connect/device.rb] |
141-
| PUT /v1/me/player/shuffle | Toggle Shuffle For User's Playback | [][connect/device.rb] |
131+
| Endpoint | Description | Coverage Status |
132+
| ----------------------------------- | ------------------------------------------- | ----------------------------------- |
133+
| GET /v1/me/player/currently-playing | Get the User's Currently Playing Track | × Not implementing |
134+
| PUT /v1/me/player/play | Start/Resume a User's Playback | [Full support ][connect/device.rb] |
135+
| PUT /v1/me/player/pause | Pause a User's Playback | [Full support ][connect/device.rb] |
136+
| POST /v1/me/player/next | Skip User's Playback To Next Track | [Full support ][connect/device.rb] |
137+
| POST /v1/me/player/previous | Skip User's Playback To Previous Track | [Full support ][connect/device.rb] |
138+
| PUT /v1/me/player/seek | Seek To Position In Currently Playing Track | [Full support ][connect/device.rb] |
139+
| PUT /v1/me/player/repeat | Set Repeat Mode On User's Playback | [Full support ][connect/device.rb] |
140+
| PUT /v1/me/player/volume | Set Volume For User's Playback | [Full support ][connect/device.rb] |
141+
| PUT /v1/me/player/shuffle | Toggle Shuffle For User's Playback | [Full support ][connect/device.rb] |
142142

143143
[connect.rb]: /lib/spotify/sdk/connect.rb
144144
[connect/playback_state.rb]: /lib/spotify/sdk/connect/playback_state.rb
145145
[connect/device.rb]: /lib/spotify/sdk/connect/device.rb
146+
[artist.rb]: /lib/spotify/sdk/artist.rb
146147
[me.rb]: /lib/spotify/sdk/me.rb
147148
[me/info.rb]: /lib/spotify/sdk/me/info.rb

lib/spotify/accounts/session.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class << self
1010
##
1111
# Parse the response we collect from the authorization code.
1212
#
13+
# @example
14+
# @session = Spotify::Accounts.from_authorization_code(@accounts, "authorization code here")
15+
#
1316
# @param [Spotify::Accounts] accounts A valid instance of Spotify::Accounts.
1417
# @param [String] code The code provided in the Redirect URI from the Spotify Accounts API.
1518
# @response [Spotify::Accounts::Session] access_token An instance of Spotify::Accounts::Session

lib/spotify/sdk/artist.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,50 @@ def retrieve_full_information!
3535
true
3636
end
3737

38+
##
39+
# Helper method for setting the following status.
40+
# Requires the `user-follow-modify` scope.
41+
# If true, PUT /v1/me/following otherwise DELETE /v1/me/following
42+
#
43+
# @example
44+
# @sdk.playback.item.artist.following = true
45+
# @sdk.playback.item.artist.following = false
46+
#
47+
def following=(should_follow)
48+
raise "#following= must be true or false" unless [true, false].include?(should_follow)
49+
should_follow ? follow! : unfollow!
50+
end
51+
52+
##
53+
# Follow the artist.
54+
# Requires the `user-follow-modify` scope.
55+
# PUT /v1/me/following
56+
#
57+
# @example
58+
# @sdk.playback.item.artist.follow!
59+
#
60+
# @return [Spotify::SDK::Artist] self Return the artist object, for chaining methods.
61+
#
62+
def follow!
63+
parent.send_http_request(:put, "/v1/me/following?type=artist&ids=%s" % id, http_options: {expect_nil: true})
64+
self
65+
end
66+
67+
##
68+
# Unfollow the artist.
69+
# Requires the `user-follow-modify` scope.
70+
# DELETE /v1/me/following
71+
#
72+
# @example
73+
# @sdk.playback.item.artist.unfollow!
74+
#
75+
# @return [Spotify::SDK::Artist] self Return the artist object, for chaining methods.
76+
#
77+
def unfollow!
78+
parent.send_http_request(:delete, "/v1/me/following?type=artist&ids=%s" % id, http_options: {expect_nil: true})
79+
self
80+
end
81+
3882
##
3983
# Display the artist's images. If not obtained, request them from the API.
4084
#

0 commit comments

Comments
 (0)