soundcloud 0.1.7 → 0.1.8
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.
- data/README.md +20 -18
- data/lib/soundcloud.rb +2 -0
- data/lib/soundcloud/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Soundcloud API Wrapper
|
2
|
-
##
|
3
|
-
|
2
|
+
## Declientription
|
3
|
+
The Soundcloud gem is a thin wrapper for the Soundcloud API based of the httparty gem.
|
4
4
|
It is providing simple methods to handle authorization and to execute HTTP calls.
|
5
5
|
|
6
6
|
## Requirements
|
@@ -14,7 +14,7 @@ It is providing simple methods to handle authorization and to execute HTTP calls
|
|
14
14
|
gem install soundcloud
|
15
15
|
|
16
16
|
## Examples
|
17
|
-
####
|
17
|
+
#### Print links of the 10 hottest tracks
|
18
18
|
# register a client with YOUR_CLIENT_ID as client_id_
|
19
19
|
client = Soundcloud.new(:client_id => YOUR_CLIENT_ID)
|
20
20
|
# get 10 hottest tracks
|
@@ -24,8 +24,10 @@ It is providing simple methods to handle authorization and to execute HTTP calls
|
|
24
24
|
puts track.permalink_url
|
25
25
|
end
|
26
26
|
|
27
|
-
####
|
27
|
+
#### OAuth2 user credentials flow and print the username of the authenticated user
|
28
28
|
# register a new client, which will exchange the username, password for an access_token
|
29
|
+
# NOTE: the SoundCloud API Docs advices to not use the user credentials flow in a web app.
|
30
|
+
# In any case never store the password of a user.
|
29
31
|
client = Soundcloud.new({
|
30
32
|
:client_id => YOUR_CLIENT_ID,
|
31
33
|
:client_secret => YOUR_CLIENT_SECRET,
|
@@ -36,17 +38,17 @@ It is providing simple methods to handle authorization and to execute HTTP calls
|
|
36
38
|
# print logged in username
|
37
39
|
puts client.get('/me').username
|
38
40
|
|
39
|
-
####
|
40
|
-
|
41
|
+
#### OAuth2 authorization code flow
|
42
|
+
client = Soundcloud.new({
|
41
43
|
:client_id => YOUR_CLIENT_ID,
|
42
44
|
:client_secret => YOUR_CLIENT_SECRET,
|
43
45
|
})
|
44
46
|
|
45
|
-
|
47
|
+
client.authorize_url(:redirect_uri => REDIRECT_URI)
|
46
48
|
# => "https://soundcloud.com/connect?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=http://host/redirect"
|
47
|
-
|
49
|
+
client.exchange_code(:redirect_uri => uri, :code => 'CODE')
|
48
50
|
|
49
|
-
####
|
51
|
+
#### OAuth2 refresh token flow, upload a track and print its link
|
50
52
|
# register a new client which will exchange an existing refresh_token for an access_token
|
51
53
|
client = Soundcloud.new({
|
52
54
|
:client_id => YOUR_CLIENT_ID,
|
@@ -58,7 +60,7 @@ It is providing simple methods to handle authorization and to execute HTTP calls
|
|
58
60
|
track = client.post('/tracks', :track => {
|
59
61
|
:title => 'a new track',
|
60
62
|
:asset_data => File.new('audio.mp3')
|
61
|
-
}
|
63
|
+
})
|
62
64
|
|
63
65
|
# print new tracks link
|
64
66
|
puts track.permalink_url
|
@@ -78,31 +80,31 @@ It is providing simple methods to handle authorization and to execute HTTP calls
|
|
78
80
|
client = Soundcloud.new(:site => 'sandbox-soundcloud.com', :access_token => SOME_ACCESS_TOKEN)
|
79
81
|
|
80
82
|
# create a new following
|
81
|
-
user_id_to_follow =
|
83
|
+
user_id_to_follow = 123
|
82
84
|
client.put("/me/followings/#{user_id_to_follow}")
|
83
85
|
|
84
|
-
##
|
86
|
+
## Interface
|
85
87
|
#### Soundcloud.new(options={})
|
86
|
-
|
88
|
+
Stores the passed options and call exchange_token in case options are passed that allow an exchange of tokens.
|
87
89
|
|
88
90
|
#### Soundcloud#exchange_token(options={})
|
89
|
-
|
91
|
+
Stores the passed options and try to exchange tokens if no access_token is present and:
|
90
92
|
- refresh_token, client_id and client_secret is present.
|
91
93
|
- client_id, client_secret, username, password is present
|
92
94
|
- client_id, client_secret, redirect_uri, code is present
|
93
95
|
|
94
96
|
#### Soundcloud#authorize_url(options={})
|
95
|
-
|
97
|
+
Stores the passed options and return an authorize url.
|
96
98
|
The client_id and redirect_uri options need to present to generate the authorize url.
|
97
99
|
|
98
100
|
#### Soundcloud#get, Soundcloud#post, Soundcloud#put, Soundcloud#delete, Soundcloud#head
|
99
|
-
|
101
|
+
These methods expose all available HTTP methods. They all share the signature (path_or_uri, query={}, options={}).
|
100
102
|
The query hash will be merged with the options hash and passed to httparty. Depending on if the client is authorized it will either add the client_id or the access_token as a query parameter.
|
101
|
-
In case an access_token is expired and a refresh_token is present it will try to refresh the access_token and retry the call.
|
103
|
+
In case an access_token is expired and a refresh_token, client_id and client_secret is present it will try to refresh the access_token and retry the call.
|
102
104
|
The response is either a Hashie::Mash or an array of Hashie::Mashs. The mashs expose all resource attributes as methods and the original response through #response.
|
103
105
|
|
104
106
|
#### Soundcloud#client_id, client_secret, access_token, refresh_token, use_ssl?
|
105
|
-
These are
|
107
|
+
These methods are accessors for the stored options.
|
106
108
|
|
107
109
|
#### Error Handling
|
108
110
|
In case a request was not successful a Soundcloud::ResponseError will be raise.
|
data/lib/soundcloud.rb
CHANGED
@@ -40,6 +40,8 @@ class Soundcloud
|
|
40
40
|
def client_secret; @options[:client_secret]; end
|
41
41
|
def access_token; @options[:access_token]; end
|
42
42
|
def refresh_token; @options[:refresh_token]; end
|
43
|
+
def redirect_uri; @options[:redirect_uri]; end
|
44
|
+
|
43
45
|
def use_ssl?;
|
44
46
|
!! @options[:use_ssl?] || access_token
|
45
47
|
end
|
data/lib/soundcloud/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soundcloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Johannes Wagener
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01
|
18
|
+
date: 2011-02-01 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|