rspotify 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/rspotify/album.rb +4 -6
- data/lib/rspotify/artist.rb +7 -0
- data/lib/rspotify/base.rb +2 -2
- data/lib/rspotify/playlist.rb +5 -6
- data/lib/rspotify/track.rb +4 -5
- data/lib/rspotify/user.rb +2 -1
- data/lib/rspotify/version.rb +1 -1
- data/spec/lib/rspotify/artist_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2f691b1533e85a23ec83b8648854b133ee9078b
|
4
|
+
data.tar.gz: 858e2159f410f058f56d6556d43cfc9fb52b1b01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a92a533beed2d5bdf7a0a753354d17e5ffb8e0aa598004c053c7f64e1a2f1a95ba8a1b89ef4aaa3b93de2c1e38ffd5e069038f4ea94d11c19b0d9342878e5976
|
7
|
+
data.tar.gz: dbbaad8372512bd4f7f4a549700b9caf126524bf5456cee04b80a18500991a93cc88aec6f90293dfb83cd88ea13ac926be69872328d4b318efd0c4eca1a37cb7
|
data/README.md
CHANGED
@@ -38,7 +38,8 @@ album.images #=> (Image array)
|
|
38
38
|
|
39
39
|
# Find by id
|
40
40
|
artist = RSpotify::Artist.find('5K4W6rqBFWDnAN6FQUkS6x')
|
41
|
-
artist.genres
|
41
|
+
artist.genres #=> ["Alternative Rap", "East Coast Rap", ...]
|
42
|
+
artist.top_tracks[:US] #=> (Track array)
|
42
43
|
|
43
44
|
album = RSpotify::Album.find('0uZ8zQLHru4BiNTL2PQY91')
|
44
45
|
album.album_type #=> "single"
|
data/lib/rspotify/album.rb
CHANGED
@@ -21,14 +21,12 @@ module RSpotify
|
|
21
21
|
@release_date = options['release_date']
|
22
22
|
@release_date_precision = options['release_date_precision']
|
23
23
|
|
24
|
-
if options['artists']
|
25
|
-
|
26
|
-
@artists = artists.map { |a| Artist.new a }
|
24
|
+
@artists = if options['artists']
|
25
|
+
options['artists'].map { |a| Artist.new a }
|
27
26
|
end
|
28
27
|
|
29
|
-
if options['tracks']
|
30
|
-
|
31
|
-
@tracks = tracks.map { |t| Track.new t }
|
28
|
+
@tracks = if options['tracks'] && options['tracks']['items']
|
29
|
+
options['tracks']['items'].map { |t| Track.new t }
|
32
30
|
end
|
33
31
|
|
34
32
|
super(options)
|
data/lib/rspotify/artist.rb
CHANGED
@@ -15,8 +15,15 @@ module RSpotify
|
|
15
15
|
@images = options['images']
|
16
16
|
@name = options['name']
|
17
17
|
@popularity = options['popularity']
|
18
|
+
@top_tracks = {}
|
18
19
|
|
19
20
|
super(options)
|
20
21
|
end
|
22
|
+
|
23
|
+
def top_tracks(country)
|
24
|
+
return @top_tracks[country] unless @top_tracks[country].nil?
|
25
|
+
json = RSpotify.get("artists/#{@id}/top-tracks?country=#{country}")
|
26
|
+
@top_tracks[country] = json['tracks'].map{ |t| Track.new t }
|
27
|
+
end
|
21
28
|
end
|
22
29
|
end
|
data/lib/rspotify/base.rb
CHANGED
@@ -34,7 +34,7 @@ module RSpotify
|
|
34
34
|
@uri = options['uri']
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def complete!
|
38
38
|
pluralized_type = "#{type}s"
|
39
39
|
initialize RSpotify.get("#{pluralized_type}/#{@id}")
|
40
40
|
end
|
@@ -46,7 +46,7 @@ module RSpotify
|
|
46
46
|
attr_value = instance_variable_get attr
|
47
47
|
return attr_value unless attr_value.nil?
|
48
48
|
|
49
|
-
|
49
|
+
complete!
|
50
50
|
instance_variable_get attr
|
51
51
|
end
|
52
52
|
|
data/lib/rspotify/playlist.rb
CHANGED
@@ -19,19 +19,18 @@ module RSpotify
|
|
19
19
|
@name = options['name']
|
20
20
|
@public = options['public']
|
21
21
|
|
22
|
-
if options['owner']
|
23
|
-
|
22
|
+
@owner = if options['owner']
|
23
|
+
User.new options['owner']
|
24
24
|
end
|
25
25
|
|
26
|
-
if options['tracks'] && options['tracks']['items']
|
27
|
-
|
28
|
-
@tracks = tracks.map { |t| Track.new t['track'] }
|
26
|
+
@tracks = if options['tracks'] && options['tracks']['items']
|
27
|
+
options['tracks']['items'].map { |t| Track.new t['track'] }
|
29
28
|
end
|
30
29
|
|
31
30
|
super(options)
|
32
31
|
end
|
33
32
|
|
34
|
-
def
|
33
|
+
def complete!
|
35
34
|
initialize RSpotify.auth_get("users/#{@owner.id}/playlists/#{@id}")
|
36
35
|
end
|
37
36
|
end
|
data/lib/rspotify/track.rb
CHANGED
@@ -21,13 +21,12 @@ module RSpotify
|
|
21
21
|
@preview_url = options['preview_url']
|
22
22
|
@track_number = options['track_number']
|
23
23
|
|
24
|
-
if options['album']
|
25
|
-
|
24
|
+
@album = if options['album']
|
25
|
+
Album.new options['album']
|
26
26
|
end
|
27
27
|
|
28
|
-
if options['artists']
|
29
|
-
|
30
|
-
@artists = artists.map { |a| Artist.new a }
|
28
|
+
@artists = if options['artists']
|
29
|
+
options['artists'].map { |a| Artist.new a }
|
31
30
|
end
|
32
31
|
|
33
32
|
super(options)
|
data/lib/rspotify/user.rb
CHANGED
@@ -15,8 +15,9 @@ module RSpotify
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def playlists
|
18
|
+
return @playlists unless @playlists.nil?
|
18
19
|
playlists = RSpotify.auth_get("users/#{@id}/playlists")['items']
|
19
|
-
playlists.map { |p| Playlist.new p }
|
20
|
+
@playlists = playlists.map { |p| Playlist.new p }
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
data/lib/rspotify/version.rb
CHANGED
@@ -17,6 +17,14 @@ describe RSpotify::Artist do
|
|
17
17
|
expect(@artist.type) .to eq 'artist'
|
18
18
|
expect(@artist.uri) .to eq 'spotify:artist:7Ln80lUS6He07XvHI8qqHH'
|
19
19
|
end
|
20
|
+
|
21
|
+
it 'should find artist with correct top tracks' do
|
22
|
+
top_tracks = @artist.top_tracks(:US)
|
23
|
+
expect(top_tracks) .to be_an Array
|
24
|
+
expect(top_tracks.size) .to eq 10
|
25
|
+
expect(top_tracks.first) .to be_an RSpotify::Track
|
26
|
+
expect(top_tracks.map(&:name)) .to include('Do I Wanna Know?', 'R U Mine?', 'Arabella', 'Knee Socks')
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
describe 'Artist#search' do
|