soundcloud 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df5b0cab01fdc8985e0059c4fbaebbb29672f58c17c33ce1cce2765861eeee3c
4
- data.tar.gz: 730fc7f919b60e2aa582e755560284ebc07957d51054115da4093adfa71ced0c
3
+ metadata.gz: e6fc3d7e7da0596a6223c2a6c2f322ed4d4892f3e66e431eba20f36e59abad83
4
+ data.tar.gz: 4fed15f8d7d7cf2d4a95146e28943356a29c10266f2e4ca74d218026b54e7fc4
5
5
  SHA512:
6
- metadata.gz: 93d8a10bd11b13c43b18e6c5449a3e640f0f43e93eb40473869f3326d84e4f6c4c347929acf9e93ddb0e4f1fa6cf8df75f68d25818636f6738efbe2a2dfafd54
7
- data.tar.gz: 71e706b85e323052f13bd39c1f32368c4cbaaccb41ceaf5e2eed65438502dc025e8adf30191af06ae9ea35efad492faad3a85443ef2cb0d57b4ad0a0b29c6e66
6
+ metadata.gz: 989b6e4dd91accff9bd05fbd1c614906447f87e1f21ced987f888c74c73a26611d6f9351ead6b29fb44fc035368a516169aaf189b2c0231c01add4bbf6c5916b
7
+ data.tar.gz: 71181c248240bcab145ab5f9d127266a3b2aa1ce252c6bfe92fa5accf490f2cdd41e1d772268859f2125c8e8d1b971d9daca54ede2ddead8a915a6e4b2c0dc5e
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ⚠️⚠️DEPRECATED - NO LONGER MAINTAINED⚠️⚠️
2
- This repository is no longer maintained by the SoundCloud team due to capacity constraints. We're instead focusing our efforts on improving the API & the developer platform. Please note, at the time of updating this, the repo is already not in sync with the latest API changes.
2
+ This repository is no longer maintained by the SoundCloud team due to capacity constraints. We're instead focusing our efforts on improving the API & the developer platform. Please note the repo might be not in sync with the latest API changes.
3
3
 
4
- We recommend the community to fork this repo in order to maintain the SDK. We'd be more than happy to make a reference on our developer that the developers can use different SDKs build by the community. In case you need to reach out to us, please head over to https://github.com/soundcloud/api/issues
4
+ We recommend the community to fork this repo in order to maintain the SDK. We'd be more than happy to make a reference on our developer portal that the developers can use different SDKs build by the community. In case you need to reach out to us, please head over to https://github.com/soundcloud/api/issues
5
5
 
6
6
  ---
7
7
 
@@ -24,39 +24,21 @@ The following examples are for the [latest gem version](https://rubygems.org/gem
24
24
 
25
25
  ```ruby
26
26
  SoundCloud::VERSION
27
- # => "0.3.4"
27
+ # => "0.3.6"
28
28
  ```
29
29
 
30
- #### Print links of the 10 most recent tracks
31
- ```ruby
32
- # register a client with YOUR_CLIENT_ID as client_id_
33
- client = SoundCloud.new(:client_id => YOUR_CLIENT_ID)
34
- # get newest tracks
35
- tracks = client.get('/tracks', :limit => 10)
36
- # print each link
37
- tracks.each do |track|
38
- puts track.permalink_url
39
- end
40
- ```
41
-
42
- #### OAuth2 user credentials flow and print the username of the authenticated user
30
+ #### OAuth2 client credentials flow
43
31
  ```ruby
44
- # register a new client, which will exchange the username, password for an access_token
45
- # NOTE: the SoundCloud API Docs advise not to use the user credentials flow in a web app.
46
- # In any case, never store the password of a user.
32
+ # register a new client, which will exchange the client_id, client_secret for an access_token
47
33
  client = SoundCloud.new({
48
34
  :client_id => YOUR_CLIENT_ID,
49
35
  :client_secret => YOUR_CLIENT_SECRET,
50
- :username => 'some@email.com',
51
- :password => 'userpass'
52
36
  })
53
-
54
- # print logged in username
55
- puts client.get('/me').username
56
37
  ```
57
38
 
58
39
  #### OAuth2 authorization code flow
59
40
  ```ruby
41
+ # register a new client, providing the client_id, client_secret and redirect_uri
60
42
  client = SoundCloud.new({
61
43
  :client_id => YOUR_CLIENT_ID,
62
44
  :client_secret => YOUR_CLIENT_SECRET,
@@ -65,14 +47,17 @@ client = SoundCloud.new({
65
47
 
66
48
  redirect client.authorize_url()
67
49
  # the user should be redirected to "https://soundcloud.com/connect?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REDIRECT_URI"
68
- # after granting access he will be redirected back to YOUR_REDIRECT_URI
50
+ # after granting access they will be redirected back to YOUR_REDIRECT_URI with an authorization code present
51
+ # ex: <YOUR_REDIRECT_URI>?code=XXX
69
52
  # in your respective handler you can build an exchange token from the transmitted code
70
53
  client.exchange_token(:code => params[:code])
71
54
  ```
72
55
 
73
56
  #### OAuth2 refresh token flow, upload a track and print its link
74
57
  ```ruby
75
- # register a new client which will exchange an existing refresh_token for an access_token
58
+ # register a new client and exchange an existing refresh_token for an access_token
59
+ # note: refresh_token can also be acquired from authorization code/client_credentials flows.
60
+ # use this flow to automatically update the token when it expires.
76
61
  client = SoundCloud.new({
77
62
  :client_id => YOUR_CLIENT_ID,
78
63
  :client_secret => YOUR_CLIENT_SECRET,
@@ -89,11 +74,19 @@ track = client.post('/tracks', :track => {
89
74
  puts track.permalink_url
90
75
  ```
91
76
 
92
- #### Resolve a track url and print its id
77
+
78
+ #### Print links of the 10 most recent tracks
93
79
  ```ruby
94
- # register the client
95
- client = SoundCloud.new(:client_id => YOUR_CLIENT_ID)
80
+ # get newest tracks
81
+ tracks = client.get('/tracks', :limit => 10)
82
+ # print each link
83
+ tracks.each do |track|
84
+ puts track.permalink_url
85
+ end
86
+ ```
96
87
 
88
+ #### Resolve a track url and print its id
89
+ ```ruby
97
90
  # call the resolve endpoint with a track url
98
91
  track = client.get('/resolve', :url => "http://soundcloud.com/forss/flickermood")
99
92
 
@@ -104,7 +97,7 @@ puts track.id
104
97
  ### Initializing a client with an access token and updating the users profile description
105
98
  ```ruby
106
99
  # initializing a client with an access token
107
- client = SoundCloud.new(:access_token => SOME_ACCESS_TOKEN)
100
+ client = SoundCloud.new(:access_token => A_VALID_TOKEN)
108
101
 
109
102
  # updating the users profile description
110
103
  client.put("/me", :user => {:description => "a new description"})
@@ -112,8 +105,6 @@ client.put("/me", :user => {:description => "a new description"})
112
105
 
113
106
  ### Add a track to a playlist / set
114
107
  ```ruby
115
- client = SoundCloud.new(:access_token => "A_VALID_TOKEN")
116
-
117
108
  # get my last playlist
118
109
  playlist = client.get("/me/playlists").first
119
110
 
@@ -137,20 +128,21 @@ p playlist.tracks.map(&:id)
137
128
 
138
129
  ## Interface
139
130
  #### SoundCloud.new(options={})
140
- Stores the passed options and call exchange_token in case options are passed
131
+ Stores the passed options and calls exchange_token in case all options are passed
141
132
  that allow an exchange of tokens.
142
133
 
143
134
  #### SoundCloud#exchange_token(options={})
144
- Stores the passed options and try to exchange tokens if no access_token is
135
+ Stores the passed options and tries to exchange tokens if no access_token is
145
136
  present and:
146
137
 
147
- * `refresh_token`, `client_id` and `client_secret` is present.
148
- * `client_id`, `client_secret`, `username`, and `password` is present
149
- * `client_id`, `client_secret`, `redirect_uri`, and `code` is present
138
+ * `client_id`, `client_secret` is present (client credentials flow).
139
+ * `refresh_token`, `client_id` and `client_secret` is present (refresh token flow).
140
+ * `client_id`, `client_secret`, `redirect_uri`, and `code` is present (authorization code flow).
150
141
 
151
142
  #### SoundCloud#authorize_url(options={})
152
- Stores the passed options except for `state` and `display` and return an
153
- authorize url. The `client_id` and `redirect_uri` options need to present to
143
+ Stores the passed options except for `state` and `display` and returns an
144
+ authorize url (a part of authorization code flow).
145
+ The `client_id` and `redirect_uri` options has to be present to
154
146
  generate the authorize url. The `state` and `display` options can be used to
155
147
  set the parameters accordingly in the authorize url.
156
148
 
@@ -18,10 +18,10 @@ module SoundCloud
18
18
 
19
19
  def initialize(options={})
20
20
  store_options(options)
21
- if access_token.nil? && (options_for_refresh_flow_present? || options_for_credentials_flow_present? || options_for_code_flow_present? || client_secret)
21
+ if access_token.nil? && (options_for_refresh_flow_present? || options_for_code_flow_present? || options_for_credentials_flow_present?)
22
22
  exchange_token
23
23
  end
24
- raise ArgumentError, "At least a client_id or an access_token must be present" if client_id.nil? && access_token.nil?
24
+ raise ArgumentError, "At least a client_id, client_secret or an access_token must be present" if client_id.nil? && client_secret.nil? && access_token.nil?
25
25
  end
26
26
 
27
27
  def get(path, query={}, options={})
@@ -102,33 +102,28 @@ module SoundCloud
102
102
  "#{param_name}=#{CGI.escape value}" unless value.nil?
103
103
  end.compact.join("&")
104
104
  store_options(options)
105
- "https://#{host}#{AUTHORIZE_PATH}?response_type=code_and_token&client_id=#{client_id}&redirect_uri=#{URI.escape(redirect_uri)}&#{additional_params}"
105
+ "https://#{api_host}#{AUTHORIZE_PATH}?response_type=code&client_id=#{client_id}&redirect_uri=#{URI.escape(redirect_uri)}&#{additional_params}"
106
106
  end
107
107
 
108
108
  def exchange_token(options={})
109
109
  store_options(options)
110
110
  raise ArgumentError, 'client_id and client_secret is required to retrieve an access_token' if client_id.nil? || client_secret.nil?
111
111
 
112
- params = if options_for_refresh_flow_present?
112
+ params = if options_for_code_flow_present?
113
+ {
114
+ :grant_type => 'authorization_code',
115
+ :redirect_uri => redirect_uri,
116
+ :code => @options[:code],
117
+ }
118
+ elsif options_for_refresh_flow_present?
113
119
  {
114
120
  :grant_type => 'refresh_token',
115
121
  :refresh_token => refresh_token,
116
122
  }
117
123
  elsif options_for_credentials_flow_present?
118
- puts "Warning: Password grant is deprecated, see https://developers.soundcloud.com/blog/security-updates-api"
119
124
  {
120
- :grant_type => 'password',
121
- :username => @options[:username],
122
- :password => @options[:password],
123
- }
124
- elsif options_for_code_flow_present?
125
- {
126
- :grant_type => 'authorization_code',
127
- :redirect_uri => @options[:redirect_uri],
128
- :code => @options[:code],
125
+ :grant_type => 'client_credentials'
129
126
  }
130
- elsif client_secret
131
- { :grant_type => 'client_credentials' }
132
127
  end
133
128
 
134
129
  params.merge!(:client_id => client_id, :client_secret => client_secret)
@@ -139,6 +134,7 @@ module SoundCloud
139
134
 
140
135
  @options.merge!(:access_token => response.access_token, :refresh_token => response.refresh_token)
141
136
  @options[:expires_at] = Time.now + response.expires_in if response.expires_in
137
+ @options[:code] = nil
142
138
  @options[:on_exchange_token].call(*[(self if @options[:on_exchange_token].arity == 1)].compact)
143
139
  response
144
140
  end
@@ -173,7 +169,7 @@ module SoundCloud
173
169
  end
174
170
 
175
171
  def options_for_credentials_flow_present?
176
- !!(@options[:username] && @options[:password])
172
+ !!@options[:client_secret]
177
173
  end
178
174
 
179
175
  def options_for_code_flow_present?
@@ -195,7 +191,7 @@ module SoundCloud
195
191
  if access_token
196
192
  options[:headers] = { 'Authorization' => "OAuth #{access_token}" }
197
193
  else
198
- puts "Warning: Authorization via ClientId is deprecated, see https://developers.soundcloud.com/blog/security-updates-api"
194
+ puts "Warning: Authorization via client_id is deprecated, access_token is required. For details see https://developers.soundcloud.com/blog/security-updates-api"
199
195
  options[body_or_query][CLIENT_ID_PARAM_NAME] = client_id
200
196
  end
201
197
  [
@@ -1,3 +1,3 @@
1
1
  module SoundCloud
2
- VERSION = '0.3.5'
2
+ VERSION = '0.3.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soundcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Wagener
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-24 00:00:00.000000000 Z
12
+ date: 2022-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httmultiparty