rspotify 0.4.0 → 0.5.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: a0f489f7b6248799f9c52fab33efa35debd4933a
4
- data.tar.gz: c235ab00785d39e994950485cee2b994b2d2addb
3
+ metadata.gz: f2f691b1533e85a23ec83b8648854b133ee9078b
4
+ data.tar.gz: 858e2159f410f058f56d6556d43cfc9fb52b1b01
5
5
  SHA512:
6
- metadata.gz: 04b88d2a1bff87009cbbb22139c9c8290a0a6880cd3edd587013f8d2e6ad0f078c6299fd7688c242426dc5439212e58676546948e735fa88a93606d780b1262f
7
- data.tar.gz: 50b468779d68fdab5b7f3bf430a485570831dc231477c899a02a28ad10a5512b5e216e1603b1223ba42a01c8a023491a5367c184fe97d3eb5da2ffeccbf30e46
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 #=> ["Alternative Rap", "East Coast Rap", ...]
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"
@@ -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
- artists = options['artists']
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
- tracks = options['tracks']['items']
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)
@@ -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
@@ -34,7 +34,7 @@ module RSpotify
34
34
  @uri = options['uri']
35
35
  end
36
36
 
37
- def complete_object!
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
- complete_object!
49
+ complete!
50
50
  instance_variable_get attr
51
51
  end
52
52
 
@@ -19,19 +19,18 @@ module RSpotify
19
19
  @name = options['name']
20
20
  @public = options['public']
21
21
 
22
- if options['owner']
23
- @owner = User.new options['owner']
22
+ @owner = if options['owner']
23
+ User.new options['owner']
24
24
  end
25
25
 
26
- if options['tracks'] && options['tracks']['items']
27
- tracks = options['tracks']['items']
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 complete_object!
33
+ def complete!
35
34
  initialize RSpotify.auth_get("users/#{@owner.id}/playlists/#{@id}")
36
35
  end
37
36
  end
@@ -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
- @album = Album.new options['album']
24
+ @album = if options['album']
25
+ Album.new options['album']
26
26
  end
27
27
 
28
- if options['artists']
29
- artists = options['artists']
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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Sad