rspotify 1.15.0 → 1.15.1

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: d7a369b00096dcefd7060c3d6d802dbd84c47891
4
- data.tar.gz: 72766cf26e96b3cb2fe24df568b70a64d5683021
3
+ metadata.gz: 1e6de26af3763d772cfac6dcaa7af1872f33eb58
4
+ data.tar.gz: c2068bee7e831a418081238f086823a0dfddf416
5
5
  SHA512:
6
- metadata.gz: b0b1c1b3a0e4651cb1fdf10c158f1ce89276450294dd18799fd72ed7006598c12f39b9220cf0a985a8e92752f37d2815ff2567f0fa7c85f5d5caa709716fe838
7
- data.tar.gz: 8c15b7aa0844acd020380670247505ae83bff813062c12918cab4a43a1595c85921dc1f3ee711eab3575b9dc744bcb6873138e62cfb7362fbd098a42cc7f2907
6
+ metadata.gz: b5da292e7de162c2525f35da9443dea08dbca5160c091b9046ca3f2b61bbad35a6667396b2afa6e62ae54e32c3413878615828760acbade35db925ef6afc1cd9
7
+ data.tar.gz: 1d7b6e62548385c7d88ef98fe74deb7efd533e848fab72450fab9487ad719c0ce7cd5fdbb7a208b54da1ac0a3da3f2be995733cdf0630a4ff251fea4e0f8f3e7
data/README.md CHANGED
@@ -211,6 +211,15 @@ spotify_user = RSpotify::User.new(hash)
211
211
  spotify_user.create_playlist!('my_awesome_playlist') # automatically refreshes token
212
212
  ```
213
213
 
214
+ ## Getting raw response
215
+
216
+ To get the raw response from Spotify API requests, just toggle the `raw_response` variable:
217
+
218
+ ```ruby
219
+ RSpotify.raw_response = true
220
+ RSpotify::Artist.search('Cher') #=> (String with raw json response)
221
+ ```
222
+
214
223
  ## Notes
215
224
 
216
225
  If you'd like to use OAuth outside rails, have a look [here](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow) for the requests that need to be made. You should be able to pass the response to RSpotify::User.new just as well, and from there easily create playlists and more for your user.
@@ -45,6 +45,8 @@ module RSpotify
45
45
  url = "browse/new-releases?limit=#{limit}&offset=#{offset}"
46
46
  url << "&country=#{country}" if country
47
47
  response = RSpotify.get(url)
48
+
49
+ return response if RSpotify.raw_response
48
50
  response['albums']['items'].map { |i| Album.new i }
49
51
  end
50
52
 
@@ -100,14 +102,18 @@ module RSpotify
100
102
  # album.tracks.first.name #=> "Do I Wanna Know?"
101
103
  def tracks(limit: 50, offset: 0)
102
104
  last_track = offset + limit - 1
103
- if @tracks_cache && last_track < 50
105
+ if @tracks_cache && last_track < 50 && !RSpotify.raw_response
104
106
  return @tracks_cache[offset..last_track]
105
107
  end
106
108
 
107
109
  url = "albums/#{@id}/tracks?limit=#{limit}&offset=#{offset}"
108
110
  response = RSpotify.get(url)
109
- tracks = response['items'].map { |i| Track.new i }
111
+ json = RSpotify.raw_response ? JSON.parse(response) : response
112
+
113
+ tracks = json['items'].map { |i| Track.new i }
110
114
  @tracks_cache = tracks if limit == 50 && offset == 0
115
+ return response if RSpotify.raw_response
116
+
111
117
  tracks
112
118
  end
113
119
  end
@@ -73,6 +73,7 @@ module RSpotify
73
73
  end
74
74
 
75
75
  response = RSpotify.get(url)
76
+ return response if RSpotify.raw_response
76
77
  response['items'].map { |i| Album.new i }
77
78
  end
78
79
 
@@ -87,8 +88,10 @@ module RSpotify
87
88
  # related_artists.size #=> 20
88
89
  # related_artists.first.name #=> "Miles Kane"
89
90
  def related_artists
90
- return @related_artists unless @related_artists.nil?
91
+ return @related_artists unless @related_artists.nil? || RSpotify.raw_response
91
92
  response = RSpotify.get("artists/#{@id}/related-artists")
93
+
94
+ return response if RSpotify.raw_response
92
95
  @related_artists = response['artists'].map { |a| Artist.new a }
93
96
  end
94
97
 
@@ -103,8 +106,10 @@ module RSpotify
103
106
  # top_tracks.size #=> 10
104
107
  # top_tracks.first.class #=> RSpotify::Track
105
108
  def top_tracks(country)
106
- return @top_tracks[country] unless @top_tracks[country].nil?
109
+ return @top_tracks[country] unless @top_tracks[country].nil? || RSpotify.raw_response
107
110
  response = RSpotify.get("artists/#{@id}/top-tracks?country=#{country}")
111
+
112
+ return response if RSpotify.raw_response
108
113
  @top_tracks[country] = response['tracks'].map { |t| Track.new t }
109
114
  end
110
115
  end
data/lib/rspotify/base.rb CHANGED
@@ -40,7 +40,9 @@ module RSpotify
40
40
  def self.find_many(ids, type)
41
41
  type_class = RSpotify.const_get(type.capitalize)
42
42
  path = "#{type}s?ids=#{ids.join ','}"
43
+
43
44
  response = RSpotify.get path
45
+ return response if RSpotify.raw_response
44
46
  response["#{type}s"].map { |t| type_class.new t }
45
47
  end
46
48
  private_class_method :find_many
@@ -48,7 +50,9 @@ module RSpotify
48
50
  def self.find_one(id, type)
49
51
  type_class = RSpotify.const_get(type.capitalize)
50
52
  path = "#{type}s/#{id}"
53
+
51
54
  response = RSpotify.get path
55
+ return response if RSpotify.raw_response
52
56
  type_class.new response
53
57
  end
54
58
  private_class_method :find_one
@@ -97,6 +101,8 @@ module RSpotify
97
101
  RSpotify.get(url)
98
102
  end
99
103
 
104
+ return response if RSpotify.raw_response
105
+
100
106
  types = types.split(',')
101
107
  result = types.flat_map do |type|
102
108
  type_class = RSpotify.const_get(type.capitalize)
@@ -30,6 +30,7 @@ module RSpotify
30
30
  end
31
31
 
32
32
  response = RSpotify.get(url)
33
+ return response if RSpotify.raw_response
33
34
  Category.new response
34
35
  end
35
36
 
@@ -50,7 +51,9 @@ module RSpotify
50
51
  options.each do |option, value|
51
52
  url << "&#{option}=#{value}"
52
53
  end
54
+
53
55
  response = RSpotify.get(url)
56
+ return response if RSpotify.raw_response
54
57
  response['categories']['items'].map { |i| Category.new i }
55
58
  end
56
59
 
@@ -92,6 +95,7 @@ module RSpotify
92
95
  end
93
96
 
94
97
  response = RSpotify.get(url)
98
+ return response if RSpotify.raw_response
95
99
  response['playlists']['items'].map { |i| Playlist.new i }
96
100
  end
97
101
  end
@@ -10,6 +10,7 @@ module RSpotify
10
10
  VERBS = %w(get post put delete)
11
11
 
12
12
  class << self
13
+ attr_accessor :raw_response
13
14
 
14
15
  # Authenticates access to restricted data. Requires {https://developer.spotify.com/my-applications user credentials}
15
16
  #
@@ -52,6 +53,7 @@ module RSpotify
52
53
 
53
54
  def send_request(verb, path, *params)
54
55
  url = path.start_with?("http") ? path : API_URI + path
56
+
55
57
  begin
56
58
  response = RestClient.send(verb, url, *params)
57
59
  rescue RestClient::Unauthorized
@@ -60,6 +62,8 @@ module RSpotify
60
62
  response = RestClient.send(verb, url, *params)
61
63
  end
62
64
  end
65
+
66
+ return response if raw_response
63
67
  JSON.parse response unless response.empty?
64
68
  end
65
69
 
@@ -32,7 +32,9 @@ module RSpotify
32
32
  options.each do |option, value|
33
33
  url << "&#{option}=#{value}"
34
34
  end
35
+
35
36
  response = RSpotify.get(url)
37
+ return response if RSpotify.raw_response
36
38
  response['playlists']['items'].map { |i| Playlist.new i }
37
39
  end
38
40
 
@@ -52,7 +54,9 @@ module RSpotify
52
54
  else
53
55
  "users/#{user_id}/playlists/#{id}"
54
56
  end
57
+
55
58
  response = RSpotify.resolve_auth_request(user_id, url)
59
+ return response if RSpotify.raw_response
56
60
  Playlist.new response
57
61
  end
58
62
 
@@ -131,10 +135,15 @@ module RSpotify
131
135
  url << "&position=#{position}" if position
132
136
 
133
137
  response = User.oauth_post(@owner.id, url, {})
134
- @snapshot_id = response['snapshot_id']
135
-
136
138
  @total += tracks.size
137
139
  @tracks_cache = nil
140
+
141
+ if RSpotify::raw_response
142
+ @snapshot_id = JSON.parse(response)['snapshot_id']
143
+ return response
144
+ end
145
+
146
+ @snapshot_id = json['snapshot_id']
138
147
  tracks
139
148
  end
140
149
 
@@ -219,13 +228,15 @@ module RSpotify
219
228
  # playlist.tracks.first.name #=> "Main Theme from Star Wars - Instrumental"
220
229
  def tracks(limit: 100, offset: 0)
221
230
  last_track = offset + limit - 1
222
- if @tracks_cache && last_track < 100
231
+ if @tracks_cache && last_track < 100 && !RSpotify.raw_response
223
232
  return @tracks_cache[offset..last_track]
224
233
  end
225
234
 
226
235
  url = "#{@href}/tracks?limit=#{limit}&offset=#{offset}"
227
236
  response = RSpotify.resolve_auth_request(@owner.id, url)
228
- tracks = response['items'].select { |i| i['track'] }
237
+
238
+ json = RSpotify.raw_response ? JSON.parse(response) : response
239
+ tracks = json['items'].select { |i| i['track'] }
229
240
 
230
241
  @tracks_added_at = hash_for(tracks, 'added_at') do |added_at|
231
242
  Time.parse added_at
@@ -241,6 +252,7 @@ module RSpotify
241
252
 
242
253
  tracks.map! { |t| Track.new t['track'] }
243
254
  @tracks_cache = tracks if limit == 100 && offset == 0
255
+ return response if RSpotify.raw_response
244
256
  tracks
245
257
  end
246
258
 
@@ -312,7 +324,9 @@ module RSpotify
312
324
  }.merge options
313
325
 
314
326
  response = User.oauth_put(@owner.id, url, data.to_json)
315
- @snapshot_id = response['snapshot_id']
327
+ json = RSpotify.raw_response ? JSON.parse(response) : response
328
+
329
+ @snapshot_id = json['snapshot_id']
316
330
  @tracks_cache = nil
317
331
  self
318
332
  end
data/lib/rspotify/user.rb CHANGED
@@ -105,7 +105,10 @@ module RSpotify
105
105
  def create_playlist!(name, public: true)
106
106
  url = "users/#{@id}/playlists"
107
107
  request_data = { name: name, public: public }.to_json
108
- Playlist.new User.oauth_post(@id, url, request_data)
108
+
109
+ response = User.oauth_post(@id, url, request_data)
110
+ return response if RSpotify.raw_response
111
+ Playlist.new response
109
112
  end
110
113
 
111
114
  # Add the current user as a follower of one or more artists, other Spotify users or a playlist. Following artists or users require the *user-follow-modify*
@@ -164,6 +167,7 @@ module RSpotify
164
167
  url << "&after=#{after}" if after
165
168
 
166
169
  response = User.oauth_get(@id, url)
170
+ return response if RSpotify.raw_response
167
171
  response["#{type}s"]['items'].map { |i| type_class.new i }
168
172
  end
169
173
 
@@ -203,6 +207,7 @@ module RSpotify
203
207
  def playlists(limit: 20, offset: 0)
204
208
  url = "users/#{@id}/playlists?limit=#{limit}&offset=#{offset}"
205
209
  response = RSpotify.resolve_auth_request(@id, url)
210
+ return response if RSpotify.raw_response
206
211
  response['items'].map { |i| Playlist.new i }
207
212
  end
208
213
 
@@ -256,12 +261,14 @@ module RSpotify
256
261
  def saved_tracks(limit: 20, offset: 0)
257
262
  url = "me/tracks?limit=#{limit}&offset=#{offset}"
258
263
  response = User.oauth_get(@id, url)
264
+ json = RSpotify.raw_response ? JSON.parse(response) : response
259
265
 
260
- tracks = response['items'].select { |i| i['track'] }
266
+ tracks = json['items'].select { |i| i['track'] }
261
267
  @tracks_added_at = hash_for(tracks, 'added_at') do |added_at|
262
268
  Time.parse added_at
263
269
  end
264
270
 
271
+ return response if RSpotify.raw_response
265
272
  tracks.map { |t| Track.new t['track'] }
266
273
  end
267
274
 
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '1.15.0'
2
+ VERSION = '1.15.1'
3
3
  end
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: 1.15.0
4
+ version: 1.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Sad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-19 00:00:00.000000000 Z
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2