spotify-client 0.0.8 → 0.0.9

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: 41aaddaf711313958fbda73d3f50868b0ac9b4da
4
- data.tar.gz: 7740dd06138e834eafc0349c12eb691fc4e2e8de
3
+ metadata.gz: 5f7f3be2065733eda7e92a6c7135a7fe2d494fd6
4
+ data.tar.gz: 9dda413fd8b39c1b97ff4e62a8047beaf6a3a32e
5
5
  SHA512:
6
- metadata.gz: b7e48774a3caccb830217c99fba668e1b765ed37ea105f6046e483e4f6636af5cc9323696b7d77d7d11b9e9f8298cdaec76d889251e3f24623292636f743728b
7
- data.tar.gz: d38b30d30f3354a8840937a5173a060fc60bfded6e2b641ea57b4025db69ad8427d3caa13c374c3eaf6b232405a4eea09fc5776c50316c263798ff0591f59c01
6
+ metadata.gz: 4c9378f4277bf916cb5fe7b833f403c1a33a096b38dccda0d57dcd81ca12722f5a71108c2bbda95f7dddc2e3b3f944fe0e4e21ad49ae86bc47613b1bde7b7df1
7
+ data.tar.gz: bdd1777d36989b2233bbb499912ed23238dd7e56c319b2e4f3fcefcf82886c480a410cacf32db7eab2b9a7e4b5d74ce1e4532666a11231dc7ae18a865e120490
@@ -22,11 +22,11 @@ module Spotify
22
22
  @retries = config[:retries] || 0
23
23
  @read_timeout = config[:read_timeout] || 10
24
24
  @write_timeout = config[:write_timeout] || 10
25
- @connection = Excon.new(BASE_URI, :persistent => config[:persistent] || false)
25
+ @connection = Excon.new(BASE_URI, persistent: config[:persistent] || false)
26
26
  end
27
27
 
28
28
  def inspect
29
- vars = self.instance_variables.map{ |v| "#{v}=#{instance_variable_get(v).inspect}"}.join(', ')
29
+ vars = instance_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(', ')
30
30
  "<#{self.class}: #{vars}>"
31
31
  end
32
32
 
@@ -37,7 +37,11 @@ module Spotify
37
37
  end
38
38
 
39
39
  def me
40
- run(:get, "/v1/me", [200])
40
+ run(:get, '/v1/me', [200])
41
+ end
42
+
43
+ def me_tracks
44
+ run(:get, '/v1/me/tracks', [200])
41
45
  end
42
46
 
43
47
  def user(user_id)
@@ -53,16 +57,16 @@ module Spotify
53
57
  end
54
58
 
55
59
  def user_playlist_tracks(user_id, playlist_id, params = {})
56
- tracks = { "items" => [] }
60
+ tracks = { 'items' => [] }
57
61
  path = "/v1/users/#{user_id}/playlists/#{playlist_id}/tracks"
58
62
 
59
63
  while path
60
64
  response = run(:get, path, [200], params)
61
- tracks["items"].concat(response.delete("items"))
65
+ tracks['items'].concat(response.delete('items'))
62
66
  tracks.merge!(response)
63
67
 
64
- path = if response["next"]
65
- response["next"].gsub(BASE_URI, '')
68
+ path = if response['next']
69
+ response['next'].gsub(BASE_URI, '')
66
70
  else
67
71
  nil
68
72
  end
@@ -76,7 +80,7 @@ module Spotify
76
80
  # Requires playlist-modify-public for a public playlist.
77
81
  # Requires playlist-modify-private for a private playlist.
78
82
  def create_user_playlist(user_id, name, is_public = true)
79
- run(:post, "/v1/users/#{user_id}/playlists", [201], JSON.dump({ :name => name, :public => is_public }), false)
83
+ run(:post, "/v1/users/#{user_id}/playlists", [201], JSON.dump(name: name, public: is_public), false)
80
84
  end
81
85
 
82
86
  # Add an Array of track uris to an existing playlist.
@@ -86,9 +90,9 @@ module Spotify
86
90
  #
87
91
  # client.add_user_tracks_to_playlist('1181346016', '7i3thJWDtmX04dJhFwYb0x', %w(spotify:track:4iV5W9uYEdYUVa79Axb7Rh spotify:track:2lzEz3A3XIFyhMDqzMdcss))
88
92
  def add_user_tracks_to_playlist(user_id, playlist_id, uris = [], position = nil)
89
- params = { :uris => Array.wrap(uris)[0..99].join(',') }
93
+ params = { uris: Array.wrap(uris)[0..99].join(',') }
90
94
  if position
91
- params.merge!(:position => position)
95
+ params.merge!(position: position)
92
96
  end
93
97
  run(:post, "/v1/users/#{user_id}/playlists/#{playlist_id}/tracks", [201], params, false)
94
98
  end
@@ -97,14 +101,14 @@ module Spotify
97
101
  #
98
102
  # client.remove_user_tracks_from_playlist('1181346016', '7i3thJWDtmX04dJhFwYb0x', [{ uri: spotify:track:4iV5W9uYEdYUVa79Axb7Rh, positions: [0]}])
99
103
  def remove_user_tracks_from_playlist(user_id, playlist_id, tracks)
100
- run(:delete, "/v1/users/#{user_id}/playlists/#{playlist_id}/tracks", [200], JSON.dump({ :tracks => tracks }))
104
+ run(:delete, "/v1/users/#{user_id}/playlists/#{playlist_id}/tracks", [200], JSON.dump(tracks: tracks))
101
105
  end
102
106
 
103
107
  # Replaces all occurrences of tracks with what's in the playlist
104
108
  #
105
109
  # client.replace_user_tracks_in_playlist('1181346016', '7i3thJWDtmX04dJhFwYb0x', %w(spotify:track:4iV5W9uYEdYUVa79Axb7Rh spotify:track:2lzEz3A3XIFyhMDqzMdcss))
106
110
  def replace_user_tracks_in_playlist(user_id, playlist_id, tracks)
107
- run(:put, "/v1/users/#{user_id}/playlists/#{playlist_id}/tracks", [201], JSON.dump({ :uris => tracks }))
111
+ run(:put, "/v1/users/#{user_id}/playlists/#{playlist_id}/tracks", [201], JSON.dump(uris: tracks))
108
112
  end
109
113
 
110
114
  # Removes all tracks in playlist
@@ -123,8 +127,8 @@ module Spotify
123
127
  end
124
128
 
125
129
  def albums(album_ids)
126
- params = { :ids => Array.wrap(album_ids).join(',') }
127
- run(:get, "/v1/albums", [200], params)
130
+ params = { ids: Array.wrap(album_ids).join(',') }
131
+ run(:get, '/v1/albums', [200], params)
128
132
  end
129
133
 
130
134
  def track(track_id)
@@ -132,8 +136,8 @@ module Spotify
132
136
  end
133
137
 
134
138
  def tracks(track_ids)
135
- params = { :ids => Array.wrap(track_ids).join(',') }
136
- run(:get, "/v1/tracks", [200], params)
139
+ params = { ids: Array.wrap(track_ids).join(',') }
140
+ run(:get, '/v1/tracks', [200], params)
137
141
  end
138
142
 
139
143
  def artist(artist_id)
@@ -141,8 +145,8 @@ module Spotify
141
145
  end
142
146
 
143
147
  def artists(artist_ids)
144
- params = { :ids => Array.wrap(artist_ids).join(',') }
145
- run(:get, "/v1/tracks", [200], params)
148
+ params = { ids: Array.wrap(artist_ids).join(',') }
149
+ run(:get, '/v1/tracks', [200], params)
146
150
  end
147
151
 
148
152
  def artist_albums(artist_id)
@@ -151,57 +155,70 @@ module Spotify
151
155
 
152
156
  def search(entity, term)
153
157
  unless [:artist, :album, :track].include?(entity.to_sym)
154
- raise(ImplementationError, "entity needs to be either artist, album or track, got: #{entity}")
158
+ fail(ImplementationError, "entity needs to be either artist, album or track, got: #{entity}")
155
159
  end
156
- run(:get, "/v1/search", [200], { :q => term.to_s, type: entity })
160
+ run(:get, '/v1/search', [200], q: term.to_s, type: entity)
157
161
  end
158
162
 
159
- # Get Spotify catalog information about an artists top 10 tracks by country.
163
+ # Get Spotify catalog information about an artist's top 10 tracks by country.
160
164
  #
161
165
  # +country_id+ is required. An ISO 3166-1 alpha-2 country code.
162
166
  def artist_top_tracks(artist_id, country_id)
163
- run(:get, "/v1/artists/#{artist_id}/top-tracks", [200], { :country => country_id })
167
+ run(:get, "/v1/artists/#{artist_id}/top-tracks", [200], country: country_id)
164
168
  end
165
-
169
+
166
170
  def related_artists(artist_id)
167
- run(:get, "/v1/artists/#{artist_id}/related-artists", [200])
171
+ run(:get, "/v1/artists/#{artist_id}/related-artists", [200])
172
+ end
173
+
174
+ # Follow artists or users
175
+ #
176
+ # client.follow('artist', ['0BvkDsjIUla7X0k6CSWh1I'])
177
+ def follow(type, ids)
178
+ params = { type: type, ids: Array.wrap(ids).join(',') }
179
+ run(:put, "/v1/me/following", [204], params)
180
+ end
181
+
182
+ # Follow a playlist
183
+ #
184
+ # client.follow_playlist('lukebryan', '0obRj9nNySESpFelMCLSya')
185
+ def follow_playlist(user_id, playlist_id, is_public = true)
186
+ run(:put, "/v1/users/#{user_id}/playlists/#{playlist_id}/followers", [200], { public: is_public })
168
187
  end
169
188
 
170
189
  protected
171
190
 
172
191
  def run(verb, path, expected_status_codes, params = {}, idempotent = true)
173
- begin
174
- run!(verb, path, expected_status_codes, params)
175
- rescue Error => e
176
- if @raise_errors
177
- raise e
178
- else
179
- false
180
- end
192
+ run!(verb, path, expected_status_codes, params, idempotent)
193
+ rescue Error => e
194
+ if @raise_errors
195
+ raise e
196
+ else
197
+ false
181
198
  end
182
199
  end
183
200
 
184
201
  def run!(verb, path, expected_status_codes, params_or_body = nil, idempotent = true)
185
202
  packet = {
186
- :idempotent => idempotent,
187
- :expects => expected_status_codes,
188
- :method => verb,
189
- :path => path,
190
- :read_timeout => @read_timeout,
191
- :write_timeout => @write_timeout,
192
- :retry_limit => @retries,
193
- :headers => {
203
+ idempotent: idempotent,
204
+ expects: expected_status_codes,
205
+ method: verb,
206
+ path: path,
207
+ read_timeout: @read_timeout,
208
+ write_timeout: @write_timeout,
209
+ retry_limit: @retries,
210
+ headers: {
194
211
  'Content-Type' => 'application/json',
195
212
  'User-Agent' => 'Spotify Ruby Client'
196
213
  }
197
214
  }
198
215
  if params_or_body.is_a?(Hash)
199
- packet.merge!(:query => params_or_body)
216
+ packet.merge!(query: params_or_body)
200
217
  else
201
- packet.merge!(:body => params_or_body)
218
+ packet.merge!(body: params_or_body)
202
219
  end
203
220
 
204
- if @access_token != nil && @access_token != ""
221
+ if !@access_token.nil? && @access_token != ''
205
222
  packet[:headers].merge!('Authorization' => "Bearer #{@access_token}")
206
223
  end
207
224
 
@@ -220,10 +237,10 @@ module Spotify
220
237
  rescue Excon::Errors::Error => exception
221
238
  # Catch all others errors. Samples:
222
239
  #
223
- #<Excon::Errors::SocketError: Connection refused - connect(2) (Errno::ECONNREFUSED)>
224
- #<Excon::Errors::InternalServerError: Expected([200, 204, 404]) <=> Actual(500 InternalServerError)>
225
- #<Excon::Errors::Timeout: read timeout reached>
226
- #<Excon::Errors::BadGateway: Expected([200]) <=> Actual(502 Bad Gateway)>
240
+ # <Excon::Errors::SocketError: Connection refused - connect(2) (Errno::ECONNREFUSED)>
241
+ # <Excon::Errors::InternalServerError: Expected([200, 204, 404]) <=> Actual(500 InternalServerError)>
242
+ # <Excon::Errors::Timeout: read timeout reached>
243
+ # <Excon::Errors::BadGateway: Expected([200]) <=> Actual(502 Bad Gateway)>
227
244
  raise(HTTPError, "Error: #{exception.message}")
228
245
  end
229
246
  end
@@ -0,0 +1,3 @@
1
+ module Spotify
2
+ VERSION = '0.0.9'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spotify-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Poli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-05 00:00:00.000000000 Z
11
+ date: 2015-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -64,6 +64,7 @@ files:
64
64
  - lib/spotify/utils.rb
65
65
  - lib/spotify/version.rb
66
66
  - lib/spotify_client.rb
67
+ - lib/spotify_client/version.rb
67
68
  homepage: https://github.com/icoretech/spotify-client
68
69
  licenses: []
69
70
  metadata: {}
@@ -83,9 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  version: '0'
84
85
  requirements: []
85
86
  rubyforge_project: "[none]"
86
- rubygems_version: 2.2.2
87
+ rubygems_version: 2.4.6
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: Ruby client for the Spotify Web API
90
91
  test_files: []
91
- has_rdoc: