rspotify 1.9.1 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e1815c6ec7f721220d003f5f6d9008a40d7f727
4
- data.tar.gz: d622ad7f253308753c81cad880116d39863d6b83
3
+ metadata.gz: 5468375f8403d6bbbceb4c409783c60938eeddf5
4
+ data.tar.gz: 57ff23567b2a528f62487f06ebaaa869eb37c5bf
5
5
  SHA512:
6
- metadata.gz: c55bb95033ed25c0de7a22da0016c07a2409173e0f9303e959a7ddc23d75bf1ced45285af3953f0d49678d5fb7a9506d92301dd70aa789be2f86fc310ee3f7cc
7
- data.tar.gz: 0c37346ee7bc3e07e8a05411a8481d6ae73a9da222dd698bfee8a981c44f5325fb6f29ac241aecc84c0e216b3556bdd788f59bcbdce31719177d4dcaecb30e34
6
+ metadata.gz: 0cba7bfcfdd1a430e76e0204515246373a8e47f32f1fc2caf6cac254c0d46e4a6d5137cce0d9e09a2cdce36eee420d1704d9c25f14d45e986add1706d33f2b1f
7
+ data.tar.gz: ebf800d7a4317423ce2e1960359c4e3a59439063f7ee504cba3f74c831378d06b17821c0ab2b151b24388a5afbfdbcf23798d268a88c2014c5ee5a347377b25c
data/README.md CHANGED
@@ -7,7 +7,7 @@ This is a ruby wrapper for the [new Spotify Web API](https://developer.spotify.c
7
7
 
8
8
  ## Features
9
9
 
10
- * [Full documentation](http://rdoc.info/github/guilhermesad/rspotify/master/frames)
10
+ * [Full documentation](http://www.rubydoc.info/github/guilhermesad/rspotify/master)
11
11
  * Full API Endpoint coverage
12
12
  * OAuth and other authorization flows
13
13
 
@@ -48,7 +48,7 @@ module RSpotify
48
48
  json['albums']['items'].map { |i| Album.new i }
49
49
  end
50
50
 
51
- # Returns array of Album objects matching the query, ordered by popularity
51
+ # Returns array of Album objects matching the query, ordered by popularity. It's also possible to find the total number of search results for the query
52
52
  #
53
53
  # @param query [String] The search query's keywords. For details access {https://developer.spotify.com/web-api/search-item here} and look for the q parameter description.
54
54
  # @param limit [Integer] Maximum number of albums to return. Maximum: 50. Default: 20.
@@ -60,6 +60,8 @@ module RSpotify
60
60
  # albums = RSpotify::Album.search('AM')
61
61
  # albums = RSpotify::Album.search('AM', limit: 10, market: 'US')
62
62
  # albums = RSpotify::Album.search('AM', market: { from: user })
63
+ #
64
+ # RSpotify::Album.search('AM').total #=> 9374
63
65
  def self.search(query, limit: 20, offset: 0, market: nil)
64
66
  super(query, 'album', limit: limit, offset: offset, market: market)
65
67
  end
@@ -25,7 +25,7 @@ module RSpotify
25
25
  super(ids, 'artist')
26
26
  end
27
27
 
28
- # Returns array of Artist objects matching the query, ordered by popularity
28
+ # Returns array of Artist objects matching the query, ordered by popularity. It's also possible to find the total number of search results for the query
29
29
  #
30
30
  # @param query [String] The search query's keywords. For details access {https://developer.spotify.com/web-api/search-item here} and look for the q parameter description.
31
31
  # @param limit [Integer] Maximum number of artists to return. Maximum: 50. Default: 20.
@@ -37,6 +37,8 @@ module RSpotify
37
37
  # artists = RSpotify::Artist.search('Arctic')
38
38
  # artists = RSpotify::Artist.search('Arctic', limit: 10, market: 'US')
39
39
  # artists = RSpotify::Artist.search('Arctic', market: { from: user })
40
+ #
41
+ # RSpotify::Artist.search('Arctic').total #=> 86
40
42
  def self.search(query, limit: 20, offset: 0, market: nil)
41
43
  super(query, 'artist', limit: limit, offset: offset, market: market)
42
44
  end
@@ -53,7 +53,20 @@ module RSpotify
53
53
  end
54
54
  private_class_method :find_one
55
55
 
56
- # Returns array of RSpotify objects matching the query, ordered by popularity
56
+ def self.insert_total(result, types, json)
57
+ result.instance_eval do
58
+ @total = types.map do |type|
59
+ json["#{type}s"]['total']
60
+ end.reduce(:+)
61
+
62
+ define_singleton_method :total do
63
+ @total
64
+ end
65
+ end
66
+ end
67
+ private_class_method :insert_total
68
+
69
+ # Returns array of RSpotify objects matching the query, ordered by popularity. It's also possible to find the total number of search results for the query
57
70
  #
58
71
  # @param query [String] The search query's keywords. For details access {https://developer.spotify.com/web-api/search-item here} and look for the q parameter description.
59
72
  # @param types [String] Valid types are: album, artist, track and playlist. Separate multiple types with commas.
@@ -67,6 +80,8 @@ module RSpotify
67
80
  # albums = RSpotify::Base.search('AM', 'album', limit: 10, market: 'US')
68
81
  # mixed = RSpotify::Base.search('Arctic', 'artist, album, track')
69
82
  # albums = RSpotify::Base.search('AM', 'album', market: { from: user })
83
+ #
84
+ # RSpotify::Base.search('Arctic', 'album,artist,playlist').total #=> 2142
70
85
  def self.search(query, types, limit: 20, offset: 0, market: nil)
71
86
  query = URI::encode query
72
87
  types.gsub!(/\s+/, '')
@@ -82,10 +97,14 @@ module RSpotify
82
97
  RSpotify.get(url)
83
98
  end
84
99
 
85
- types.split(',').flat_map do |type|
100
+ types = types.split(',')
101
+ result = types.flat_map do |type|
86
102
  type_class = RSpotify.const_get(type.capitalize)
87
103
  json["#{type}s"]['items'].map { |i| type_class.new i }
88
104
  end
105
+
106
+ insert_total(result, types, json)
107
+ result
89
108
  end
90
109
 
91
110
  def initialize(options = {})
@@ -137,5 +156,17 @@ module RSpotify
137
156
  return true if instance_variable_defined? attr
138
157
  super
139
158
  end
159
+
160
+ protected
161
+
162
+ def hash_for(tracks, field)
163
+ return nil unless tracks
164
+ pairs = tracks.map do |track|
165
+ key = track['track']['id']
166
+ value = yield track[field] if track[field]
167
+ [key, value]
168
+ end
169
+ Hash[pairs]
170
+ end
140
171
  end
141
172
  end
@@ -8,8 +8,9 @@ module RSpotify
8
8
  # @attr [User] owner The user who owns the playlist
9
9
  # @attr [Boolean] public true if the playlist is not marked as secret
10
10
  # @attr [String] snapshot_id The version identifier for the current playlist. Can be supplied in other requests to target a specific playlist version
11
- # @attr [Hash] tracks_added_at A hash containing the date and time each track was added to the playlist. Note: whenever {#tracks} is used the hash is updated with the correspondent tracks' values.
12
- # @attr [Hash] tracks_added_by A hash containing the user that added each track to the playlist. Note: whenever {#tracks} is used the hash is updated with the correspondent tracks' values.
11
+ # @attr [Integer] total The total number of tracks in the playlist
12
+ # @attr [Hash] tracks_added_at A hash containing the date and time each track was added to the playlist. Note: the hash is updated only when {#tracks} is used.
13
+ # @attr [Hash] tracks_added_by A hash containing the user that added each track to the playlist. Note: the hash is updated only when {#tracks} is used.
13
14
  class Playlist < Base
14
15
 
15
16
  # Get a list of Spotify featured playlists (shown, for example, on a Spotify player’s “Browse” tab).
@@ -54,7 +55,7 @@ module RSpotify
54
55
  Playlist.new json
55
56
  end
56
57
 
57
- # Returns array of Playlist objects matching the query
58
+ # Returns array of Playlist objects matching the query. It's also possible to find the total number of search results for the query
58
59
  #
59
60
  # @param query [String] The search query's keywords. See the q description in {https://developer.spotify.com/web-api/search-item here} for details.
60
61
  # @param limit [Integer] Maximum number of playlists to return. Maximum: 50. Default: 20.
@@ -63,12 +64,9 @@ module RSpotify
63
64
  #
64
65
  # @example
65
66
  # playlists = RSpotify::Playlist.search('Indie')
66
- # playlists.size #=> 20
67
- # playlists.first.class #=> RSpotify::Playlist
68
- # playlists.first.name #=> "The Indie Mix"
69
- #
70
67
  # playlists = RSpotify::Playlist.search('Indie', limit: 10)
71
- # playlists.size #=> 10
68
+ #
69
+ # RSpotify::Playlist.search('Indie').total #=> 14653
72
70
  def self.search(query, limit: 20, offset: 0)
73
71
  super(query, 'playlist', limit: limit, offset: offset)
74
72
  end
@@ -81,6 +79,7 @@ module RSpotify
81
79
  @name = options['name']
82
80
  @public = options['public']
83
81
  @snapshot_id = options['snapshot_id']
82
+ @total = options['tracks']['total']
84
83
 
85
84
  @owner = if options['owner']
86
85
  User.new options['owner']
@@ -127,7 +126,9 @@ module RSpotify
127
126
  url << "&position=#{position}" if position
128
127
 
129
128
  User.oauth_post(@owner.id, url, {})
129
+ @total += tracks.size
130
130
  @tracks_cache = nil
131
+
131
132
  tracks
132
133
  end
133
134
 
@@ -214,21 +215,13 @@ module RSpotify
214
215
  def replace_tracks!(tracks)
215
216
  track_uris = tracks.map(&:uri).join(',')
216
217
  url = @href + "/tracks?uris=#{track_uris}"
218
+
217
219
  User.oauth_put(@owner.id, url, {})
220
+ @total = tracks.size
218
221
  @tracks_cache = nil
222
+
219
223
  tracks
220
224
  end
221
225
 
222
- private
223
-
224
- def hash_for(tracks, field)
225
- return nil unless tracks
226
- pairs = tracks.map do |track|
227
- key = track['track']['id']
228
- value = yield track[field] if track[field]
229
- [key, value]
230
- end
231
- Hash[pairs]
232
- end
233
226
  end
234
227
  end
@@ -31,7 +31,7 @@ module RSpotify
31
31
  super(ids, 'track')
32
32
  end
33
33
 
34
- # Returns array of Track objects matching the query, ordered by popularity
34
+ # Returns array of Track objects matching the query, ordered by popularity. It's also possible to find the total number of search results for the query
35
35
  #
36
36
  # @param query [String] The search query's keywords. For details access {https://developer.spotify.com/web-api/search-item here} and look for the q parameter description.
37
37
  # @param limit [Integer] Maximum number of tracks to return. Maximum: 50. Default: 20.
@@ -43,6 +43,8 @@ module RSpotify
43
43
  # tracks = RSpotify::Track.search('Wanna Know')
44
44
  # tracks = RSpotify::Track.search('Wanna Know', limit: 10, market: 'US')
45
45
  # tracks = RSpotify::Track.search('Wanna Know', market: { from: user })
46
+ #
47
+ # RSpotify::Track.search('Wanna Know').total #=> 3686
46
48
  def self.search(query, limit: 20, offset: 0, market: nil)
47
49
  super(query, 'track', limit: limit, offset: offset, market: market)
48
50
  end
@@ -1,12 +1,13 @@
1
1
  module RSpotify
2
2
 
3
- # @attr [String] country The country of the user, as set in the user's account profile. An {http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country code}. This field is only available when the current user has granted access to the *user-read-private* scope.
4
- # @attr [Hash] credentials The credentials generated for the user with OAuth. Includes access token, token type, token expiration time and refresh token. This field is only available when the current user has granted access to any scope.
5
- # @attr [String] display_name The name displayed on the user's profile. This field is only available when the current user has granted access to the *user-read-private* scope.
6
- # @attr [String] email The user's email address. This field is only available when the current user has granted access to the *user-read-email* scope.
7
- # @attr [Hash] followers Information about the followers of the user
8
- # @attr [Array] images The user's profile image. This field is only available when the current user has granted access to the *user-read-private* scope.
9
- # @attr [String] product The user's Spotify subscription level: "premium", "free", etc. This field is only available when the current user has granted access to the *user-read-private* scope.
3
+ # @attr [String] country The country of the user, as set in the user's account profile. An {http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country code}. This field is only available when the current user has granted access to the *user-read-private* scope.
4
+ # @attr [Hash] credentials The credentials generated for the user with OAuth. Includes access token, token type, token expiration time and refresh token. This field is only available when the current user has granted access to any scope.
5
+ # @attr [String] display_name The name displayed on the user's profile. This field is only available when the current user has granted access to the *user-read-private* scope.
6
+ # @attr [String] email The user's email address. This field is only available when the current user has granted access to the *user-read-email* scope.
7
+ # @attr [Hash] followers Information about the followers of the user
8
+ # @attr [Array] images The user's profile image. This field is only available when the current user has granted access to the *user-read-private* scope.
9
+ # @attr [String] product The user's Spotify subscription level: "premium", "free", etc. This field is only available when the current user has granted access to the *user-read-private* scope.
10
+ # @attr [Hash] tracks_added_at A hash containing the date and time each track was saved by the user. Note: the hash is filled and updated only when {#saved_tracks} is used.
10
11
  class User < Base
11
12
 
12
13
  # Returns User object with id provided
@@ -105,9 +106,44 @@ module RSpotify
105
106
  Playlist.new User.oauth_post(@id, url, request_data)
106
107
  end
107
108
 
109
+ # Add the current user as a follower of one or more artists or other Spotify users. This method
110
+ # is only available when the current user has granted access to the *user-follow-modify* scope.
111
+ #
112
+ # @param followed [Array<User>, Array<Artist>] The users or artists to follow
113
+ # @return [Array<User>, Array<Artist>]
114
+ #
115
+ # @example
116
+ # artists = RSpotify::Artist.search('John')
117
+ # user.follow(artists)
118
+ def follow(followed)
119
+ type = followed.first.type
120
+ ids = followed.map(&:id).join(',')
121
+ url = "me/following?type=#{type}&ids=#{ids}"
122
+
123
+ User.oauth_put(@id, url, {})
124
+ followed
125
+ end
126
+
127
+ # Check to see if the current user is following one or more artists or other Spotify users. This method
128
+ # is only available when the current user has granted access to the *user-follow-read* scope.
129
+ #
130
+ # @param followed [Array<User>, Array<Artist>] The users or artists to check
131
+ # @return [Array<Boolean>]
132
+ #
133
+ # @example
134
+ # artists = RSpotify::Artist.search('John')
135
+ # user.follows?(artists) #=> [true, false, true...]
136
+ def follows?(followed)
137
+ type = followed.first.type
138
+ ids = followed.map(&:id).join(',')
139
+ url = "me/following/contains?type=#{type}&ids=#{ids}"
140
+
141
+ User.oauth_get(@id, url)
142
+ end
143
+
108
144
  # Returns all playlists from user
109
145
  #
110
- # @param limit [Integer] Maximum number of playlists to return. Maximum: 50. Default: 20.
146
+ # @param limit [Integer] Maximum number of playlists to return. Maximum: 50. Minimum: 1. Default: 20.
111
147
  # @param offset [Integer] The index of the first playlist to return. Use with limit to get the next set of playlists. Default: 0.
112
148
  # @return [Array<Playlist>]
113
149
  #
@@ -161,7 +197,7 @@ module RSpotify
161
197
 
162
198
  # Returns the tracks saved in the Spotify user’s “Your Music” library
163
199
  #
164
- # @param limit [Integer] Maximum number of tracks to return. Maximum: 50. Default: 20.
200
+ # @param limit [Integer] Maximum number of tracks to return. Maximum: 50. Minimum: 1. Default: 20.
165
201
  # @param offset [Integer] The index of the first track to return. Use with limit to get the next set of tracks. Default: 0.
166
202
  # @return [Array<Track>]
167
203
  #
@@ -172,7 +208,13 @@ module RSpotify
172
208
  def saved_tracks(limit: 20, offset: 0)
173
209
  url = "me/tracks?limit=#{limit}&offset=#{offset}"
174
210
  json = User.oauth_get(@id, url)
175
- json['items'].map { |i| Track.new i['track'] }
211
+
212
+ tracks = json['items'].select { |i| i['track'] }
213
+ @tracks_added_at = hash_for(tracks, 'added_at') do |added_at|
214
+ Time.parse added_at
215
+ end
216
+
217
+ tracks.map { |t| Track.new t['track'] }
176
218
  end
177
219
 
178
220
  # Check if tracks are already saved in the Spotify user’s “Your Music” library
@@ -196,5 +238,23 @@ module RSpotify
196
238
  end
197
239
  Hash[pairs]
198
240
  end
241
+
242
+ # Remove the current user as a follower of one or more artists or other Spotify users. This method
243
+ # is only available when the current user has granted access to the *user-follow-modify* scope.
244
+ #
245
+ # @param followed [Array<User>, Array<Artist>] The users or artists to unfollow
246
+ # @return [Array<User>, Array<Artist>]
247
+ #
248
+ # @example
249
+ # artists = RSpotify::Artist.search('John')
250
+ # user.unfollow(artists)
251
+ def unfollow(unfollowed)
252
+ type = unfollowed.first.type
253
+ ids = unfollowed.map(&:id).join(',')
254
+ url = "me/following?type=#{type}&ids=#{ids}"
255
+
256
+ User.oauth_delete(@id, url)
257
+ unfollowed
258
+ end
199
259
  end
200
260
  end
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '1.9.1'
2
+ VERSION = '1.10.0'
3
3
  end
@@ -106,6 +106,7 @@ describe RSpotify::Album do
106
106
  end
107
107
  expect(albums) .to be_an Array
108
108
  expect(albums.size) .to eq 20
109
+ expect(albums.total) .to eq 8672
109
110
  expect(albums.first) .to be_an RSpotify::Album
110
111
  expect(albums.map(&:name)) .to include('AM', 'Am I Wrong', 'A.M.', 'Melody AM')
111
112
  end
@@ -81,6 +81,7 @@ describe RSpotify::Artist do
81
81
  end
82
82
  expect(artists) .to be_an Array
83
83
  expect(artists.size) .to eq 20
84
+ expect(artists.total) .to eq 81
84
85
  expect(artists.first) .to be_an RSpotify::Artist
85
86
  expect(artists.map(&:name)) .to include('Arctic Monkeys', 'Arctic', 'Arctic Warbler', 'Arctic Express')
86
87
  end
@@ -17,7 +17,7 @@ describe RSpotify::Playlist do
17
17
 
18
18
  describe 'Playlist::browse_featured' do
19
19
  it 'should find the appropriate featured playlists' do
20
- playlists = VCR.use_cassette('playlist:browse_featured') do
20
+ playlists = VCR.use_cassette('playlist:browse_featured') do
21
21
  RSpotify::Playlist.browse_featured
22
22
  end
23
23
  expect(playlists.size) .to eq 13
@@ -25,19 +25,19 @@ describe RSpotify::Playlist do
25
25
  end
26
26
 
27
27
  it 'should accept additional options' do
28
- playlists = VCR.use_cassette('playlist:browse_featured:limit:10:offset:10') do
28
+ playlists = VCR.use_cassette('playlist:browse_featured:limit:10:offset:10') do
29
29
  RSpotify::Playlist.browse_featured(limit: 10, offset: 10)
30
30
  end
31
31
  expect(playlists.size) .to eq 3
32
32
  expect(playlists.map(&:name)) .to include('Sleep', 'Late Night R&B')
33
33
 
34
- playlists = VCR.use_cassette('playlist:browse_featured:locale:es_MX') do
34
+ playlists = VCR.use_cassette('playlist:browse_featured:locale:es_MX') do
35
35
  RSpotify::Playlist.browse_featured(locale: 'es_MX')
36
36
  end
37
37
  expect(playlists.size) .to eq 13
38
38
  expect(playlists.map(&:name)) .to include('Dance Mega Mix', 'Peaceful Piano', 'Sleep')
39
39
 
40
- playlists = VCR.use_cassette('playlist:browse_featured:country:ES:timestamp:2014-10-23T09:00:00') do
40
+ playlists = VCR.use_cassette('playlist:browse_featured:country:ES:timestamp:2014-10-23T09:00:00') do
41
41
  RSpotify::Playlist.browse_featured(country: 'ES', timestamp: '2014-10-23T09:00:00')
42
42
  end
43
43
  expect(playlists.size) .to eq 17
@@ -65,6 +65,7 @@ describe RSpotify::Playlist do
65
65
  expect(playlist.name) .to eq 'Movie Soundtrack Masterpieces'
66
66
  expect(playlist.public) .to eq true
67
67
  expect(playlist.snapshot_id) .to eq 'ViCZCcnhRtzkGq09wO4OPxvC/UBP/ZqMjrmTYoNurZ706SIXyMJiKb/zj27NYjiP'
68
+ expect(playlist.total) .to eq 53
68
69
  expect(playlist.type) .to eq 'playlist'
69
70
  expect(playlist.uri) .to eq 'spotify:user:wizzler:playlist:00wHcTN0zQiun4xri9pmvX'
70
71
  end
@@ -104,37 +105,39 @@ describe RSpotify::Playlist do
104
105
 
105
106
  context 'starred playlist' do
106
107
  it "should support starred playlists" do
107
- expect(starred_playlist.name).to eq 'Starred'
108
- expect(starred_playlist.href).to eq 'https://api.spotify.com/v1/users/118430647/starred'
108
+ expect(starred_playlist.name) .to eq 'Starred'
109
+ expect(starred_playlist.href) .to eq 'https://api.spotify.com/v1/users/118430647/starred'
110
+ expect(starred_playlist.total).to eq 185
109
111
  end
110
112
  end
111
113
  end
112
114
 
113
115
  describe 'Playlist::search' do
114
116
  it 'should search for the right playlists' do
115
- playlists = VCR.use_cassette('playlist:search:Indie') do
117
+ playlists = VCR.use_cassette('playlist:search:Indie') do
116
118
  RSpotify::Playlist.search('Indie')
117
119
  end
118
120
  expect(playlists) .to be_an Array
119
121
  expect(playlists.size) .to eq 20
122
+ expect(playlists.total) .to eq 14027
120
123
  expect(playlists.first) .to be_an RSpotify::Playlist
121
124
  expect(playlists.map(&:name)) .to include('The Indie Mix', 'Indie Folk', 'Alt/Indie')
122
125
  end
123
126
 
124
127
  it 'should accept additional options' do
125
- playlists = VCR.use_cassette('playlist:search:Indie:limit:10') do
128
+ playlists = VCR.use_cassette('playlist:search:Indie:limit:10') do
126
129
  RSpotify::Playlist.search('Indie', limit: 10)
127
130
  end
128
131
  expect(playlists.size) .to eq 10
129
132
  expect(playlists.map(&:name)) .to include('The Indie Mix', 'Indie Folk')
130
133
 
131
- playlists = VCR.use_cassette('playlist:search:Indie:offset:10') do
134
+ playlists = VCR.use_cassette('playlist:search:Indie:offset:10') do
132
135
  RSpotify::Playlist.search('Indie', offset: 10)
133
136
  end
134
137
  expect(playlists.size) .to eq 20
135
138
  expect(playlists.map(&:name)) .to include('Indie Workout', 'Indie Brunch')
136
139
 
137
- playlists = VCR.use_cassette('playlist:search:Indie:offset:10:limit:10') do
140
+ playlists = VCR.use_cassette('playlist:search:Indie:offset:10:limit:10') do
138
141
  RSpotify::Playlist.search('Indie', limit: 10, offset: 10)
139
142
  end
140
143
  expect(playlists.size) .to eq 10
@@ -143,19 +146,27 @@ describe RSpotify::Playlist do
143
146
  end
144
147
 
145
148
  describe 'Playlist#tracks' do
149
+ use_vcr_cassette 'playlist:tracks:118430647:starred'
150
+
151
+ before { @tracks = starred_playlist.tracks(offset: 100, limit: 100) }
152
+
146
153
  it 'should fetch more tracks correctly' do
147
- tracks = VCR.use_cassette('playlist:tracks:118430647:starred') do
148
- starred_playlist.tracks(offset: 100, limit: 100)
149
- end
150
- expect(tracks) .to be_an Array
151
- expect(tracks.size) .to eq 85
152
- expect(tracks.last.name) .to eq 'On The Streets - Kollectiv Turmstrasse Let Freedom Ring Remix'
154
+ expect(@tracks) .to be_an Array
155
+ expect(@tracks.size) .to eq 85
156
+ expect(@tracks.last.name) .to eq 'On The Streets - Kollectiv Turmstrasse Let Freedom Ring Remix'
153
157
  end
154
158
  end
155
159
 
156
160
  describe 'Playlist#complete!' do
157
161
  let(:href) { 'https://api.spotify.com/v1/users/wizzler/playlists/00wHcTN0zQiun4xri9pmvX' }
158
- let(:playlist) { RSpotify::Playlist.new('href' => href, 'owner' => {'id' => 'wizzler'}) }
162
+ let(:playlist) do
163
+ min_attrs = {
164
+ 'href' => href,
165
+ 'owner' => {'id' => 'wizzler'},
166
+ 'tracks' => {'total' => 53 }
167
+ }
168
+ RSpotify::Playlist.new(min_attrs)
169
+ end
159
170
 
160
171
  it 'should fetch the complete information correctly' do
161
172
  VCR.use_cassette('playlist:find:wizzler:00wHcTN0zQiun4xri9pmvX') do
@@ -70,6 +70,7 @@ describe RSpotify::Track do
70
70
  end
71
71
  expect(tracks) .to be_an Array
72
72
  expect(tracks.size) .to eq 20
73
+ expect(tracks.total) .to eq 3565
73
74
  expect(tracks.first) .to be_an RSpotify::Track
74
75
  expect(tracks.map(&:name)) .to include('Do I Wanna Know?', 'I Wanna Know', 'Never Wanna Know')
75
76
  end
@@ -30,4 +30,6 @@ RSpec.configure do |config|
30
30
 
31
31
  mocks.verify_partial_doubles = true
32
32
  end
33
+
34
+ config.extend VCR::RSpec::Macros
33
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Sad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-14 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2