rspotify 2.0.0 → 2.1.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: 3a560e9bc44938d7a54e6df175ee4f17f05e5bd5
4
- data.tar.gz: df0f62eabdef80756d5733dcf8c2662991ab8620
3
+ metadata.gz: 3b837a539cae25d32cc6bdfad118ec0ae25de9f4
4
+ data.tar.gz: 21153745531d4695bba73613c70535eb9fac7f0f
5
5
  SHA512:
6
- metadata.gz: 1ab393b11f5dcfc668506b3d5765dd305da5cb6f623fe61c6d9e62bb8616055f2f622d412fb8c13b7caf4fe45aa98b6c30aedeffa376f8c64e7bb3efb03db48e
7
- data.tar.gz: 3e1f2c2e6283dbebaeac0db621a785805d6e25cc2d5a1af0382bd612e236703809fb7d15fc4d3a14a75fed7789bfcf3a6d8cbb2ec06323e0df7bcebfec6c3e5b
6
+ metadata.gz: 25ffeff226c2c59241faffc769685d00122d62ffb1ea51d21a2faa0d5dd641bcdeca88ffba6d4218447204cfe72df9174739ac2011c2413987bf0ec00e950129
7
+ data.tar.gz: '0975e8de9ebdc83fb4778a2229c6a72b33c60639eb9cf64c9df1eb8352291ac0d26f91cfe9304bd5bb5c1d9f2aed2333ebc9c05eece629474424683d5e1b3eb2'
@@ -54,7 +54,6 @@ module RSpotify
54
54
 
55
55
  def send_request(verb, path, *params)
56
56
  url = path.start_with?('http') ? path : API_URI + path
57
-
58
57
  url, query = *url.split('?')
59
58
  url = URI::encode(url)
60
59
  url << "?#{query}" if query
@@ -340,6 +340,24 @@ module RSpotify
340
340
  self
341
341
  end
342
342
 
343
+ # Replace the image used to represent a specific playlist. Requires ugc-image-upload scope. Changing a public playlist
344
+ # requires the *playlist-modify-public* scope; changing a private playlist requires the *playlist-modify-private* scope.
345
+ #
346
+ # @param image [String] Base64 encoded JPEG image data, maximum payload size is 256 KB
347
+ # @param content_type [String] The content type of the request body, e.g. "image/jpeg"
348
+ # @return [NilClass] When the image has been provided, Spofity forwards it on to their transcoder service in order to generate the three sizes provided in the playlist’s images object. This operation takes some time, that's why nothing is returned for this method.
349
+ #
350
+ # @example
351
+ # playlist.replace_image!('SkZJRgABA...', 'image/jpeg')
352
+ def replace_image!(image, content_type)
353
+ url = "#{@path}/images"
354
+ headers = {
355
+ 'Content-Type' => content_type
356
+ }
357
+ User.oauth_put(@owner.id, url, image, { headers: headers })
358
+ nil
359
+ end
360
+
343
361
  # Replace all the tracks in a playlist, overwriting its existing tracks. Changing a public playlist requires
344
362
  # the *playlist-modify-public* scope; changing a private playlist requires the *playlist-modify-private* scope.
345
363
  #
data/lib/rspotify/user.rb CHANGED
@@ -43,6 +43,13 @@ module RSpotify
43
43
  end
44
44
  private_class_method :refresh_token
45
45
 
46
+ def self.extract_custom_headers(params)
47
+ headers_param = params.find{|x| x.is_a?(Hash) && x[:headers]}
48
+ params.delete(headers_param) if headers_param
49
+ headers_param ? headers_param[:headers] : {}
50
+ end
51
+ private_class_method :extract_custom_headers
52
+
46
53
  def self.oauth_header(user_id)
47
54
  {
48
55
  'Authorization' => "Bearer #{@@users_credentials[user_id]['token']}",
@@ -52,18 +59,21 @@ module RSpotify
52
59
  private_class_method :oauth_header
53
60
 
54
61
  def self.oauth_send(user_id, verb, path, *params)
62
+ custom_headers = extract_custom_headers(params)
63
+ headers = oauth_header(user_id).merge(custom_headers)
64
+ params << headers
55
65
  RSpotify.send(:send_request, verb, path, *params)
66
+
56
67
  rescue RestClient::Exception => e
57
68
  raise e if e.response !~ /access token expired/
58
69
  refresh_token(user_id)
59
- params[-1] = oauth_header(user_id)
70
+ params[-1] = headers
60
71
  RSpotify.send(:send_request, verb, path, *params)
61
72
  end
62
73
  private_class_method :oauth_header
63
74
 
64
75
  RSpotify::VERBS.each do |verb|
65
76
  define_singleton_method "oauth_#{verb}" do |user_id, path, *params|
66
- params << oauth_header(user_id)
67
77
  oauth_send(user_id, verb, path, *params)
68
78
  end
69
79
  end
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
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: 2.0.0
4
+ version: 2.1.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: 2018-02-23 00:00:00.000000000 Z
11
+ date: 2018-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2