rspotify 0.5.0 → 0.6.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: f2f691b1533e85a23ec83b8648854b133ee9078b
4
- data.tar.gz: 858e2159f410f058f56d6556d43cfc9fb52b1b01
3
+ metadata.gz: 143c29a98dc6fd1ddcea30f3652f0f90b76b20cf
4
+ data.tar.gz: 37b43846b4ef02d85492c9c28a37e9508d927124
5
5
  SHA512:
6
- metadata.gz: a92a533beed2d5bdf7a0a753354d17e5ffb8e0aa598004c053c7f64e1a2f1a95ba8a1b89ef4aaa3b93de2c1e38ffd5e069038f4ea94d11c19b0d9342878e5976
7
- data.tar.gz: dbbaad8372512bd4f7f4a549700b9caf126524bf5456cee04b80a18500991a93cc88aec6f90293dfb83cd88ea13ac926be69872328d4b318efd0c4eca1a37cb7
6
+ metadata.gz: f2e541262d61bc8b5337a29c4a37cf2f19c204ace211767d19579ae936d4107e79ea6a6c7d80d70c6e75356d984388a339a7dfcd9611fedd5b65353363cb2db2
7
+ data.tar.gz: 8e3fb4b604c933c1b86d3c0a20960350b766110cf81bc8a3b9b18b8959ed044b62356d29bd4e57594c5d12c90b9792a45f573982070ba80ec781141829b44416
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  .bundle
2
+ .yardoc
3
+ doc
2
4
  pkg
3
5
  Gemfile.lock
data/README.md CHANGED
@@ -23,35 +23,55 @@ Directly access Spotify public data such as albums, tracks, artists and users:
23
23
  ```ruby
24
24
  require 'rspotify'
25
25
 
26
- tracks = RSpotify::Track.search('Do I wanna know?')
26
+ artists = RSpotify::Artist.search('Arctic Monkeys')
27
27
 
28
- tracks.first.name #=> "Do I Wanna Know?"
29
- tracks.first.popularity #=> 86
28
+ arctic_monkeys = artists.first
29
+ arctic_monkeys.popularity #=> 74
30
+ arctic_monkeys.genres #=> ["Alternative Pop/Rock", "Indie", ...]
31
+ arctic_monkeys.top_tracks[:US] #=> (Track array)
30
32
 
31
- artists = tracks.first.artists
32
- artists.first.name #=> "Arctic Monkeys"
33
- artists.first.uri #=> "spotify:artist:7Ln80lUS6He07XvHI8qqHH"
33
+ albums = arctic_monkeys.albums
34
+ albums.first.name #=> "AM"
34
35
 
35
- album = tracks.first.album
36
- album.name #=> "AM"
37
- album.images #=> (Image array)
36
+ am = albums.first
37
+ am.release_date #=> "2013-09-10"
38
+ am.images #=> (Image array)
39
+ am.available_markets #=> ["AR", "BO", "BR", ...]
38
40
 
39
- # Find by id
40
- artist = RSpotify::Artist.find('5K4W6rqBFWDnAN6FQUkS6x')
41
- artist.genres #=> ["Alternative Rap", "East Coast Rap", ...]
42
- artist.top_tracks[:US] #=> (Track array)
41
+ tracks = am.tracks
42
+ tracks.first.name #=> "Do I Wanna Know?"
43
43
 
44
- album = RSpotify::Album.find('0uZ8zQLHru4BiNTL2PQY91')
45
- album.album_type #=> "single"
46
- album.tracks #=> (Track array)
44
+ do_i_wanna_know = tracks.first
45
+ do_i_wanna_know.duration_ms #=> 272386
46
+ do_i_wanna_know.track_number #=> 1
47
+ do_i_wanna_know.preview_url #=> "https://p.scdn.co/mp3-preview/<id>"
47
48
 
48
- track = RSpotify::Track.find('2qmxggATKFIeg68guRSG3r')
49
- track.duration_ms #=> 270800
50
- track.album #=> (Album object)
49
+ # You can search within other types too
50
+ albums = RSpotify::Album.search('The Wall')
51
+ tracks = RSpotify::Track.search('Thriller')
52
+ ```
53
+
54
+ If you prefer, you can find them directly by id:
55
+
56
+ ```ruby
57
+ arctic_monkeys = RSpotify::Artist.find('7Ln80lUS6He07XvHI8qqHH')
58
+ arctic_monkeys.external_urls['spotify'] #=> "https://open.spotify.com/artist/<id>"
59
+
60
+ am = RSpotify::Album.find('41vPD50kQ7JeamkxQW7Vuy')
61
+ am.album_type #=> "single"
62
+
63
+ do_i_wanna_know = RSpotify::Track.find('2UzMpPKPhbcC8RbsmuURAZ')
64
+ do_i_wanna_know.album #=> (Album object)
65
+
66
+ wizzler = RSpotify::User.find('wizzler')
67
+ wizzler.uri #=> "spotify:user:wizzler"
51
68
 
52
- user = RSpotify::User.find('wizzler')
53
- user.href #=> "https://api.spotify.com/v1/users/wizzler"
54
- user.external_urls["spotify"] #=> "https://open.spotify.com/user/wizzler"
69
+ # Or find several objects at once:
70
+
71
+ ids = %w(2UzMpPKPhbcC8RbsmuURAZ 7Jzsc04YpkRwB1zeyM39wE)
72
+
73
+ my_tracks = RSpotify::Track.find(ids)
74
+ my_tracks.size #=> 2
55
75
  ```
56
76
 
57
77
  Some data require authentication to be accessed, such as playlists. You can easily get your credentials [here](https://developer.spotify.com/my-applications).
@@ -73,7 +93,17 @@ my_user = RSpotify::User.find("my_user")
73
93
  my_playlists = my_user.playlists #=> (Playlist array)
74
94
  ```
75
95
 
76
- More documentation will follow
96
+ RSpotify focuses on objects behaviour so you can forget the API and worry about your tracks, artists and so on.
97
+
98
+ It is possible to write things like `playlist.tracks.sort_by(&:popularity).last.album` without having to think what API calls must be done. RSpotify fills the gaps for you.
99
+
100
+ Full documentation can be found [here](http://rdoc.info/github/guilhermesad/rspotify/master/frames). (Will be complete in the next few days)
101
+
102
+ ## Notes
103
+
104
+ This gem uses [client credentials](https://developer.spotify.com/web-api/authorization-guide/#client_credentials_flow) to authenticate your access. This means you can get all public data you want, but it's not possible to access private playlists or to create new ones. For that you would want to use [authorization code flow](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow).
105
+
106
+ RSpotify focuses on simplicity of use and straight access to data, so the authorization code flow is not supported at the moment. If you really feel the need to use it, please leave a issue for it to be implemented.
77
107
 
78
108
  ## Contributing
79
109
 
@@ -2,8 +2,8 @@ module RSpotify
2
2
 
3
3
  class Album < Base
4
4
 
5
- def self.find(id)
6
- super(id, 'album')
5
+ def self.find(ids)
6
+ super(ids, 'album')
7
7
  end
8
8
 
9
9
  def self.search(query, limit = 20, offset = 0)
@@ -2,8 +2,8 @@ module RSpotify
2
2
 
3
3
  class Artist < Base
4
4
 
5
- def self.find(id)
6
- super(id, 'artist')
5
+ def self.find(ids)
6
+ super(ids, 'artist')
7
7
  end
8
8
 
9
9
  def self.search(query, limit = 20, offset = 0)
@@ -20,10 +20,16 @@ module RSpotify
20
20
  super(options)
21
21
  end
22
22
 
23
+ def albums
24
+ return @albums unless @albums.nil?
25
+ json = RSpotify.get("artists/#{@id}/albums")
26
+ @albums = json['items'].map { |a| Album.new a }
27
+ end
28
+
23
29
  def top_tracks(country)
24
30
  return @top_tracks[country] unless @top_tracks[country].nil?
25
31
  json = RSpotify.get("artists/#{@id}/top-tracks?country=#{country}")
26
- @top_tracks[country] = json['tracks'].map{ |t| Track.new t }
32
+ @top_tracks[country] = json['tracks'].map { |t| Track.new t }
27
33
  end
28
34
  end
29
35
  end
data/lib/rspotify/base.rb CHANGED
@@ -2,12 +2,22 @@ module RSpotify
2
2
 
3
3
  class Base
4
4
 
5
- def self.find(id, type)
5
+ def self.find(ids, type)
6
6
  pluralized_type = "#{type}s"
7
+ path = pluralized_type.dup
7
8
  type_class = eval type.capitalize
8
9
 
9
- json = RSpotify.get "#{pluralized_type}/#{id}"
10
- type_class.new json
10
+ case ids.class.to_s
11
+ when 'Array'
12
+ path << "?ids=#{ids.join ','}"
13
+ json = RSpotify.get path
14
+ json[pluralized_type].map { |t| type_class.new t }
15
+ when 'String'
16
+ id = ids
17
+ path << "/#{id}"
18
+ json = RSpotify.get path
19
+ type_class.new json
20
+ end
11
21
  end
12
22
 
13
23
  def self.search(query, type, limit = 20, offset = 0)
@@ -2,8 +2,8 @@ module RSpotify
2
2
 
3
3
  class Track < Base
4
4
 
5
- def self.find(id)
6
- super(id, 'track')
5
+ def self.find(ids)
6
+ super(ids, 'track')
7
7
  end
8
8
 
9
9
  def self.search(query, limit = 20, offset = 0)
data/lib/rspotify/user.rb CHANGED
@@ -3,6 +3,10 @@ module RSpotify
3
3
  class User < Base
4
4
 
5
5
  def self.find(id)
6
+ if id.is_a? Array
7
+ warn 'Spotify API does not support finding several users simultaneously'
8
+ return false
9
+ end
6
10
  super(id, 'user')
7
11
  end
8
12
 
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
data/rspotify.gemspec CHANGED
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_dependency 'rest_client', '~> 1.7'
20
20
 
21
- spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'rspec'
23
21
  spec.add_development_dependency 'bundler'
24
22
  spec.add_development_dependency 'fakeweb', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'yard'
25
26
  end
@@ -1,7 +1,7 @@
1
1
  describe RSpotify::Album do
2
2
 
3
- describe 'Album#find' do
4
-
3
+ describe 'Album::find receiving id as a string' do
4
+
5
5
  before(:each) do
6
6
  # Get Arctic Monkeys's AM album as a testing sample
7
7
  @album = RSpotify::Album.find('5bU1XKYxHhEwukllT20xtk')
@@ -41,7 +41,24 @@ describe RSpotify::Album do
41
41
  end
42
42
  end
43
43
 
44
- describe 'Album#search' do
44
+ describe 'Album::find receiving array of ids' do
45
+ it 'should find the right albums' do
46
+ ids = ['2agWNCZl5Ts9W05mij8EPh']
47
+ albums = RSpotify::Album.find(ids)
48
+ expect(albums) .to be_an Array
49
+ expect(albums.size) .to eq 1
50
+ expect(albums.first.name) .to eq 'The Next Day Extra'
51
+
52
+ ids << '3JquYMWj5wrzuZCNAvOYN9'
53
+ albums = RSpotify::Album.find(ids)
54
+ expect(albums) .to be_an Array
55
+ expect(albums.size) .to eq 2
56
+ expect(albums.first.name) .to eq 'The Next Day Extra'
57
+ expect(albums.last.name) .to eq 'A Beard Of Stars (Deluxe Edition)'
58
+ end
59
+ end
60
+
61
+ describe 'Album::search' do
45
62
  it 'should search for the right albums' do
46
63
  albums = RSpotify::Album.search('AM')
47
64
  expect(albums) .to be_an Array
@@ -1,6 +1,7 @@
1
1
  describe RSpotify::Artist do
2
2
 
3
- describe 'Artist#find' do
3
+ describe 'Artist::find receiving id as a string' do
4
+
4
5
  before(:each) do
5
6
  # Get Arctic Monkeys as a testing sample
6
7
  @artist = RSpotify::Artist.find('7Ln80lUS6He07XvHI8qqHH')
@@ -18,6 +19,14 @@ describe RSpotify::Artist do
18
19
  expect(@artist.uri) .to eq 'spotify:artist:7Ln80lUS6He07XvHI8qqHH'
19
20
  end
20
21
 
22
+ it 'should find artist with correct albums' do
23
+ albums = @artist.albums
24
+ expect(albums) .to be_an Array
25
+ expect(albums.size) .to eq 20
26
+ expect(albums.first) .to be_an RSpotify::Album
27
+ expect(albums.map(&:name)) .to include('AM', 'Suck It and See', 'Suck It and See Sampler' , 'Humbug')
28
+ end
29
+
21
30
  it 'should find artist with correct top tracks' do
22
31
  top_tracks = @artist.top_tracks(:US)
23
32
  expect(top_tracks) .to be_an Array
@@ -27,7 +36,24 @@ describe RSpotify::Artist do
27
36
  end
28
37
  end
29
38
 
30
- describe 'Artist#search' do
39
+ describe 'Artist::find receiving array of ids' do
40
+ it 'should find the right artists' do
41
+ ids = ['0oSGxfWSnnOXhD2fKuz2Gy']
42
+ artists = RSpotify::Artist.find(ids)
43
+ expect(artists) .to be_an Array
44
+ expect(artists.size) .to eq 1
45
+ expect(artists.first.name) .to eq 'David Bowie'
46
+
47
+ ids << '3dBVyJ7JuOMt4GE9607Qin'
48
+ artists = RSpotify::Artist.find(ids)
49
+ expect(artists) .to be_an Array
50
+ expect(artists.size) .to eq 2
51
+ expect(artists.first.name) .to eq 'David Bowie'
52
+ expect(artists.last.name) .to eq 'T. Rex'
53
+ end
54
+ end
55
+
56
+ describe 'Artist::search' do
31
57
  it 'should search for the right artists' do
32
58
  artists = RSpotify::Artist.search('Arctic')
33
59
  expect(artists) .to be_an Array
@@ -1,6 +1,6 @@
1
1
  describe RSpotify::Playlist do
2
2
 
3
- describe 'Playlist#find' do
3
+ describe 'Playlist::find' do
4
4
 
5
5
  before(:each) do
6
6
  # Keys generated specifically for the tests. Should be removed in the future
@@ -1,6 +1,6 @@
1
1
  describe RSpotify::Track do
2
2
 
3
- describe 'Track#find' do
3
+ describe 'Track::find receiving id as a string' do
4
4
 
5
5
  before(:each) do
6
6
  # Get Arctic Monkeys's "Do I Wanna Know?" track as a testing sample
@@ -40,7 +40,24 @@ describe RSpotify::Track do
40
40
  end
41
41
  end
42
42
 
43
- describe 'Track#search' do
43
+ describe 'Track::find receiving array of ids' do
44
+ it 'should find the right tracks' do
45
+ ids = ['4oI9kesyxHUr8fqiLd6uO9']
46
+ tracks = RSpotify::Track.find(ids)
47
+ expect(tracks) .to be_an Array
48
+ expect(tracks.size) .to eq 1
49
+ expect(tracks.first.name) .to eq 'The Next Day'
50
+
51
+ ids << '7D8BAYkrR9peCB9XSKCADc'
52
+ tracks = RSpotify::Track.find(ids)
53
+ expect(tracks) .to be_an Array
54
+ expect(tracks.size) .to eq 2
55
+ expect(tracks.first.name) .to eq 'The Next Day'
56
+ expect(tracks.last.name) .to eq 'Sunday'
57
+ end
58
+ end
59
+
60
+ describe 'Track::search' do
44
61
  it 'should search for the right tracks' do
45
62
  tracks = RSpotify::Track.search('Wanna Know')
46
63
  expect(tracks) .to be_an Array
@@ -1,6 +1,6 @@
1
1
  describe RSpotify::User do
2
2
 
3
- describe 'User#find' do
3
+ describe 'User::find' do
4
4
 
5
5
  before(:each) do
6
6
  # Get wizzler user as a testing sample
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: 0.5.0
4
+ version: 0.6.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-06-22 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest_client
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,21 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: fakeweb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -53,7 +67,7 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: bundler
70
+ name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -67,19 +81,19 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: fakeweb
84
+ name: yard
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '1.3'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '1.3'
96
+ version: '0'
83
97
  description:
84
98
  email:
85
99
  - gorgulhoguilherme@gmail.com
@@ -94,7 +108,6 @@ files:
94
108
  - LICENSE.txt
95
109
  - README.md
96
110
  - Rakefile
97
- - doc/TODO
98
111
  - lib/rspotify.rb
99
112
  - lib/rspotify/album.rb
100
113
  - lib/rspotify/artist.rb
@@ -143,3 +156,4 @@ test_files:
143
156
  - spec/lib/rspotify/user_spec.rb
144
157
  - spec/lib/rspotify_spec.rb
145
158
  - spec/spec_helper.rb
159
+ has_rdoc:
data/doc/TODO DELETED
File without changes