soundcloud 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/lib/soundcloud.rb +16 -3
- data/lib/soundcloud/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -106,6 +106,15 @@ The response is either a Hashie::Mash or an array of Hashie::Mashs. The mashs ex
|
|
106
106
|
#### Soundcloud#client_id, client_secret, access_token, refresh_token, use_ssl?
|
107
107
|
These methods are accessors for the stored options.
|
108
108
|
|
109
|
+
### Soundcloud#on_exchange_token
|
110
|
+
A Proc passed to on_exchange_token will be called each time a token was successfully exchanged or refreshed
|
111
|
+
|
112
|
+
### Soundcloud#expires_at
|
113
|
+
Returns a date based on the expires_in attribute returned from a token exchange.
|
114
|
+
|
115
|
+
### Soundcloud#expired?
|
116
|
+
Will return true or false depending on if expires_at is in the past.
|
117
|
+
|
109
118
|
#### Error Handling
|
110
119
|
In case a request was not successful a Soundcloud::ResponseError will be raise.
|
111
120
|
The original HTTParty response is available through Soundcloud::ResponseError#response.
|
data/lib/soundcloud.rb
CHANGED
@@ -15,7 +15,8 @@ class Soundcloud
|
|
15
15
|
AUTHORIZE_PATH = '/connect'
|
16
16
|
TOKEN_PATH = '/oauth2/token'
|
17
17
|
DEFAULT_OPTIONS = {
|
18
|
-
:site
|
18
|
+
:site => 'soundcloud.com',
|
19
|
+
:on_exchange_token => lambda {}
|
19
20
|
}
|
20
21
|
|
21
22
|
|
@@ -40,7 +41,12 @@ class Soundcloud
|
|
40
41
|
def client_secret; @options[:client_secret]; end
|
41
42
|
def access_token; @options[:access_token]; end
|
42
43
|
def refresh_token; @options[:refresh_token]; end
|
43
|
-
def redirect_uri; @options[:redirect_uri];
|
44
|
+
def redirect_uri; @options[:redirect_uri]; end
|
45
|
+
def expires_at; @options[:expires_at]; end
|
46
|
+
|
47
|
+
def expired?
|
48
|
+
(expires_at.nil? || expires_at < Time.now)
|
49
|
+
end
|
44
50
|
|
45
51
|
def use_ssl?;
|
46
52
|
!! @options[:use_ssl?] || access_token
|
@@ -72,9 +78,15 @@ class Soundcloud
|
|
72
78
|
self.class.post("https://#{api_host}#{TOKEN_PATH}", :query => params)
|
73
79
|
}
|
74
80
|
@options.merge!(:access_token => response.access_token, :refresh_token => response.refresh_token)
|
81
|
+
@options[:expires_at] = Time.now + response.expires_in
|
82
|
+
@options[:on_exchange_token].call
|
75
83
|
response
|
76
84
|
end
|
77
|
-
|
85
|
+
|
86
|
+
def on_exchange_token(&block)
|
87
|
+
store_options(:on_exchange_token => block)
|
88
|
+
end
|
89
|
+
|
78
90
|
private
|
79
91
|
def handle_response(refreshing_enabled=true, &block)
|
80
92
|
response = block.call
|
@@ -101,6 +113,7 @@ private
|
|
101
113
|
@options ||= DEFAULT_OPTIONS.dup
|
102
114
|
@options.merge! options
|
103
115
|
end
|
116
|
+
|
104
117
|
|
105
118
|
def construct_query_arguments(path_or_uri, options={})
|
106
119
|
uri = URI.parse(path_or_uri)
|
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: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
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-02-
|
18
|
+
date: 2011-02-11 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|