soundcloud 0.3.2 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e6fc3d7e7da0596a6223c2a6c2f322ed4d4892f3e66e431eba20f36e59abad83
4
+ data.tar.gz: 4fed15f8d7d7cf2d4a95146e28943356a29c10266f2e4ca74d218026b54e7fc4
5
+ SHA512:
6
+ metadata.gz: 989b6e4dd91accff9bd05fbd1c614906447f87e1f21ced987f888c74c73a26611d6f9351ead6b29fb44fc035368a516169aaf189b2c0231c01add4bbf6c5916b
7
+ data.tar.gz: 71181c248240bcab145ab5f9d127266a3b2aa1ce252c6bfe92fa5accf490f2cdd41e1d772268859f2125c8e8d1b971d9daca54ede2ddead8a915a6e4b2c0dc5e
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2015 SoundCloud Ltd., Johannes Wagener, Erik Michaels-Ober
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,3 +1,10 @@
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 the repo might be not in sync with the latest API changes.
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 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
+
6
+ ---
7
+
1
8
  # SoundCloud API Wrapper
2
9
 
3
10
  [![Build Status](https://travis-ci.org/soundcloud/soundcloud-ruby.png?branch=master)](https://travis-ci.org/soundcloud/soundcloud-ruby)
@@ -12,36 +19,26 @@ gem install soundcloud
12
19
  ```
13
20
 
14
21
  ## Examples
15
- #### Print links of the 10 hottest tracks
22
+
23
+ The following examples are for the [latest gem version](https://rubygems.org/gems/soundcloud).
24
+
16
25
  ```ruby
17
- # register a client with YOUR_CLIENT_ID as client_id_
18
- client = SoundCloud.new(:client_id => YOUR_CLIENT_ID)
19
- # get 10 hottest tracks
20
- tracks = client.get('/tracks', :limit => 10, :order => 'hotness')
21
- # print each link
22
- tracks.each do |track|
23
- puts track.permalink_url
24
- end
26
+ SoundCloud::VERSION
27
+ # => "0.3.6"
25
28
  ```
26
29
 
27
- #### OAuth2 user credentials flow and print the username of the authenticated user
30
+ #### OAuth2 client credentials flow
28
31
  ```ruby
29
- # register a new client, which will exchange the username, password for an access_token
30
- # NOTE: the SoundCloud API Docs advise not to use the user credentials flow in a web app.
31
- # 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
32
33
  client = SoundCloud.new({
33
34
  :client_id => YOUR_CLIENT_ID,
34
35
  :client_secret => YOUR_CLIENT_SECRET,
35
- :username => 'some@email.com',
36
- :password => 'userpass'
37
36
  })
38
-
39
- # print logged in username
40
- puts client.get('/me').username
41
37
  ```
42
38
 
43
39
  #### OAuth2 authorization code flow
44
40
  ```ruby
41
+ # register a new client, providing the client_id, client_secret and redirect_uri
45
42
  client = SoundCloud.new({
46
43
  :client_id => YOUR_CLIENT_ID,
47
44
  :client_secret => YOUR_CLIENT_SECRET,
@@ -50,21 +47,24 @@ client = SoundCloud.new({
50
47
 
51
48
  redirect client.authorize_url()
52
49
  # the user should be redirected to "https://soundcloud.com/connect?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REDIRECT_URI"
53
- # 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
54
52
  # in your respective handler you can build an exchange token from the transmitted code
55
53
  client.exchange_token(:code => params[:code])
56
54
  ```
57
55
 
58
56
  #### OAuth2 refresh token flow, upload a track and print its link
59
57
  ```ruby
60
- # 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.
61
61
  client = SoundCloud.new({
62
62
  :client_id => YOUR_CLIENT_ID,
63
63
  :client_secret => YOUR_CLIENT_SECRET,
64
64
  :refresh_token => SOME_REFRESH_TOKEN
65
65
  })
66
66
 
67
- # upload a new track with track.mp3 as audio and image.jpg as artwork
67
+ # upload a new track with audio.mp3 as audio and image.jpg as artwork
68
68
  track = client.post('/tracks', :track => {
69
69
  :title => 'a new track',
70
70
  :asset_data => File.new('audio.mp3')
@@ -74,11 +74,19 @@ track = client.post('/tracks', :track => {
74
74
  puts track.permalink_url
75
75
  ```
76
76
 
77
- #### Resolve a track url and print its id
77
+
78
+ #### Print links of the 10 most recent tracks
78
79
  ```ruby
79
- # register the client
80
- 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
+ ```
81
87
 
88
+ #### Resolve a track url and print its id
89
+ ```ruby
82
90
  # call the resolve endpoint with a track url
83
91
  track = client.get('/resolve', :url => "http://soundcloud.com/forss/flickermood")
84
92
 
@@ -89,7 +97,7 @@ puts track.id
89
97
  ### Initializing a client with an access token and updating the users profile description
90
98
  ```ruby
91
99
  # initializing a client with an access token
92
- client = SoundCloud.new(:access_token => SOME_ACCESS_TOKEN)
100
+ client = SoundCloud.new(:access_token => A_VALID_TOKEN)
93
101
 
94
102
  # updating the users profile description
95
103
  client.put("/me", :user => {:description => "a new description"})
@@ -97,8 +105,6 @@ client.put("/me", :user => {:description => "a new description"})
97
105
 
98
106
  ### Add a track to a playlist / set
99
107
  ```ruby
100
- client = SoundCloud.new(:access_token => "A_VALID_TOKEN")
101
-
102
108
  # get my last playlist
103
109
  playlist = client.get("/me/playlists").first
104
110
 
@@ -122,20 +128,21 @@ p playlist.tracks.map(&:id)
122
128
 
123
129
  ## Interface
124
130
  #### SoundCloud.new(options={})
125
- 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
126
132
  that allow an exchange of tokens.
127
133
 
128
134
  #### SoundCloud#exchange_token(options={})
129
- 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
130
136
  present and:
131
137
 
132
- * `refresh_token`, `client_id` and `client_secret` is present.
133
- * `client_id`, `client_secret`, `username`, and `password` is present
134
- * `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).
135
141
 
136
142
  #### SoundCloud#authorize_url(options={})
137
- Stores the passed options except for `state` and `display` and return an
138
- 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
139
146
  generate the authorize url. The `state` and `display` options can be used to
140
147
  set the parameters accordingly in the authorize url.
141
148
 
@@ -168,3 +175,7 @@ Will return true or false depending on if `expires_at` is in the past.
168
175
  In case a request was not successful a SoundCloud::ResponseError will be
169
176
  raised. The original HTTParty response is available through
170
177
  `SoundCloud::ResponseError#response`.
178
+
179
+ ## Documentation
180
+
181
+ For more code examples, please visit the [SoundCloud API Documentation](http://developers.soundcloud.com/docs).
@@ -1,7 +1,9 @@
1
+ require 'soundcloud/version'
2
+
1
3
  module SoundCloud
2
4
  class Client
3
5
  include HTTMultiParty
4
- USER_AGENT = "SoundCloud Ruby Wrapper #{VERSION}"
6
+ USER_AGENT = "SoundCloud Ruby Wrapper #{SoundCloud::VERSION}"
5
7
  CLIENT_ID_PARAM_NAME = :client_id
6
8
  API_SUBHOST = 'api'
7
9
  AUTHORIZE_PATH = '/connect'
@@ -16,10 +18,10 @@ module SoundCloud
16
18
 
17
19
  def initialize(options={})
18
20
  store_options(options)
19
- if access_token.nil? && (options_for_refresh_flow_present? || options_for_credentials_flow_present? || options_for_code_flow_present?)
21
+ if access_token.nil? && (options_for_refresh_flow_present? || options_for_code_flow_present? || options_for_credentials_flow_present?)
20
22
  exchange_token
21
23
  end
22
- 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?
23
25
  end
24
26
 
25
27
  def get(path, query={}, options={})
@@ -100,37 +102,39 @@ module SoundCloud
100
102
  "#{param_name}=#{CGI.escape value}" unless value.nil?
101
103
  end.compact.join("&")
102
104
  store_options(options)
103
- "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}"
104
106
  end
105
107
 
106
108
  def exchange_token(options={})
107
109
  store_options(options)
108
110
  raise ArgumentError, 'client_id and client_secret is required to retrieve an access_token' if client_id.nil? || client_secret.nil?
109
- client_params = {:client_id => client_id, :client_secret => client_secret}
110
- params = if options_for_refresh_flow_present?
111
+
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?
111
119
  {
112
120
  :grant_type => 'refresh_token',
113
121
  :refresh_token => refresh_token,
114
122
  }
115
123
  elsif options_for_credentials_flow_present?
116
124
  {
117
- :grant_type => 'password',
118
- :username => @options[:username],
119
- :password => @options[:password],
120
- }
121
- elsif options_for_code_flow_present?
122
- {
123
- :grant_type => 'authorization_code',
124
- :redirect_uri => @options[:redirect_uri],
125
- :code => @options[:code],
125
+ :grant_type => 'client_credentials'
126
126
  }
127
127
  end
128
- params.merge!(client_params)
128
+
129
+ params.merge!(:client_id => client_id, :client_secret => client_secret)
130
+
129
131
  response = handle_response(false) {
130
132
  self.class.post("https://#{api_host}#{TOKEN_PATH}", :query => params)
131
133
  }
134
+
132
135
  @options.merge!(:access_token => response.access_token, :refresh_token => response.refresh_token)
133
136
  @options[:expires_at] = Time.now + response.expires_in if response.expires_in
137
+ @options[:code] = nil
134
138
  @options[:on_exchange_token].call(*[(self if @options[:on_exchange_token].arity == 1)].compact)
135
139
  response
136
140
  end
@@ -151,9 +155,9 @@ module SoundCloud
151
155
  else
152
156
  raise ResponseError.new(response)
153
157
  end
154
- elsif response.is_a?(Hash)
158
+ elsif response_is_a?(response, Hash)
155
159
  HashResponseWrapper.new(response)
156
- elsif response.is_a?(Array)
160
+ elsif response_is_a?(response, Array)
157
161
  ArrayResponseWrapper.new(response)
158
162
  elsif response && response.success?
159
163
  response
@@ -165,7 +169,7 @@ module SoundCloud
165
169
  end
166
170
 
167
171
  def options_for_credentials_flow_present?
168
- !!(@options[:username] && @options[:password])
172
+ !!@options[:client_secret]
169
173
  end
170
174
 
171
175
  def options_for_code_flow_present?
@@ -185,8 +189,9 @@ module SoundCloud
185
189
  options[body_or_query] ||= {}
186
190
  options[body_or_query][:format] = "json"
187
191
  if access_token
188
- options[body_or_query][:oauth_token] = access_token
192
+ options[:headers] = { 'Authorization' => "OAuth #{access_token}" }
189
193
  else
194
+ puts "Warning: Authorization via client_id is deprecated, access_token is required. For details see https://developers.soundcloud.com/blog/security-updates-api"
190
195
  options[body_or_query][CLIENT_ID_PARAM_NAME] = client_id
191
196
  end
192
197
  [
@@ -195,5 +200,8 @@ module SoundCloud
195
200
  ]
196
201
  end
197
202
 
203
+ def response_is_a?(response, type)
204
+ response.is_a?(type) || (response.respond_to?(:parsed_response) && response.parsed_response.is_a?(type))
205
+ end
198
206
  end
199
207
  end
@@ -1,3 +1,3 @@
1
1
  module SoundCloud
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.7'
3
3
  end
metadata CHANGED
@@ -1,102 +1,94 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soundcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
5
- prerelease:
4
+ version: 0.3.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Johannes Wagener
9
- autorequire:
8
+ - Erik Michaels-Ober
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-19 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
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
- - - ~>
18
+ - - "~>"
20
19
  - !ruby/object:Gem::Version
21
20
  version: 0.3.0
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
- - - ~>
25
+ - - "~>"
28
26
  - !ruby/object:Gem::Version
29
27
  version: 0.3.0
30
28
  - !ruby/object:Gem::Dependency
31
29
  name: hashie
32
30
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
- - - ~>
32
+ - - ">="
36
33
  - !ruby/object:Gem::Version
37
- version: '2.0'
34
+ version: '0'
38
35
  type: :runtime
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
- - - ~>
39
+ - - ">="
44
40
  - !ruby/object:Gem::Version
45
- version: '2.0'
41
+ version: '0'
46
42
  - !ruby/object:Gem::Dependency
47
43
  name: bundler
48
44
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
45
  requirements:
51
- - - ~>
46
+ - - "~>"
52
47
  - !ruby/object:Gem::Version
53
48
  version: '1.0'
54
49
  type: :development
55
50
  prerelease: false
56
51
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
- - - ~>
53
+ - - "~>"
60
54
  - !ruby/object:Gem::Version
61
55
  version: '1.0'
62
56
  description: The official SoundCloud API wrapper. It provides simple methods to handle
63
57
  authorization and to execute HTTP calls.
64
58
  email:
65
- - johannes@soundcloud.com
59
+ - api@soundcloud.com
66
60
  executables: []
67
61
  extensions: []
68
62
  extra_rdoc_files: []
69
63
  files:
64
+ - LICENSE.md
65
+ - README.md
66
+ - lib/soundcloud.rb
70
67
  - lib/soundcloud/array_response_wrapper.rb
71
68
  - lib/soundcloud/client.rb
72
69
  - lib/soundcloud/hash_response_wrapper.rb
73
70
  - lib/soundcloud/response_error.rb
74
71
  - lib/soundcloud/version.rb
75
- - lib/soundcloud.rb
76
- - README.md
77
- homepage: http://dev.soundcloud.com
72
+ homepage: https://dev.soundcloud.com
78
73
  licenses: []
79
- post_install_message:
74
+ metadata: {}
75
+ post_install_message:
80
76
  rdoc_options: []
81
77
  require_paths:
82
78
  - lib
83
79
  required_ruby_version: !ruby/object:Gem::Requirement
84
- none: false
85
80
  requirements:
86
- - - ! '>='
81
+ - - ">="
87
82
  - !ruby/object:Gem::Version
88
83
  version: '0'
89
84
  required_rubygems_version: !ruby/object:Gem::Requirement
90
- none: false
91
85
  requirements:
92
- - - ! '>='
86
+ - - ">="
93
87
  - !ruby/object:Gem::Version
94
88
  version: 1.3.5
95
89
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 1.8.23
98
- signing_key:
99
- specification_version: 3
90
+ rubygems_version: 3.1.2
91
+ signing_key:
92
+ specification_version: 4
100
93
  summary: The official SoundCloud API wrapper.
101
94
  test_files: []
102
- has_rdoc: