rspotify 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rspotify/album.rb +25 -4
  3. data/lib/rspotify/artist.rb +3 -3
  4. data/lib/rspotify/base.rb +2 -13
  5. data/lib/rspotify/playlist.rb +40 -12
  6. data/lib/rspotify/track.rb +1 -1
  7. data/lib/rspotify/user.rb +3 -3
  8. data/lib/rspotify/version.rb +1 -1
  9. data/rspotify.gemspec +1 -0
  10. data/spec/lib/rspotify/album_spec.rb +21 -7
  11. data/spec/lib/rspotify/artist_spec.rb +32 -12
  12. data/spec/lib/rspotify/playlist_spec.rb +7 -2
  13. data/spec/lib/rspotify/track_spec.rb +21 -7
  14. data/spec/lib/rspotify/user_spec.rb +12 -5
  15. data/spec/spec_helper.rb +6 -0
  16. data/spec/vcr_cassettes/album_find_2agWNCZl5Ts9W05mij8EPh.yml +138 -0
  17. data/spec/vcr_cassettes/album_find_3JquYMWj5wrzuZCNAvOYN9.yml +267 -0
  18. data/spec/vcr_cassettes/album_find_5bU1XKYxHhEwukllT20xtk.yml +107 -0
  19. data/spec/vcr_cassettes/album_search_AM.yml +145 -0
  20. data/spec/vcr_cassettes/album_search_AM_limit_10.yml +109 -0
  21. data/spec/vcr_cassettes/album_search_AM_offset_10.yml +145 -0
  22. data/spec/vcr_cassettes/album_search_AM_offset_10_limit_10.yml +108 -0
  23. data/spec/vcr_cassettes/artist_7Ln80lUS6He07XvHI8qqHH_albums.yml +133 -0
  24. data/spec/vcr_cassettes/artist_7Ln80lUS6He07XvHI8qqHH_related_artists.yml +153 -0
  25. data/spec/vcr_cassettes/artist_7Ln80lUS6He07XvHI8qqHH_top_tracks_US.yml +102 -0
  26. data/spec/vcr_cassettes/artist_find_0oSGxfWSnnOXhD2fKuz2Gy.yml +74 -0
  27. data/spec/vcr_cassettes/artist_find_3dBVyJ7JuOMt4GE9607Qin.yml +80 -0
  28. data/spec/vcr_cassettes/artist_find_7Ln80lUS6He07XvHI8qqHH.yml +68 -0
  29. data/spec/vcr_cassettes/artist_search_Arctic.yml +122 -0
  30. data/spec/vcr_cassettes/artist_search_Arctic_limit_10.yml +96 -0
  31. data/spec/vcr_cassettes/artist_search_Arctic_offset_10.yml +119 -0
  32. data/spec/vcr_cassettes/artist_search_Arctic_offset_10_limit_10.yml +92 -0
  33. data/spec/vcr_cassettes/authenticate_5ac1cda2ad354aeaa1ad2693d33bb98c.yml +71 -0
  34. data/spec/vcr_cassettes/playlist_find_wizzler_00wHcTN0zQiun4xri9pmvX.yml +507 -0
  35. data/spec/vcr_cassettes/track_find_3jfr0TF6DQcOLat8gGn7E2.yml +76 -0
  36. data/spec/vcr_cassettes/track_find_4oI9kesyxHUr8fqiLd6uO9.yml +77 -0
  37. data/spec/vcr_cassettes/track_find_7D8BAYkrR9peCB9XSKCADc.yml +85 -0
  38. data/spec/vcr_cassettes/track_search_Wanna_Know.yml +234 -0
  39. data/spec/vcr_cassettes/track_search_Wanna_Know_limit_10.yml +154 -0
  40. data/spec/vcr_cassettes/track_search_Wanna_Know_limit_10_offset_10.yml +154 -0
  41. data/spec/vcr_cassettes/track_search_Wanna_Know_offset_10.yml +236 -0
  42. data/spec/vcr_cassettes/user_find_wizzler.yml +62 -0
  43. data/spec/vcr_cassettes/user_wizzler_playlists.yml +77 -0
  44. metadata +72 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fd61ef8b246df135f26baba22ee01c8c8b95aea
4
- data.tar.gz: 2e9b132363b9250147ef8e1f94dd6c5a1ed4b79f
3
+ metadata.gz: c7f112a228d4a745e4a0856808fdcb5c9380f852
4
+ data.tar.gz: b13cbfa86d18bcd1f747ed8767fb710e19249381
5
5
  SHA512:
6
- metadata.gz: c30d2c943bd75df12a5215cb1f459bbef43298c740513f0757a0b0e49475047ef6e5758c47f5a98a25972e1f6ce6afb10cac8d43d6ab807c6e66bc08e9d2bad6
7
- data.tar.gz: ec69eab471a3dbd4149f48bc2d319c229a3333671467f74bae73cb13b2db3c4367a2bd0d1fe676e1c7a630e3c45a61e29aad5df24e3133112c6bcc62e22d940f
6
+ metadata.gz: 75306911e3e1cb4c6b2c156fa97a106e0cb205711d4ea913878dbc725f8ef6bc767d6a5d07bbba68128252ecd04c671130baea05f096327c83c562ec20d43f65
7
+ data.tar.gz: f3422f96d4299b9ef58399a843c2bbbf43a4df3ce99126e0d636b1605d2e8759280cc424ab2ba4fabfd04514f545b2a29ae6e6fd644d1692f4e3a1ebea4d9d86
@@ -10,7 +10,6 @@ module RSpotify
10
10
  # @attr [Integer] popularity The popularity of the album. The value will be between 0 and 100, with 100 being the most popular
11
11
  # @attr [String] release_date The date the album was first released, for example "1981-12-15". Depending on the precision, it might be shown as "1981" or "1981-12"
12
12
  # @attr [String] release_date_precision The precision with which release_date value is known: "year", "month", or "day"
13
- # @attr [Array<Track>] tracks The tracks of the album.
14
13
  class Album < Base
15
14
 
16
15
  # Returns Album object(s) with id(s) provided
@@ -34,7 +33,7 @@ module RSpotify
34
33
  # Returns array of Album objects matching the query, ordered by popularity
35
34
  #
36
35
  # @param query [String] The search query's keywords. See the q description in {https://developer.spotify.com/web-api/search-item here} for details.
37
- # @param limit [Integer] Maximum number of albums to return. Minimum: 1. Maximum: 50. Default: 20.
36
+ # @param limit [Integer] Maximum number of albums to return. Maximum: 50. Default: 20.
38
37
  # @param offset [Integer] The index of the first album to return. Use with limit to get the next set of albums. Default: 0.
39
38
  # @return [Array<Album>]
40
39
  #
@@ -65,11 +64,33 @@ module RSpotify
65
64
  options['artists'].map { |a| Artist.new a }
66
65
  end
67
66
 
68
- @tracks = if options['tracks'] && options['tracks']['items']
69
- options['tracks']['items'].map { |t| Track.new t }
67
+ @tracks_cache = if options['tracks'] && options['tracks']['items']
68
+ options['tracks']['items'].map { |i| Track.new i }
70
69
  end
71
70
 
72
71
  super(options)
73
72
  end
73
+
74
+ # Returns array of tracks from the album
75
+ #
76
+ # @param limit [Integer] Maximum number of tracks to return. Maximum: 50. Default: 50.
77
+ # @param offset [Integer] The index of the first track to return. Use with limit to get the next set of objects. Default: 0.
78
+ # @return [Array<Track>]
79
+ #
80
+ # @example
81
+ # album = RSpotify::Album.find('41vPD50kQ7JeamkxQW7Vuy')
82
+ # album.tracks.first.name #=> "Do I Wanna Know?"
83
+ def tracks(limit: 50, offset: 0)
84
+ last_track = offset + limit - 1
85
+ if @tracks_cache && last_track < 50
86
+ return @tracks_cache[offset..last_track]
87
+ end
88
+
89
+ url = "albums/#{@id}/tracks?limit=#{limit}&offset=#{offset}"
90
+ json = RSpotify.get(url)
91
+ tracks = json['items'].map { |i| Track.new i }
92
+ @tracks_cache = tracks if limit == 50 && offset == 0
93
+ tracks
94
+ end
74
95
  end
75
96
  end
@@ -27,7 +27,7 @@ module RSpotify
27
27
  # Returns array of Artist objects matching the query, ordered by popularity
28
28
  #
29
29
  # @param query [String] The search query's keywords. See the q description in {https://developer.spotify.com/web-api/search-item here} for details.
30
- # @param limit [Integer] Maximum number of artists to return. Minimum: 1. Maximum: 50. Default: 20.
30
+ # @param limit [Integer] Maximum number of artists to return. Maximum: 50. Default: 20.
31
31
  # @param offset [Integer] The index of the first artist to return. Use with limit to get the next set of artists. Default: 0.
32
32
  # @return [Array<Artist>]
33
33
  #
@@ -65,10 +65,10 @@ module RSpotify
65
65
  def albums
66
66
  return @albums unless @albums.nil?
67
67
  json = RSpotify.get("artists/#{@id}/albums")
68
- @albums = json['items'].map { |a| Album.new a }
68
+ @albums = json['items'].map { |i| Album.new i }
69
69
  end
70
70
 
71
- # Returns array of similar artists. Similarity is based on analysis of the Spotify community’s {http://news.spotify.com/se/2010/02/03/related-artists listening history}
71
+ # Returns array of similar artists. Similarity is based on analysis of the Spotify community’s {http://news.spotify.com/se/2010/02/03/related-artists listening history}.
72
72
  #
73
73
  # @return [Array<Artist>]
74
74
  #
@@ -30,10 +30,6 @@ module RSpotify
30
30
  return false
31
31
  end
32
32
  limit = (type == 'album' ? 20 : 50)
33
- if ids.size > limit
34
- warn "Too many ids requested. Maximum: #{limit} for #{type}"
35
- return false
36
- end
37
33
  find_many(ids, type)
38
34
  when String
39
35
  id = ids
@@ -43,7 +39,6 @@ module RSpotify
43
39
 
44
40
  def self.find_many(ids, type)
45
41
  type_class = RSpotify.const_get(type.capitalize)
46
-
47
42
  path = "#{type}s?ids=#{ids.join ','}"
48
43
  json = RSpotify.get path
49
44
  json["#{type}s"].map { |t| type_class.new t }
@@ -52,7 +47,6 @@ module RSpotify
52
47
 
53
48
  def self.find_one(id, type)
54
49
  type_class = RSpotify.const_get(type.capitalize)
55
-
56
50
  path = "#{type}s/#{id}"
57
51
  json = RSpotify.get path
58
52
  type_class.new json
@@ -63,7 +57,7 @@ module RSpotify
63
57
  #
64
58
  # @param query [String] The search query's keywords. See the q description in {https://developer.spotify.com/web-api/search-item here} for details.
65
59
  # @param type [String] Valid types are: album, artist and track. Separate multiple types with commas.
66
- # @param limit [Integer] Maximum number of objects to return. Minimum: 1. Maximum: 50. Default: 20.
60
+ # @param limit [Integer] Maximum number of objects to return. Maximum: 50. Default: 20.
67
61
  # @param offset [Integer] The index of the first object to return. Use with limit to get the next set of objects. Default: 0.
68
62
  # @return [Array<Base>]
69
63
  #
@@ -76,11 +70,6 @@ module RSpotify
76
70
  # albums = RSpotify::Base.search('AM', 'album', limit: 10)
77
71
  # albums.size #=> 10
78
72
  def self.search(query, types, limit: 20, offset: 0)
79
- if limit < 1 || limit > 50
80
- warn 'Limit must be between 1 and 50'
81
- return false
82
- end
83
-
84
73
  types.gsub!(/\s+/, '')
85
74
 
86
75
  json = RSpotify.get 'search',
@@ -93,7 +82,7 @@ module RSpotify
93
82
 
94
83
  types.split(',').flat_map do |type|
95
84
  type_class = RSpotify.const_get(type.capitalize)
96
- json["#{type}s"]['items'].map { |item| type_class.new item }
85
+ json["#{type}s"]['items'].map { |i| type_class.new i }
97
86
  end
98
87
  end
99
88
 
@@ -7,7 +7,6 @@ module RSpotify
7
7
  # @attr [String] name The name of the playlist
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
- # @attr [Array<Track>] tracks The tracks of the playlist
11
10
  class Playlist < Base
12
11
 
13
12
  # Returns Playlist object with user_id and id provided
@@ -43,10 +42,10 @@ module RSpotify
43
42
  User.new options['owner']
44
43
  end
45
44
 
46
- @tracks = if options['tracks'] && options['tracks']['items']
47
- options['tracks']['items'].map { |t| Track.new t['track'] }
45
+ @tracks_cache = if options['tracks'] && options['tracks']['items']
46
+ options['tracks']['items'].map { |i| Track.new i['track'] }
48
47
  end
49
-
48
+
50
49
  super(options)
51
50
  end
52
51
 
@@ -68,11 +67,6 @@ module RSpotify
68
67
  # playlist.add_tracks!(tracks, position: 20)
69
68
  # playlist.tracks[20].name #=> "Somebody That I Used To Know"
70
69
  def add_tracks!(tracks, position: nil)
71
- if tracks.size > 100
72
- warn 'Too many tracks requested. Maximum: 100'
73
- return false
74
- end
75
-
76
70
  track_uris = tracks.map(&:uri).join(',')
77
71
  url = "users/#{@owner.id}/playlists/#{@id}/tracks?uris=#{track_uris}"
78
72
  url << "&position=#{position}" if position
@@ -94,14 +88,48 @@ module RSpotify
94
88
  # playlist.instance_variable_get("@description") #=> "Iconic soundtracks..."
95
89
  def complete!
96
90
  url = "users/#{@owner.id}/playlists/#{@id}"
97
- credentials_defined = User.class_variable_defined?('@@users_credentials')
98
- credentials = (credentials_defined ? User.class_variable_get('@@users_credentials') : nil)
99
91
 
100
- if credentials && credentials[@owner.id]
92
+ if users_credentials && users_credentials[@owner.id]
101
93
  initialize User.oauth_get(@owner.id, url)
102
94
  else
103
95
  initialize RSpotify.auth_get(url)
104
96
  end
105
97
  end
98
+
99
+ # Returns array of tracks from the playlist
100
+ #
101
+ # @param limit [Integer] Maximum number of tracks to return. Maximum: 100. Default: 100.
102
+ # @param offset [Integer] The index of the first track to return. Use with limit to get the next set of objects. Default: 0.
103
+ # @return [Array<Track>]
104
+ #
105
+ # @example
106
+ # playlist = RSpotify::Playlist.find('wizzler', '00wHcTN0zQiun4xri9pmvX')
107
+ # playlist.tracks.first.name #=> "Main Theme from Star Wars - Instrumental"
108
+ def tracks(limit: 100, offset: 0)
109
+ last_track = offset + limit - 1
110
+ if @tracks_cache && last_track < 100
111
+ return @tracks_cache[offset..last_track]
112
+ end
113
+
114
+ url = "users/#{@owner.id}/playlists/#{@id}/tracks" \
115
+ "?limit=#{limit}&offset=#{offset}"
116
+
117
+ json = if users_credentials && users_credentials[@owner.id]
118
+ User.oauth_get(@owner.id, url)
119
+ else
120
+ RSpotify.auth_get(url)
121
+ end
122
+
123
+ tracks = json['items'].map { |i| Track.new i['track'] }
124
+ @tracks_cache = tracks if limit == 100 && offset == 0
125
+ tracks
126
+ end
127
+
128
+ private
129
+
130
+ def users_credentials
131
+ credentials_defined = User.class_variable_defined?('@@users_credentials')
132
+ User.class_variable_get('@@users_credentials') if credentials_defined
133
+ end
106
134
  end
107
135
  end
@@ -34,7 +34,7 @@ module RSpotify
34
34
  # Returns array of Track objects matching the query, ordered by popularity
35
35
  #
36
36
  # @param query [String] The search query's keywords. See the q description in {https://developer.spotify.com/web-api/search-item here} for details.
37
- # @param limit [Integer] Maximum number of tracks to return. Minimum: 1. Maximum: 50. Default: 20.
37
+ # @param limit [Integer] Maximum number of tracks to return. Maximum: 50. Default: 20.
38
38
  # @param offset [Integer] The index of the first track to return. Use with limit to get the next set of tracks. Default: 0.
39
39
  # @return [Array<Track>]
40
40
  #
@@ -114,7 +114,7 @@ module RSpotify
114
114
  # playlists.first.name #=> "Movie Soundtrack Masterpieces"
115
115
  def playlists
116
116
  json = RSpotify.auth_get("users/#{@id}/playlists")
117
- json['items'].map { |p| Playlist.new p }
117
+ json['items'].map { |i| Playlist.new i }
118
118
  end
119
119
 
120
120
  # Remove tracks from the user’s “Your Music” library.
@@ -156,7 +156,7 @@ module RSpotify
156
156
 
157
157
  # Returns the tracks saved in the Spotify user’s “Your Music” library
158
158
  #
159
- # @param limit [Integer] Maximum number of tracks to return. Minimum: 1. Maximum: 50. Default: 20.
159
+ # @param limit [Integer] Maximum number of tracks to return. Maximum: 50. Default: 20.
160
160
  # @param offset [Integer] The index of the first track to return. Use with limit to get the next set of tracks. Default: 0.
161
161
  # @return [Array<Track>]
162
162
  #
@@ -167,7 +167,7 @@ module RSpotify
167
167
  def saved_tracks(limit: 20, offset: 0)
168
168
  url = "me/tracks?limit=#{limit}&offset=#{offset}"
169
169
  json = User.oauth_get(@id, url)
170
- json['items'].map { |t| Track.new t['track'] }
170
+ json['items'].map { |i| Track.new i['track'] }
171
171
  end
172
172
 
173
173
  # Check if tracks are already saved in the Spotify user’s “Your Music” library
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'rake'
25
25
  spec.add_development_dependency 'rspec'
26
26
  spec.add_development_dependency 'yard'
27
+ spec.add_development_dependency 'vcr', '~> 2.9'
27
28
  end
@@ -4,7 +4,9 @@ describe RSpotify::Album do
4
4
 
5
5
  before(:each) do
6
6
  # Get Arctic Monkeys's AM album as a testing sample
7
- @album = RSpotify::Album.find('5bU1XKYxHhEwukllT20xtk')
7
+ @album = VCR.use_cassette('album:find:5bU1XKYxHhEwukllT20xtk') do
8
+ RSpotify::Album.find('5bU1XKYxHhEwukllT20xtk')
9
+ end
8
10
  end
9
11
 
10
12
  it 'should find album with correct attributes' do
@@ -44,13 +46,17 @@ describe RSpotify::Album do
44
46
  describe 'Album::find receiving array of ids' do
45
47
  it 'should find the right albums' do
46
48
  ids = ['2agWNCZl5Ts9W05mij8EPh']
47
- albums = RSpotify::Album.find(ids)
49
+ albums = VCR.use_cassette('album:find:2agWNCZl5Ts9W05mij8EPh') do
50
+ RSpotify::Album.find(ids)
51
+ end
48
52
  expect(albums) .to be_an Array
49
53
  expect(albums.size) .to eq 1
50
54
  expect(albums.first.name) .to eq 'The Next Day Extra'
51
55
 
52
56
  ids << '3JquYMWj5wrzuZCNAvOYN9'
53
- albums = RSpotify::Album.find(ids)
57
+ albums = VCR.use_cassette('album:find:3JquYMWj5wrzuZCNAvOYN9') do
58
+ RSpotify::Album.find(ids)
59
+ end
54
60
  expect(albums) .to be_an Array
55
61
  expect(albums.size) .to eq 2
56
62
  expect(albums.first.name) .to eq 'The Next Day Extra'
@@ -60,7 +66,9 @@ describe RSpotify::Album do
60
66
 
61
67
  describe 'Album::search' do
62
68
  it 'should search for the right albums' do
63
- albums = RSpotify::Album.search('AM')
69
+ albums = VCR.use_cassette('album:search:AM') do
70
+ RSpotify::Album.search('AM')
71
+ end
64
72
  expect(albums) .to be_an Array
65
73
  expect(albums.size) .to eq 20
66
74
  expect(albums.first) .to be_an RSpotify::Album
@@ -68,15 +76,21 @@ describe RSpotify::Album do
68
76
  end
69
77
 
70
78
  it 'should accept additional options' do
71
- albums = RSpotify::Album.search('AM', limit: 10)
79
+ albums = VCR.use_cassette('album:search:AM:limit:10') do
80
+ RSpotify::Album.search('AM', limit: 10)
81
+ end
72
82
  expect(albums.size) .to eq 10
73
83
  expect(albums.map(&:name)) .to include('AM', 'Am I Wrong')
74
84
 
75
- albums = RSpotify::Album.search('AM', offset: 10)
85
+ albums = VCR.use_cassette('album:search:AM:offset:10') do
86
+ RSpotify::Album.search('AM', offset: 10)
87
+ end
76
88
  expect(albums.size) .to eq 20
77
89
  expect(albums.map(&:name)) .to include('Melody AM', 'I Am')
78
90
 
79
- albums = RSpotify::Album.search('AM', limit: 10, offset: 10)
91
+ albums = VCR.use_cassette('album:search:AM:offset:10:limit:10') do
92
+ RSpotify::Album.search('AM', limit: 10, offset: 10)
93
+ end
80
94
  expect(albums.size) .to eq 10
81
95
  expect(albums.map(&:name)) .to include('Melody AM')
82
96
  end
@@ -4,7 +4,9 @@ describe RSpotify::Artist do
4
4
 
5
5
  before(:each) do
6
6
  # Get Arctic Monkeys as a testing sample
7
- @artist = RSpotify::Artist.find('7Ln80lUS6He07XvHI8qqHH')
7
+ @artist = VCR.use_cassette('artist:find:7Ln80lUS6He07XvHI8qqHH') do
8
+ RSpotify::Artist.find('7Ln80lUS6He07XvHI8qqHH')
9
+ end
8
10
  end
9
11
 
10
12
  it 'should find artist with correct attributes' do
@@ -20,7 +22,9 @@ describe RSpotify::Artist do
20
22
  end
21
23
 
22
24
  it 'should find artist with correct albums' do
23
- albums = @artist.albums
25
+ albums = VCR.use_cassette('artist:7Ln80lUS6He07XvHI8qqHH:albums') do
26
+ @artist.albums
27
+ end
24
28
  expect(albums) .to be_an Array
25
29
  expect(albums.size) .to eq 20
26
30
  expect(albums.first) .to be_an RSpotify::Album
@@ -28,7 +32,9 @@ describe RSpotify::Artist do
28
32
  end
29
33
 
30
34
  it 'should find artist with correct top tracks' do
31
- top_tracks = @artist.top_tracks(:US)
35
+ top_tracks = VCR.use_cassette('artist:7Ln80lUS6He07XvHI8qqHH:top_tracks:US') do
36
+ @artist.top_tracks(:US)
37
+ end
32
38
  expect(top_tracks) .to be_an Array
33
39
  expect(top_tracks.size) .to eq 10
34
40
  expect(top_tracks.first) .to be_an RSpotify::Track
@@ -36,7 +42,9 @@ describe RSpotify::Artist do
36
42
  end
37
43
 
38
44
  it 'should find artist with correct related artists' do
39
- related_artists = @artist.related_artists
45
+ related_artists = VCR.use_cassette('artist:7Ln80lUS6He07XvHI8qqHH:related_artists') do
46
+ @artist.related_artists
47
+ end
40
48
  expect(related_artists) .to be_an Array
41
49
  expect(related_artists.size) .to eq 20
42
50
  expect(related_artists.first) .to be_an RSpotify::Artist
@@ -47,13 +55,17 @@ describe RSpotify::Artist do
47
55
  describe 'Artist::find receiving array of ids' do
48
56
  it 'should find the right artists' do
49
57
  ids = ['0oSGxfWSnnOXhD2fKuz2Gy']
50
- artists = RSpotify::Artist.find(ids)
58
+ artists = VCR.use_cassette('artist:find:0oSGxfWSnnOXhD2fKuz2Gy') do
59
+ RSpotify::Artist.find(ids)
60
+ end
51
61
  expect(artists) .to be_an Array
52
62
  expect(artists.size) .to eq 1
53
63
  expect(artists.first.name) .to eq 'David Bowie'
54
64
 
55
65
  ids << '3dBVyJ7JuOMt4GE9607Qin'
56
- artists = RSpotify::Artist.find(ids)
66
+ artists = VCR.use_cassette('artist:find:3dBVyJ7JuOMt4GE9607Qin') do
67
+ RSpotify::Artist.find(ids)
68
+ end
57
69
  expect(artists) .to be_an Array
58
70
  expect(artists.size) .to eq 2
59
71
  expect(artists.first.name) .to eq 'David Bowie'
@@ -63,7 +75,9 @@ describe RSpotify::Artist do
63
75
 
64
76
  describe 'Artist::search' do
65
77
  it 'should search for the right artists' do
66
- artists = RSpotify::Artist.search('Arctic')
78
+ artists = VCR.use_cassette('artist:search:Arctic') do
79
+ RSpotify::Artist.search('Arctic')
80
+ end
67
81
  expect(artists) .to be_an Array
68
82
  expect(artists.size) .to eq 20
69
83
  expect(artists.first) .to be_an RSpotify::Artist
@@ -71,17 +85,23 @@ describe RSpotify::Artist do
71
85
  end
72
86
 
73
87
  it 'should accept additional options' do
74
- artists = RSpotify::Artist.search('Arctic', limit: 10)
88
+ artists = VCR.use_cassette('artist:search:Arctic:limit:10') do
89
+ RSpotify::Artist.search('Arctic', limit: 10)
90
+ end
75
91
  expect(artists.size) .to eq 10
76
92
  expect(artists.map(&:name)) .to include('Arctic Monkeys', 'Arctic')
77
93
 
78
- artists = RSpotify::Artist.search('Arctic', offset: 10)
94
+ artists = VCR.use_cassette('artist:search:Arctic:offset:10') do
95
+ RSpotify::Artist.search('Arctic', offset: 10)
96
+ end
79
97
  expect(artists.size) .to eq 20
80
- expect(artists.map(&:name)) .to include('Arctic Light', 'Arctic Night')
98
+ expect(artists.map(&:name)) .to include('Arctic Flame', 'Arctic Night')
81
99
 
82
- artists = RSpotify::Artist.search('Arctic', limit: 10, offset: 10)
100
+ artists = VCR.use_cassette('artist:search:Arctic:offset:10:limit:10') do
101
+ RSpotify::Artist.search('Arctic', limit: 10, offset: 10)
102
+ end
83
103
  expect(artists.size) .to eq 10
84
- expect(artists.map(&:name)) .to include('Arctic Light')
104
+ expect(artists.map(&:name)) .to include('Arctic Flame')
85
105
  end
86
106
  end
87
107
  end
@@ -6,10 +6,15 @@ describe RSpotify::Playlist do
6
6
  # Keys generated specifically for the tests. Should be removed in the future
7
7
  client_id = '5ac1cda2ad354aeaa1ad2693d33bb98c'
8
8
  client_secret = '155fc038a85840679b55a1822ef36b9b'
9
- RSpotify.authenticate(client_id, client_secret)
9
+
10
+ VCR.use_cassette('authenticate:5ac1cda2ad354aeaa1ad2693d33bb98c') do
11
+ RSpotify.authenticate(client_id, client_secret)
12
+ end
10
13
 
11
14
  # Get wizzler's "Movie Soundtrack Masterpieces" playlist as a testing sample
12
- @playlist = RSpotify::Playlist.find('wizzler', '00wHcTN0zQiun4xri9pmvX')
15
+ @playlist = VCR.use_cassette('playlist:find:wizzler:00wHcTN0zQiun4xri9pmvX') do
16
+ RSpotify::Playlist.find('wizzler', '00wHcTN0zQiun4xri9pmvX')
17
+ end
13
18
  end
14
19
 
15
20
  it 'should find playlist with correct attributes' do