rdioid 0.0.1
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rdioid/client.rb +101 -0
- data/lib/rdioid/config.rb +11 -0
- data/lib/rdioid/version.rb +3 -0
- data/lib/rdioid.rb +23 -0
- data/rdioid.gemspec +27 -0
- metadata +114 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: dd5abcbdd6d06aecfc6b7753adf1e98257ebc9f0
|
|
4
|
+
data.tar.gz: 626af7c0ec328b43bffae95f0be1f6663b0aae9c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f3680cf4f7596175ad30deef58e9eabb6d5a7124a0ca259685c8e60fb8efdb7af8cd406de0d44003e3ab9ab17efcc1bae85d2fbb0c704a16734f1a08114ea7d8
|
|
7
|
+
data.tar.gz: b8be35e3fb36bacfd148f453a44c651bd4625624bd63bc9fc317f9bf03a06f8776752f36367db46ee1102a77195829a68e4afa7cdca9b4dd596cc242f0271e7e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Brent Redd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Rdioid
|
|
2
|
+
|
|
3
|
+
A simple Ruby Gem wrapper for the Rdio Web Services API with OAuth 2.0. Handles OAuth authtentication and API calls.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'rdioid'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install rdioid
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Config
|
|
24
|
+
```ruby
|
|
25
|
+
Rdioid.configure do |config|
|
|
26
|
+
config.client_id = 'your_client_id'
|
|
27
|
+
config.client_secret = 'your_client_secret'
|
|
28
|
+
config.redirect_uri = 'http://your_redirect_uri/'
|
|
29
|
+
end
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Oauth
|
|
33
|
+
```ruby
|
|
34
|
+
Rdioid::Client.authorization_url
|
|
35
|
+
# => "https://www.rdio.com/oauth2/authorize/?response_type=code&client_id=your_client_id&redirect_uri=http%3A%2F%2Fyour_redirect_uri%2F"
|
|
36
|
+
|
|
37
|
+
rdioid_client = Rdioid::Client.new
|
|
38
|
+
rdioid_client.request_token_with_authorization_code('authorization_code')
|
|
39
|
+
# => { "access_token" => "...", "token_type" => "bearer", "expires_in" => 43200, "refresh_token" => "...", "scope" => "" }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### API Request
|
|
43
|
+
```ruby
|
|
44
|
+
rdioid_client = Rdioid::Client.new
|
|
45
|
+
|
|
46
|
+
body = {
|
|
47
|
+
:method => 'searchSuggestions',
|
|
48
|
+
:query => 'Run_Return',
|
|
49
|
+
:types => 'Artist'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
rdio_client.api_request('access_token', body)
|
|
53
|
+
# => { "status" => "ok", "result" => [{ "name" => "Run_Return", "key" => "r400361" }] }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Contributing
|
|
57
|
+
|
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/reddshack/rdioid.
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "rdioid"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
module Rdioid
|
|
2
|
+
class Client
|
|
3
|
+
##
|
|
4
|
+
# Class methods
|
|
5
|
+
#
|
|
6
|
+
def self.authorization_url(options = {})
|
|
7
|
+
query = {
|
|
8
|
+
:response_type => 'code', # use 'token' for Implicit Grant
|
|
9
|
+
:client_id => Rdioid.config.client_id,
|
|
10
|
+
:redirect_uri => Rdioid.config.redirect_uri
|
|
11
|
+
}.merge(options)
|
|
12
|
+
|
|
13
|
+
authorization_query = HTTP::Message.escape_query(query)
|
|
14
|
+
|
|
15
|
+
"#{Rdioid::AUTHORIZATION_URL}?#{authorization_query}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
# Constructor
|
|
20
|
+
#
|
|
21
|
+
def initialize
|
|
22
|
+
self.http_client = HTTPClient.new(:base_url => Rdioid::BASE_URL, :force_basic_auth => true)
|
|
23
|
+
|
|
24
|
+
http_client.set_auth(Rdioid::OAUTH_TOKEN_ENDPOINT, Rdioid.config.client_id, Rdioid.config.client_secret)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
# Instance Methods
|
|
29
|
+
#
|
|
30
|
+
def api_request(access_token, body = {})
|
|
31
|
+
header = {
|
|
32
|
+
:Authorization => "Bearer #{access_token}"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
request(Rdioid::API_ENDPOINT, :header => header, :body => body)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def request_device_code(options = {})
|
|
39
|
+
body = {
|
|
40
|
+
:client_id => Rdioid.config.client_id,
|
|
41
|
+
}.merge(options)
|
|
42
|
+
|
|
43
|
+
request(Rdioid::OAUTH_DEVICE_CODE_ENDPOINT, :body => body)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def request_token_with_authorization_code(code, options = {})
|
|
47
|
+
body = {
|
|
48
|
+
:grant_type => 'authorization_code',
|
|
49
|
+
:code => code,
|
|
50
|
+
:redirect_uri => Rdioid.config.redirect_uri
|
|
51
|
+
}.merge(options)
|
|
52
|
+
|
|
53
|
+
request(Rdioid::OAUTH_TOKEN_ENDPOINT, :body => body)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def request_token_with_client_credentials(options = {})
|
|
57
|
+
body = {
|
|
58
|
+
:grant_type => 'client_credentials'
|
|
59
|
+
}.merge(options)
|
|
60
|
+
|
|
61
|
+
request(Rdioid::OAUTH_TOKEN_ENDPOINT, :body => body)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def request_token_with_device_code(device_code, options = {})
|
|
65
|
+
body = {
|
|
66
|
+
:grant_type => 'device_code',
|
|
67
|
+
:device_code => device_code
|
|
68
|
+
}.merge(options)
|
|
69
|
+
|
|
70
|
+
request(Rdioid::OAUTH_TOKEN_ENDPOINT, :body => body)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def request_token_with_password(username, password, options = {})
|
|
74
|
+
body = {
|
|
75
|
+
:grant_type => 'password',
|
|
76
|
+
:username => username,
|
|
77
|
+
:password => password
|
|
78
|
+
}.merge(options)
|
|
79
|
+
|
|
80
|
+
request(Rdioid::OAUTH_TOKEN_ENDPOINT, :body => body)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def request_token_with_refresh_token(refresh_token, options = {})
|
|
84
|
+
body = {
|
|
85
|
+
:grant_type => 'refresh_token',
|
|
86
|
+
:refresh_token => refresh_token
|
|
87
|
+
}.merge(options)
|
|
88
|
+
|
|
89
|
+
request(Rdioid::OAUTH_TOKEN_ENDPOINT, :body => body)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
private
|
|
93
|
+
attr_accessor :http_client
|
|
94
|
+
|
|
95
|
+
def request(endpoint, options = {})
|
|
96
|
+
response = http_client.post(endpoint, options)
|
|
97
|
+
|
|
98
|
+
JSON.parse(response.body)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
data/lib/rdioid.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "httpclient"
|
|
2
|
+
require "json"
|
|
3
|
+
|
|
4
|
+
require "rdioid/client"
|
|
5
|
+
require "rdioid/config"
|
|
6
|
+
require "rdioid/version"
|
|
7
|
+
|
|
8
|
+
module Rdioid
|
|
9
|
+
AUTHORIZATION_URL = 'https://www.rdio.com/oauth2/authorize/'
|
|
10
|
+
BASE_URL = 'https://services.rdio.com/'
|
|
11
|
+
API_ENDPOINT = 'api/1/'
|
|
12
|
+
OAUTH_TOKEN_ENDPOINT = 'oauth2/token/'
|
|
13
|
+
OAUTH_DEVICE_CODE_ENDPOINT = 'oauth2/device/code/generate/'
|
|
14
|
+
|
|
15
|
+
class << self
|
|
16
|
+
attr_accessor :config
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.configure
|
|
20
|
+
self.config ||= Rdioid::Config.new
|
|
21
|
+
yield(config)
|
|
22
|
+
end
|
|
23
|
+
end
|
data/rdioid.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'rdioid/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "rdioid"
|
|
8
|
+
spec.version = Rdioid::VERSION
|
|
9
|
+
spec.authors = ["Brent Redd"]
|
|
10
|
+
spec.email = ["reddshack@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Simple Rdio Web Services API wrapper with OAuth 2.0}
|
|
13
|
+
spec.description = %q{Handles OAuth authtentication and API calls for Rdio Web Services API.}
|
|
14
|
+
spec.homepage = "https://github.com/reddshack/rdioid"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.bindir = "exe"
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_dependency "httpclient", "~> 2.6.0"
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rspec"
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rdioid
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Brent Redd
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httpclient
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 2.6.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 2.6.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.10'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.10'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: Handles OAuth authtentication and API calls for Rdio Web Services API.
|
|
70
|
+
email:
|
|
71
|
+
- reddshack@gmail.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".travis.yml"
|
|
79
|
+
- Gemfile
|
|
80
|
+
- LICENSE.txt
|
|
81
|
+
- README.md
|
|
82
|
+
- Rakefile
|
|
83
|
+
- bin/console
|
|
84
|
+
- bin/setup
|
|
85
|
+
- lib/rdioid.rb
|
|
86
|
+
- lib/rdioid/client.rb
|
|
87
|
+
- lib/rdioid/config.rb
|
|
88
|
+
- lib/rdioid/version.rb
|
|
89
|
+
- rdioid.gemspec
|
|
90
|
+
homepage: https://github.com/reddshack/rdioid
|
|
91
|
+
licenses:
|
|
92
|
+
- MIT
|
|
93
|
+
metadata: {}
|
|
94
|
+
post_install_message:
|
|
95
|
+
rdoc_options: []
|
|
96
|
+
require_paths:
|
|
97
|
+
- lib
|
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
requirements: []
|
|
109
|
+
rubyforge_project:
|
|
110
|
+
rubygems_version: 2.4.8
|
|
111
|
+
signing_key:
|
|
112
|
+
specification_version: 4
|
|
113
|
+
summary: Simple Rdio Web Services API wrapper with OAuth 2.0
|
|
114
|
+
test_files: []
|