rdioid 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +94 -13
- data/lib/rdioid/client.rb +281 -97
- data/lib/rdioid/version.rb +1 -1
- data/rdioid.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1f8b63dcc16df01167fee9c8c07702dbebe3141d
|
|
4
|
+
data.tar.gz: f3993d9d7e610c881e687669c7c01c813d8824e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b578278e0c8c7e4f310c380b7813601386d7609d633017745cac2e1c934bfc05ec1f28767699f1dd052e6e059ecc9c77fa6ab112a580243c38b86f47c3c371a
|
|
7
|
+
data.tar.gz: d23962e4e07e5c2d2314719c001e7b4edf923699242d4883cec594275df94ddb3338aee6eb18d800604eb2e1b3de40303db8068853138ba912b70287a8e4dee0
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Rdioid
|
|
2
2
|
|
|
3
|
-
A simple Ruby Gem wrapper for the Rdio Web
|
|
3
|
+
A simple Ruby Gem wrapper for the Rdio Web Service API with OAuth 2.0. Handles OAuth requests and API requests.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -29,28 +29,109 @@ Rdioid.configure do |config|
|
|
|
29
29
|
end
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
###
|
|
32
|
+
### OAuth 2.0
|
|
33
|
+
Use these methods to request an `access_token`.
|
|
34
|
+
|
|
35
|
+
#### Authorization Code
|
|
33
36
|
```ruby
|
|
34
37
|
Rdioid::Client.authorization_url
|
|
35
|
-
# =>
|
|
38
|
+
# => https://www.rdio.com/oauth2/authorize/?response_type=code&client_id=a1b2c3&redirect_uri=http%3A%2F%test.com%2F
|
|
39
|
+
#
|
|
40
|
+
# redirect User to this URL
|
|
41
|
+
|
|
42
|
+
# GET request to your "redirect_uri" after User has allowed access
|
|
43
|
+
# => http://test.com/?code=ImSLMoN02mqBkO
|
|
44
|
+
|
|
45
|
+
rdioid_client = Rdioid::Client.new
|
|
46
|
+
code = 'ImSLMoN02mqBkO'
|
|
47
|
+
|
|
48
|
+
rdioid_client.request_token_with_authorization_code(code)
|
|
49
|
+
# => { "access_token" => "manFxdW1-WuBd", "token_type" = >"bearer", "expires_in" => 43200, "refresh_token" = >"06l79UCO90G", "scope" => "" }
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Client Credentials
|
|
53
|
+
```ruby
|
|
54
|
+
rdioid_client = Rdioid::Client.new
|
|
55
|
+
|
|
56
|
+
rdioid_client.request_token_with_client_credentials
|
|
57
|
+
# => { "access_token" => "AAAdmanFxdWxlayip", "token_type" => "bearer", "expires_in" => 43200, "scope" => "" }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Device Code
|
|
61
|
+
```ruby
|
|
62
|
+
rdioid_client = Rdioid::Client.new
|
|
63
|
+
|
|
64
|
+
rdioid_client.request_device_code
|
|
65
|
+
# => { "expires_in_s" => 1800, "device_code" => "2479RA", "interval_s" => 5, "verification_url" => "rdio.com/device" }
|
|
66
|
+
#
|
|
67
|
+
# redirect User to "verification_url"
|
|
68
|
+
|
|
69
|
+
code = '2479RA'
|
|
70
|
+
|
|
71
|
+
# poll this method at a rate of "interval_s", waiting for a response without an "error"
|
|
72
|
+
#
|
|
73
|
+
rdioid_client.request_token_with_device_code(code)
|
|
74
|
+
# => { "error_description" => "user has not approved this code yet", "error" => "pending_authorization" }
|
|
75
|
+
|
|
76
|
+
rdioid_client.request_token_with_device_code(code)
|
|
77
|
+
# => { "access_token" => "AAAA3lB6RbI3l8", "token_type" => "bearer", "expires_in" => 43200, "refresh_token" => "AAAFxdWxlbX1z", "scope" => "" }
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Implicit Grant
|
|
81
|
+
```ruby
|
|
82
|
+
Rdioid::Client.authorization_url(:response_type => 'token')
|
|
83
|
+
# => https://www.rdio.com/oauth2/authorize/?response_type=token&client_id=a1b2c3&redirect_uri=http%3A%2F%test.com%2F
|
|
84
|
+
#
|
|
85
|
+
# redirect User to this URL
|
|
86
|
+
|
|
87
|
+
# GET request to your "redirect_uri" after User has allowed access
|
|
88
|
+
# => http://test.com/#access_token=AAAAWMgAAAIB-4ACc6qc&token_type=bearer&expires_in=43199
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Resource Owner Credential
|
|
92
|
+
```ruby
|
|
93
|
+
rdioid_client = Rdioid::Client.new
|
|
94
|
+
username = 'rdioid@test.com'
|
|
95
|
+
password = 'ruby<3'
|
|
96
|
+
|
|
97
|
+
rdioid_client.request_token_with_password(username, password)
|
|
98
|
+
# => { "access_token" => "AAp2Y2dmWxlan", "token_type" => "bearer", "expires_in" => 43200, "refresh_token" => "AAAX1z4mNk84", "scope" => "" }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### Refresh Token
|
|
102
|
+
After an `access_token` has expired, use the received `refresh_token` to request another one.
|
|
36
103
|
|
|
104
|
+
```ruby
|
|
37
105
|
rdioid_client = Rdioid::Client.new
|
|
38
|
-
|
|
39
|
-
|
|
106
|
+
refresh_token = 'AAxlayVmNkMzwlYY64TNB'
|
|
107
|
+
|
|
108
|
+
rdioid_client.request_token_with_refresh_token(refresh_token)
|
|
109
|
+
# => { "access_token" => "AAJ3bXHQWqh5ueD6", "token_type" => "bearer", "expires_in" => 43200, "refresh_token" => "AAAoyYWJ3beClfGsm", "scope" => "" }
|
|
40
110
|
```
|
|
41
111
|
|
|
42
|
-
### API Request
|
|
112
|
+
### Web Service API Request
|
|
113
|
+
Use the `access_token` and provide a `:method` to send a Web Service API request.
|
|
114
|
+
|
|
115
|
+
Available methods: http://www.rdio.com/developers/docs/web-service/methods/
|
|
116
|
+
|
|
43
117
|
```ruby
|
|
44
118
|
rdioid_client = Rdioid::Client.new
|
|
119
|
+
access_token = 'AAWEAAVWMgAAAABVsG3t'
|
|
120
|
+
|
|
121
|
+
rdioid_client.api_request(access_token)
|
|
122
|
+
# => { "status" => "error", "message" => "You must pass a method name as an HTTP POST parameter named \"method\".", "code" => 400 }
|
|
123
|
+
|
|
124
|
+
rdioid_client.api_request(access_token, :method => 'getTopCharts', :type => 'Artist', :count => 3, :extras => '-*,name')
|
|
125
|
+
# => { "status" => "ok", "result" => [{ "name" => "Future" }, { "name" => "Tame Impala" }, { "name" => "Ratatat" }] }
|
|
126
|
+
|
|
127
|
+
rdioid_client.api_request(access_token, :method => 'searchSuggestions', :query => 'Mac', :types => 'Artist', :count => 3, :extras => '-*,name')
|
|
128
|
+
# => { "status" => "ok", "result" => [{ "name" => "Macklemore & Ryan Lewis" }, { "name" => "Mac Miller" }, { "name" => "Macy Gray" }] }
|
|
45
129
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
:query => 'Run_Return',
|
|
49
|
-
:types => 'Artist'
|
|
50
|
-
}
|
|
130
|
+
rdioid_client.api_request(access_token, :method => 'getAlbumsInCollection', :extras => '-*,name')
|
|
131
|
+
# => { "status" => "ok", "result" => [{ "name" => "Adore" }, { "name" => "Against The Grain (Reissue)" }, { "name" => "Agony & Irony" }] }
|
|
51
132
|
|
|
52
|
-
|
|
53
|
-
# => { "
|
|
133
|
+
rdioid_client.api_request(access_token, :method => 'getFavorites')
|
|
134
|
+
# => { "error_description" => "Invalid or expired access token", "error" => "invalid_token" }
|
|
54
135
|
```
|
|
55
136
|
|
|
56
137
|
## Contributing
|
data/lib/rdioid/client.rb
CHANGED
|
@@ -1,101 +1,285 @@
|
|
|
1
1
|
module Rdioid
|
|
2
|
+
# Once *Rdioid* is configured with all required values, *Rdioid::Client* is
|
|
3
|
+
# able to make requests to the <b>Web Service API</b>.
|
|
2
4
|
class Client
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
5
|
+
##
|
|
6
|
+
# Provides the redirect URL for <b>Authorization Code</b> and <b>Implicit Grant</b>.
|
|
7
|
+
#
|
|
8
|
+
# @param options [Hash] additional query string values
|
|
9
|
+
# @option options [String] :response_type ('code') for <b>Authorization Code</b>, or use +'token'+ for <b>Implicit Grant</b>
|
|
10
|
+
# @option options [String] :scope the desired scope you wish to have access to
|
|
11
|
+
# @option options [String] :state a string you provide that will be returned back to you
|
|
12
|
+
#
|
|
13
|
+
# @return [String] escaped URL used for redirection
|
|
14
|
+
#
|
|
15
|
+
# @example Authorization Code
|
|
16
|
+
# Rdioid::Client.authorization_url
|
|
17
|
+
# # => https://www.rdio.com/oauth2/authorize/?response_type=code&client_id=a1b2c3&redirect_uri=http%3A%2F%test.com%2F
|
|
18
|
+
#
|
|
19
|
+
# # GET request to your +redirect_uri+ after User has allowed access
|
|
20
|
+
# # => http://test.com/?code=ImSLMoN02mqBkO
|
|
21
|
+
#
|
|
22
|
+
# # GET request to your +redirect_uri+ after User has denied access
|
|
23
|
+
# # => http://test.com/?error=access_denied
|
|
24
|
+
#
|
|
25
|
+
# @example
|
|
26
|
+
# Rdioid::Client.authorization_url(:state => 'new_user')
|
|
27
|
+
# # => https://www.rdio.com/oauth2/authorize/?response_type=code&client_id=a1b2c3&redirect_uri=http%3A%2F%test.com%2F&state=new_user
|
|
28
|
+
#
|
|
29
|
+
# # GET request to your +redirect_uri+ after User has allowed access
|
|
30
|
+
# # => http://test.com/?state=new_user&code=ImSLMoN02mqBkO
|
|
31
|
+
#
|
|
32
|
+
# # GET request to your +redirect_uri+ after User has denied access
|
|
33
|
+
# # => http://test.com/?state=new_user&error=access_denied
|
|
34
|
+
#
|
|
35
|
+
# @example Implicit Grant
|
|
36
|
+
# Rdioid::Client.authorization_url(:response_type => 'token')
|
|
37
|
+
# # => https://www.rdio.com/oauth2/authorize/?response_type=token&client_id=a1b2c3&redirect_uri=http%3A%2F%test.com%2F
|
|
38
|
+
#
|
|
39
|
+
# # GET request to your +redirect_uri+ after User has allowed access
|
|
40
|
+
# # => http://test.com/#access_token=AAAAWMgAAAIB-4ACc6qc&token_type=bearer&expires_in=43199
|
|
41
|
+
#
|
|
42
|
+
# # GET request to your +redirect_uri+ after User has denied access
|
|
43
|
+
# # => http://test.com/#error=access_denied
|
|
44
|
+
#
|
|
45
|
+
# @example
|
|
46
|
+
# Rdioid::Client.authorization_url(:response_type => 'token', :state => 'new_user')
|
|
47
|
+
# # => https://www.rdio.com/oauth2/authorize/?response_type=token&client_id=a1b2c3&redirect_uri=http%3A%2F%test.com%2F&state=new_user
|
|
48
|
+
#
|
|
49
|
+
# # GET request to your +redirect_uri+ after User has allowed access
|
|
50
|
+
# # => http://test.com/#access_token=AAAAWMgAAAIB-4ACc6qc&token_type=bearer&state=new_user&expires_in=43199
|
|
51
|
+
#
|
|
52
|
+
# # GET request to your +redirect_uri+ after User has denied access
|
|
53
|
+
# # => http://test.com/#state=new_user&error=access_denied
|
|
54
|
+
#
|
|
55
|
+
def self.authorization_url(options = {})
|
|
56
|
+
query = {
|
|
57
|
+
:response_type => 'code',
|
|
58
|
+
:client_id => Rdioid.config.client_id,
|
|
59
|
+
:redirect_uri => Rdioid.config.redirect_uri
|
|
60
|
+
}.merge(options)
|
|
61
|
+
|
|
62
|
+
authorization_query = HTTP::Message.escape_query(query)
|
|
63
|
+
|
|
64
|
+
"#{Rdioid::AUTHORIZATION_URL}?#{authorization_query}"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
##
|
|
68
|
+
# Initializes a new Client for making OAuth and Web Service API requests.
|
|
69
|
+
#
|
|
70
|
+
def initialize
|
|
71
|
+
self.http_client = HTTPClient.new(:base_url => Rdioid::BASE_URL, :force_basic_auth => true)
|
|
72
|
+
|
|
73
|
+
http_client.set_auth(Rdioid::OAUTH_TOKEN_ENDPOINT, Rdioid.config.client_id, Rdioid.config.client_secret)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
##
|
|
77
|
+
# Sends a request to the Web Service API.
|
|
78
|
+
#
|
|
79
|
+
# @param access_token [String] OAuth token required for sending requests to the Web Service API
|
|
80
|
+
# @param body [Hash] values to send in the body of the request
|
|
81
|
+
# @option body [String] :method method for the request: http://www.rdio.com/developers/docs/web-service/methods/
|
|
82
|
+
# @option body [Hash] :* additional *Arguments* unique to each +method+
|
|
83
|
+
#
|
|
84
|
+
# @return [Hash] response from the Web Service API
|
|
85
|
+
#
|
|
86
|
+
# @example
|
|
87
|
+
# rdioid_client = Rdioid::Client.new
|
|
88
|
+
# access_token = 'AAWEAAVWMgAAAABVsG3t'
|
|
89
|
+
#
|
|
90
|
+
# rdioid_client.api_request(access_token)
|
|
91
|
+
# # => { "status" => "error", "message" => "You must pass a method name as an HTTP POST parameter named \"method\".", "code" => 400 }
|
|
92
|
+
#
|
|
93
|
+
# rdioid_client.api_request(access_token, :method => 'getTopCharts', :type => 'Artist', :count => 3, :extras => '-*,name')
|
|
94
|
+
# # => { "status" => "ok", "result" => [{ "name" => "Future" }, { "name" => "Tame Impala" }, { "name" => "Ratatat" }] }
|
|
95
|
+
#
|
|
96
|
+
# rdioid_client.api_request(access_token, :method => 'searchSuggestions', :query => 'Mac', :types => 'Artist', :count => 3, :extras => '-*,name')
|
|
97
|
+
# # => { "status" => "ok", "result" => [{ "name" => "Macklemore & Ryan Lewis" }, { "name" => "Mac Miller" }, { "name" => "Macy Gray" }] }
|
|
98
|
+
#
|
|
99
|
+
# rdioid_client.api_request(access_token, :method => 'getAlbumsInCollection', :extras => '-*,name')
|
|
100
|
+
# # => { "status" => "ok", "result" => [{ "name" => "Adore" }, { "name" => "Against The Grain (Reissue)" }, { "name" => "Agony & Irony" }] }
|
|
101
|
+
#
|
|
102
|
+
# rdioid_client.api_request(access_token, :method => 'getFavorites')
|
|
103
|
+
# # => { "error_description" => "Invalid or expired access token", "error" => "invalid_token" }
|
|
104
|
+
#
|
|
105
|
+
def api_request(access_token, body = {})
|
|
106
|
+
header = {
|
|
107
|
+
:Authorization => "Bearer #{access_token}"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
request(Rdioid::API_ENDPOINT, :header => header, :body => body)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
##
|
|
114
|
+
# Requests an OAuth +device_code+ for the <b>Device Code Grant</b>.
|
|
115
|
+
#
|
|
116
|
+
# @param options [Hash] additional request values
|
|
117
|
+
# @option options [String] :scope the desired scope you wish to have access to
|
|
118
|
+
#
|
|
119
|
+
# @return [Hash] response from the Web Service API
|
|
120
|
+
#
|
|
121
|
+
# @example
|
|
122
|
+
# rdioid_client = Rdioid::Client.new
|
|
123
|
+
#
|
|
124
|
+
# rdioid_client.request_device_code
|
|
125
|
+
# # => { "expires_in_s" => 1800, "device_code" => "2479RA", "interval_s" => 5, "verification_url" => "rdio.com/device" }
|
|
126
|
+
#
|
|
127
|
+
def request_device_code(options = {})
|
|
128
|
+
body = {
|
|
129
|
+
:client_id => Rdioid.config.client_id,
|
|
130
|
+
}.merge(options)
|
|
131
|
+
|
|
132
|
+
request(Rdioid::OAUTH_DEVICE_CODE_ENDPOINT, :body => body)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
##
|
|
136
|
+
# Requests an OAuth +access_token+ using the <b>Authorization Code Grant</b>.
|
|
137
|
+
#
|
|
138
|
+
# @param code [String] OAuth code received from the +.authorization_url+ redirect
|
|
139
|
+
# @param options [Hash] additional request values
|
|
140
|
+
# @option options [String] :scope the desired scope you wish to have access to
|
|
141
|
+
#
|
|
142
|
+
# @return [Hash] response from the Web Service API
|
|
143
|
+
#
|
|
144
|
+
# @example
|
|
145
|
+
# rdioid_client = Rdioid::Client.new
|
|
146
|
+
# code = 'ImSLMoN02mqBkO'
|
|
147
|
+
#
|
|
148
|
+
# rdioid_client.request_token_with_authorization_code(code)
|
|
149
|
+
# # => { "access_token" => "manFxdW1-WuBd", "token_type" = >"bearer", "expires_in" => 43200, "refresh_token" = >"06l79UCO90G", "scope" => "" }
|
|
150
|
+
#
|
|
151
|
+
# rdioid_client.request_token_with_authorization_code(code)
|
|
152
|
+
# # => { "error_description" => "unknown authorization code ImSLMoN02mqBkO", "error" => "invalid_grant" }
|
|
153
|
+
#
|
|
154
|
+
def request_token_with_authorization_code(code, options = {})
|
|
155
|
+
body = {
|
|
156
|
+
:grant_type => 'authorization_code',
|
|
157
|
+
:code => code,
|
|
158
|
+
:redirect_uri => Rdioid.config.redirect_uri
|
|
159
|
+
}.merge(options)
|
|
160
|
+
|
|
161
|
+
request(Rdioid::OAUTH_TOKEN_ENDPOINT, :body => body)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
##
|
|
165
|
+
# Requests an OAuth +access_token+ using the <b>Client Credentials</b>.
|
|
166
|
+
#
|
|
167
|
+
# @param options [Hash] additional request values
|
|
168
|
+
# @option options [String] :scope the desired scope you wish to have access to
|
|
169
|
+
#
|
|
170
|
+
# @return [Hash] response from the Web Service API
|
|
171
|
+
#
|
|
172
|
+
# @example
|
|
173
|
+
# rdioid_client = Rdioid::Client.new
|
|
174
|
+
#
|
|
175
|
+
# rdioid_client.request_token_with_client_credentials
|
|
176
|
+
# # => { "access_token" => "AAAdmanFxdWxlayip", "token_type" => "bearer", "expires_in" => 43200, "scope" => "" }
|
|
177
|
+
#
|
|
178
|
+
def request_token_with_client_credentials(options = {})
|
|
179
|
+
body = {
|
|
180
|
+
:grant_type => 'client_credentials'
|
|
181
|
+
}.merge(options)
|
|
182
|
+
|
|
183
|
+
request(Rdioid::OAUTH_TOKEN_ENDPOINT, :body => body)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
##
|
|
187
|
+
# Requests an OAuth +access_token+ using the <b>Device Code Grant</b>.
|
|
188
|
+
#
|
|
189
|
+
# @param device_code [String] +device_code+ received from calling +#request_device_code+
|
|
190
|
+
# @param options [Hash] additional request values
|
|
191
|
+
# @option options [String] :scope the desired scope you wish to have access to
|
|
192
|
+
#
|
|
193
|
+
# @return [Hash] response from the Web Service API
|
|
194
|
+
#
|
|
195
|
+
# @example
|
|
196
|
+
# rdioid_client = Rdioid::Client.new
|
|
197
|
+
# device_code = 'BX55E2'
|
|
198
|
+
#
|
|
199
|
+
# rdioid_client.request_token_with_device_code(device_code)
|
|
200
|
+
# # => { "error_description" => "user has not approved this code yet", "error" => "pending_authorization" }
|
|
201
|
+
#
|
|
202
|
+
# rdioid_client.request_token_with_device_code(device_code)
|
|
203
|
+
# # => { "access_token" => "AAAA3lB6RbI3l8", "token_type" => "bearer", "expires_in" => 43200, "refresh_token" => "AAAFxdWxlbX1z", "scope" => "" }
|
|
204
|
+
#
|
|
205
|
+
# rdioid_client.request_token_with_device_code(device_code)
|
|
206
|
+
# # => { "error_description" => "no entry found for given device_code", "error" => "invalid_request" }
|
|
207
|
+
#
|
|
208
|
+
def request_token_with_device_code(device_code, options = {})
|
|
209
|
+
body = {
|
|
210
|
+
:grant_type => 'device_code',
|
|
211
|
+
:device_code => device_code
|
|
212
|
+
}.merge(options)
|
|
213
|
+
|
|
214
|
+
request(Rdioid::OAUTH_TOKEN_ENDPOINT, :body => body)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
##
|
|
218
|
+
# Requests an OAuth +access_token+ using the <b>Resource Owner Credential</b>.
|
|
219
|
+
#
|
|
220
|
+
# @param username [String] email address for the User
|
|
221
|
+
# @param password [String] password for the User
|
|
222
|
+
# @param options [Hash] additional request values
|
|
223
|
+
# @option options [String] :scope the desired scope you wish to have access to
|
|
224
|
+
#
|
|
225
|
+
# @return [Hash] response from the Web Service API
|
|
226
|
+
#
|
|
227
|
+
# @example
|
|
228
|
+
# rdioid_client = Rdioid::Client.new
|
|
229
|
+
# username = 'rdioid@test.com'
|
|
230
|
+
# password = 'ruby<3'
|
|
231
|
+
#
|
|
232
|
+
# rdioid_client.request_token_with_password(username, password)
|
|
233
|
+
# # => { "access_token" => "AAp2Y2dmWxlan", "token_type" => "bearer", "expires_in" => 43200, "refresh_token" => "AAAX1z4mNk84", "scope" => "" }
|
|
234
|
+
#
|
|
235
|
+
# rdioid_client.request_token_with_password(username, password)
|
|
236
|
+
# # => { "error_description" => "This client is not authorized to use the password grant", "error" => "unauthorized_client" }
|
|
237
|
+
#
|
|
238
|
+
def request_token_with_password(username, password, options = {})
|
|
239
|
+
body = {
|
|
240
|
+
:grant_type => 'password',
|
|
241
|
+
:username => username,
|
|
242
|
+
:password => password
|
|
243
|
+
}.merge(options)
|
|
244
|
+
|
|
245
|
+
request(Rdioid::OAUTH_TOKEN_ENDPOINT, :body => body)
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
##
|
|
249
|
+
# Requests an OAuth +access_token+ using the <b>Refresh Token</b>.
|
|
250
|
+
#
|
|
251
|
+
# @param refresh_token [String] refresh token previously issued during an +access_token+ request
|
|
252
|
+
# @param options [Hash] additional request values
|
|
253
|
+
# @option options [String] :scope the desired scope you wish to have access to
|
|
254
|
+
#
|
|
255
|
+
# @return [Hash] response from the Web Service API
|
|
256
|
+
#
|
|
257
|
+
# @example
|
|
258
|
+
# rdioid_client = Rdioid::Client.new
|
|
259
|
+
# refresh_token = 'AAxlayVmNkMzwlYY64TNB'
|
|
260
|
+
#
|
|
261
|
+
# rdioid_client.request_token_with_refresh_token(refresh_token)
|
|
262
|
+
# # => { "access_token" => "AAJ3bXHQWqh5ueD6", "token_type" => "bearer", "expires_in" => 43200, "refresh_token" => "AAAoyYWJ3beClfGsm", "scope" => "" }
|
|
263
|
+
#
|
|
264
|
+
# rdioid_client.request_token_with_refresh_token(refresh_token)
|
|
265
|
+
# # => { "error_description" => "invalid refresh token", "error" => "invalid_grant" }
|
|
266
|
+
#
|
|
267
|
+
def request_token_with_refresh_token(refresh_token, options = {})
|
|
268
|
+
body = {
|
|
269
|
+
:grant_type => 'refresh_token',
|
|
270
|
+
:refresh_token => refresh_token
|
|
271
|
+
}.merge(options)
|
|
272
|
+
|
|
273
|
+
request(Rdioid::OAUTH_TOKEN_ENDPOINT, :body => body)
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
private
|
|
277
|
+
attr_accessor :http_client
|
|
278
|
+
|
|
279
|
+
def request(endpoint, options = {})
|
|
280
|
+
response = http_client.post(endpoint, options)
|
|
281
|
+
|
|
282
|
+
JSON.parse(response.body)
|
|
283
|
+
end
|
|
100
284
|
end
|
|
101
285
|
end
|
data/lib/rdioid/version.rb
CHANGED
data/rdioid.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.email = ["reddshack@gmail.com"]
|
|
11
11
|
|
|
12
12
|
spec.summary = %q{Simple Rdio Web Services API wrapper with OAuth 2.0}
|
|
13
|
-
spec.description = %q{Handles OAuth authentication and API calls for Rdio Web Services API.}
|
|
13
|
+
spec.description = %q{Handles OAuth 2.0 authentication and API calls for Rdio Web Services API.}
|
|
14
14
|
spec.homepage = "https://github.com/reddshack/rdioid"
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rdioid
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brent Redd
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-07-
|
|
11
|
+
date: 2015-07-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httpclient
|
|
@@ -66,7 +66,8 @@ dependencies:
|
|
|
66
66
|
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '0'
|
|
69
|
-
description: Handles OAuth authentication and API calls for Rdio Web Services
|
|
69
|
+
description: Handles OAuth 2.0 authentication and API calls for Rdio Web Services
|
|
70
|
+
API.
|
|
70
71
|
email:
|
|
71
72
|
- reddshack@gmail.com
|
|
72
73
|
executables: []
|
|
@@ -112,3 +113,4 @@ signing_key:
|
|
|
112
113
|
specification_version: 4
|
|
113
114
|
summary: Simple Rdio Web Services API wrapper with OAuth 2.0
|
|
114
115
|
test_files: []
|
|
116
|
+
has_rdoc:
|