rhapsody 0.0.11 → 0.1.0

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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MmZlNjMwZmM3NWMwZGY4YmQ1NjFmYzE3MzYxY2FiZGI0YmMwNzRkMA==
5
- data.tar.gz: !binary |-
6
- YjFhOGM1NDg2MmEyYWZkZTYyMWRlYWNhYWQwNWNkYWFhNWZlY2NlZA==
2
+ SHA1:
3
+ metadata.gz: 6b7471c6ad267c63056f9ee20e4fe2e531714ba1
4
+ data.tar.gz: f61e059843f25d80ed6f130fa8548b88bb3f2a3b
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- OTdhZDQyNWJiMTI0ZWYxYjkwODI5MmIxNGEzOTVjZTUyMTkxZGFjOGMxZDA4
10
- NDI4MDNjZjEzNzhmNWY1NDY0MDIyMjdjZGRhYWIzMGZiYTdkZGIxMzRkMDhh
11
- MjA4MTk3MDEyN2M3N2JmNjcyMzRiMWI3Yzc3ZGVkMjhkZTc0N2U=
12
- data.tar.gz: !binary |-
13
- ODVhYTRiMGVhY2Y2OTAwNzc0MGQ0ZWQxMjQ3ZjFkZWIxMTYxMTNlZjM4Yzhi
14
- ZGI4ZWQwODM4MzMzZDAzMzViNTU2ODRjNGE4NTkzMDhkYjUxMzcwMTdiMGRk
15
- OGM2NzA2NTdhOTJhY2ViOTUzMmI3ZjFlYWY4NzRmMzgxOWY5ZDA=
6
+ metadata.gz: 69d51b4dbba1fd8726cad231a46a75a736bc25a0893b4a2e99eed33bf3dca3b521c7e7b84825b0665d96d6f10f38e16a57c44e60e1a6a5f142c1e587f22544ad
7
+ data.tar.gz: 3256714251d7b03247a19b94101dd4279a71d587023b51706f8782db30f5f4c4415619ff01c05a0ab05c37b3d4f064ec0c53f3855b8d5d74742d286490f108d0
data/.gitignore CHANGED
@@ -1,25 +1,12 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
23
10
 
24
11
  # custom
25
12
  spec/config.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile CHANGED
@@ -1,13 +1,19 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in rhapsody.gemspec
4
3
  gemspec
5
4
 
5
+ # HTTP client lib
6
6
  gem 'faraday', '~> 0.9.1'
7
7
 
8
- group :test, :development do
9
- gem 'rspec', '~> 3.2.0'
10
- gem 'factory_girl', '~> 4.5.0'
11
- gem 'debugger', '~> 1.6.8'
12
- gem 'pry', '~> 0.10.0'
8
+ # JSON parsing
9
+ gem 'oj', '~> 2.12.9'
10
+
11
+ group :development do
12
+ gem 'byebug', '~> 5.0.0'
13
+ end
14
+
15
+ group :test do
16
+ gem 'rspec', '~> 3.3.0'
17
+ gem 'capybara', '~> 2.4.4'
18
+ gem 'selenium-webdriver', '~> 2.46.2'
13
19
  end
@@ -1,22 +1,21 @@
1
- Copyright (c) 2014 Jason Kim
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2015 Jason Kim
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
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:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 CHANGED
@@ -1,14 +1,14 @@
1
- # Rhapsody gem
1
+ # Rhapsody Gem
2
2
 
3
- **Still under development**
4
-
5
- Rhapsody gem provides a Ruby object-oriented interface for Rhapsody API.
3
+ A Ruby interface to the Rhapsody API.
6
4
 
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
- gem 'rhapsody'
9
+ ```ruby
10
+ gem 'rhapsody'
11
+ ```
12
12
 
13
13
  And then execute:
14
14
 
@@ -30,16 +30,53 @@ Here is an example code for setting up a client using
30
30
  require 'rhapsody'
31
31
 
32
32
  options = {
33
- api_key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
34
- api_secret: 'yyyyyyyyyyyy',
35
- auth_code: 'zzzzzzzzzz',
36
- redirect_url: 'http://example.com/rhapsody/auth'
33
+ api_key: 'API_KEY',
34
+ api_secret: 'API_SECRET',
37
35
  }
38
36
 
39
37
  client = Rhapsody::Client.new(options)
38
+ ```
39
+
40
+ ### Getting an access token
41
+
42
+ #### Password grant
43
+
44
+ ```ruby
45
+ client_hash = {
46
+ api_key: 'API_KEY',
47
+ api_secret: 'API_SECRET',
48
+ username: 'USERNAME',
49
+ password: 'PASSWORD'
50
+ }
51
+
52
+ client = Rhapsody::Client.new(client_hash)
53
+ client.password_grant
54
+
55
+ client.authentication.access_token # => returns access_token
56
+ client.authentication.refresh_token
57
+ client.authentication.expires_in
58
+ ```
59
+
60
+ #### OAuth 2
61
+
62
+ ```ruby
63
+ client_hash = {
64
+ api_key: 'API_KEY',
65
+ api_secret: 'API_SECRET',
66
+ redirect_uri: 'REDIRECT_URI',
67
+ auth_code: 'AUTH_CODE'
68
+ }
69
+
70
+ client = Rhapsody::Client.new(client_hash)
40
71
  client.connect
72
+
73
+ client.authentication.access_token # => returns access_token
74
+ client.authentication.refresh_token
75
+ client.authentication.expires_in
41
76
  ```
42
77
 
78
+ ## Development
79
+
43
80
  ### Running tests
44
81
 
45
82
  Rhapsody gem uses RSpec and FactoryGirl.
@@ -53,8 +90,11 @@ Rhapsody gem uses RSpec and FactoryGirl.
53
90
 
54
91
  ``` yml
55
92
  config_variables:
56
- API_KEY: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
57
- API_SECRET: "yyyyyyyyyyyy"
93
+ API_KEY: 'API_KEY'
94
+ API_SECRET: 'API_SECRET'
95
+ USERNAME: 'USERNAME'
96
+ PASSWORD: 'PASSWORD'
97
+ REDIRECT_URI: 'REDIRECT_URI'
58
98
  ```
59
99
 
60
100
  4. `$ bundle install`
@@ -63,8 +103,8 @@ config_variables:
63
103
 
64
104
  ## Contributing
65
105
 
66
- 1. Fork it ( https://github.com/[my-github-username]/rhapsody/fork )
67
- 2. Create your feature branch (`git checkout -b my-new-feature`)
68
- 3. Commit your changes (`git commit -am 'Add some feature'`)
69
- 4. Push to the branch (`git push origin my-new-feature`)
70
- 5. Create a new Pull Request
106
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rhapsody.
107
+
108
+ ## License
109
+
110
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rhapsody"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -1,12 +1,4 @@
1
- require "rhapsody/version"
2
-
3
- require 'rhapsody/helpers/faraday_connection'
4
-
5
- require 'rhapsody/controllers/clients_controller'
6
- require 'rhapsody/controllers/members_controller'
7
-
8
- require 'rhapsody/models/member'
9
-
10
- module Rhapsody
11
- HOST_URL = 'https://api.rhapsody.com'
12
- end
1
+ require 'rhapsody/authentication'
2
+ require 'rhapsody/client'
3
+ require 'rhapsody/request'
4
+ require 'rhapsody/version'
@@ -0,0 +1,78 @@
1
+ class Rhapsody::Authentication
2
+ attr_accessor :client,
3
+ :access_token,
4
+ :refresh_token,
5
+ :expires_in
6
+
7
+ def initialize(options)
8
+ options.each do |name, value|
9
+ instance_variable_set("@#{name}", value)
10
+ end
11
+ end
12
+
13
+ def password_grant
14
+ request_hash = {
15
+ api_key: @client.api_key,
16
+ api_secret: @client.api_secret
17
+ }
18
+ request = Rhapsody::Request.new(request_hash)
19
+
20
+ post_hash = {
21
+ response_type: 'code',
22
+ grant_type: 'password',
23
+ username: @client.username,
24
+ password: @client.password
25
+ }
26
+ raw_response = request.faraday.post('/oauth/token', post_hash)
27
+ body = Oj.load(raw_response.body)
28
+
29
+ @access_token = body['access_token']
30
+ @refresh_token = body['refresh_token']
31
+ @expires_in = body['expires_in'].to_i
32
+
33
+ self
34
+ end
35
+
36
+ def connect
37
+ request = Rhapsody::Request.new({})
38
+
39
+ post_hash = {
40
+ client_id: @client.api_key,
41
+ client_secret: @client.api_secret,
42
+ response_type: 'code',
43
+ grant_type: 'authorization_code',
44
+ code: @client.auth_code,
45
+ redirect_uri: @client.redirect_uri
46
+ }
47
+
48
+ raw_response = request.faraday.post('oauth/access_token', post_hash)
49
+ body = Oj.load(raw_response.body)
50
+
51
+ @access_token = body['access_token']
52
+ @refresh_token = body['refresh_token']
53
+ @expires_in = body['expires_in'].to_i
54
+
55
+ self
56
+ end
57
+
58
+ def renew
59
+ request = Rhapsody::Request.new({})
60
+
61
+ post_hash = {
62
+ client_id: @client.api_key,
63
+ client_secret: @client.api_secret,
64
+ response_type: 'code',
65
+ grant_type: 'refresh_token',
66
+ refresh_token: @refresh_token
67
+ }
68
+
69
+ raw_response = request.faraday.post('oauth/access_token', post_hash)
70
+ body = Oj.load(raw_response.body)
71
+
72
+ @access_token = body['access_token']
73
+ @refresh_token = body['refresh_token']
74
+ @expires_in = body['expires_in'].to_i
75
+
76
+ self
77
+ end
78
+ end
@@ -0,0 +1,37 @@
1
+ class Rhapsody::Client
2
+ attr_accessor :api_key,
3
+ :api_secret,
4
+ :redirect_uri,
5
+ :username,
6
+ :password,
7
+ :auth_code,
8
+ :authentication
9
+
10
+ def initialize(options)
11
+ # TODO: verify options
12
+ options.each do |name, value|
13
+ instance_variable_set("@#{name}", value)
14
+ end
15
+ end
16
+
17
+ def password_grant
18
+ @authentication = Rhapsody::Authentication.new({ client: self })
19
+ @authentication.password_grant
20
+ end
21
+
22
+ def authorization_url
23
+ Rhapsody::Request::HOST_URL + "/oauth/authorize?client_id=#{@api_key}&redirect_uri=#{@redirect_uri}&response_type=code"
24
+ end
25
+
26
+ def connect
27
+ @authentication = Rhapsody::Authentication.new({ client: self })
28
+ @authentication.connect
29
+ end
30
+
31
+ def renew
32
+ if @authentication
33
+ @authentication.renew
34
+ end
35
+ # TODO Need to handle, authentication
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ require 'faraday'
2
+
3
+ class Rhapsody::Request
4
+ HOST_URL = 'https://api.rhapsody.com'
5
+
6
+ attr_accessor :faraday
7
+
8
+ def initialize(options)
9
+ @faraday = Faraday.new(:url => HOST_URL) do |faraday|
10
+ faraday.request :url_encoded
11
+ faraday.adapter Faraday.default_adapter
12
+
13
+ if options[:access_token]
14
+ faraday.authorization :Bearer, options[:access_token]
15
+ end
16
+
17
+ if options[:api_key] && options[:api_secret]
18
+ faraday.basic_auth(options[:api_key], options[:api_secret])
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Rhapsody
2
- VERSION = "0.0.11"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,16 +8,18 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Rhapsody::VERSION
9
9
  spec.authors = ["Jason Kim"]
10
10
  spec.email = ["jasonkim@rhapsody.com"]
11
- spec.summary = %q{NOT READY: A Ruby object-oriented interface to the Rhapsody REST API}
12
- spec.description = %q{Rhapsody REST API gem provides a Ruby object-oriented interface.}
11
+
12
+ spec.summary = %q{A Ruby interface to the Rhapsody API.}
13
+ spec.description = %q{A Ruby interface to the Rhapsody API.}
13
14
  spec.homepage = "https://github.com/serv/rhapsody"
14
15
  spec.license = "MIT"
15
16
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
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) }
19
20
  spec.require_paths = ["lib"]
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
23
25
  end
metadata CHANGED
@@ -1,71 +1,79 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhapsody
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Kim
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '1.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ! '>='
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
- description: Rhapsody REST API gem provides a Ruby object-oriented interface.
55
+ description: A Ruby interface to the Rhapsody API.
42
56
  email:
43
57
  - jasonkim@rhapsody.com
44
58
  executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
- - .gitignore
62
+ - ".gitignore"
63
+ - ".rspec"
49
64
  - Gemfile
50
65
  - Gemfile.lock
51
66
  - LICENSE.txt
52
67
  - README.md
53
68
  - Rakefile
69
+ - bin/console
70
+ - bin/setup
54
71
  - lib/rhapsody.rb
55
- - lib/rhapsody/controllers/clients_controller.rb
56
- - lib/rhapsody/controllers/members_controller.rb
57
- - lib/rhapsody/helpers/faraday_connection.rb
58
- - lib/rhapsody/models/member.rb
72
+ - lib/rhapsody/authentication.rb
73
+ - lib/rhapsody/client.rb
74
+ - lib/rhapsody/request.rb
59
75
  - lib/rhapsody/version.rb
60
76
  - rhapsody.gemspec
61
- - spec/config_helper.rb
62
- - spec/helpers/authentication_helper.rb
63
- - spec/rhapsody/controllers/clients_controller_spec.rb
64
- - spec/rhapsody/controllers/members_controller_spec.rb
65
- - spec/rhapsody/helpers/faraday_connection_spec.rb
66
- - spec/rhapsody/models/member_spec.rb
67
- - spec/rhapsody/rhapsody_spec.rb
68
- - spec/spec_helper.rb
69
77
  homepage: https://github.com/serv/rhapsody
70
78
  licenses:
71
79
  - MIT
@@ -76,12 +84,12 @@ require_paths:
76
84
  - lib
77
85
  required_ruby_version: !ruby/object:Gem::Requirement
78
86
  requirements:
79
- - - ! '>='
87
+ - - ">="
80
88
  - !ruby/object:Gem::Version
81
89
  version: '0'
82
90
  required_rubygems_version: !ruby/object:Gem::Requirement
83
91
  requirements:
84
- - - ! '>='
92
+ - - ">="
85
93
  - !ruby/object:Gem::Version
86
94
  version: '0'
87
95
  requirements: []
@@ -89,14 +97,5 @@ rubyforge_project:
89
97
  rubygems_version: 2.4.6
90
98
  signing_key:
91
99
  specification_version: 4
92
- summary: ! 'NOT READY: A Ruby object-oriented interface to the Rhapsody REST API'
93
- test_files:
94
- - spec/config_helper.rb
95
- - spec/helpers/authentication_helper.rb
96
- - spec/rhapsody/controllers/clients_controller_spec.rb
97
- - spec/rhapsody/controllers/members_controller_spec.rb
98
- - spec/rhapsody/helpers/faraday_connection_spec.rb
99
- - spec/rhapsody/models/member_spec.rb
100
- - spec/rhapsody/rhapsody_spec.rb
101
- - spec/spec_helper.rb
102
- has_rdoc:
100
+ summary: A Ruby interface to the Rhapsody API.
101
+ test_files: []
@@ -1,69 +0,0 @@
1
- class Rhapsody::ClientsController
2
- attr_accessor :api_key,
3
- :api_secret,
4
- :auth_code,
5
- :redirect_url,
6
- :raw_reponse,
7
- :json_response,
8
- :response_status,
9
- :access_token,
10
- :refresh_token,
11
- :expires_in
12
-
13
- OAUTH_PATH = '/oauth/access_token'
14
-
15
- def initialize(options)
16
- options.each do |name, value|
17
- instance_variable_set("@#{name}", value)
18
- end
19
- end
20
-
21
- def connect
22
- connection = Rhapsody::FaradayConnection.prepare_authentication
23
-
24
- post_hash = {
25
- client_id: @api_key,
26
- client_secret: @api_secret,
27
- response_type: 'code',
28
- grant_type: 'authorization_code',
29
- code: @auth_code,
30
- redirect_uri: @redirect_url
31
- }
32
-
33
- @raw_response = connection.post(OAUTH_PATH, post_hash)
34
- @json_response = JSON.parse(@raw_response.env[:body])
35
- @response_status = @raw_response.env[:status]
36
-
37
- @access_token = @json_response['access_token']
38
- @refresh_token = @json_response['refresh_token']
39
- @expires_in = @json_response['expires_in']
40
- self
41
- end
42
-
43
- def renew
44
- connection = Rhapsody::FaradayConnection.prepare_authentication
45
-
46
- post_hash = {
47
- client_id: @api_key,
48
- client_secret: @api_secret,
49
- response_type: 'code',
50
- grant_type: 'refresh_token',
51
- refresh_token: @refresh_token
52
- }
53
-
54
- @raw_response = connection.post(OAUTH_PATH, post_hash)
55
- @json_response = JSON.parse(@raw_response.env[:body])
56
- @response_status = @raw_response.env[:status]
57
-
58
- @access_token = @json_response['access_token']
59
- @refresh_token = @json_response['refresh_token']
60
- @expires_in = @json_response['expires_in']
61
- self
62
- end
63
-
64
- def me_account
65
- options = { access_token: @access_token }
66
- members_controller = Rhapsody::MembersController.new(options)
67
- member = members_controller.account
68
- end
69
- end
@@ -1,23 +0,0 @@
1
- class Rhapsody::MembersController
2
- attr_accessor :path,
3
- :access_token,
4
- :raw_reponse,
5
- :json_response,
6
- :response_status
7
-
8
- PARENT_PATH = '/v1/me'
9
-
10
- def initialize(options)
11
- @access_token = options[:access_token]
12
- end
13
-
14
- # /me/account
15
- def account
16
- @path = PARENT_PATH + '/account'
17
- connection = Rhapsody::FaradayConnection.prepare_authorization(access_token)
18
- @raw_response = connection.get(@path)
19
- @json_response = JSON.parse(@raw_response.env[:body])
20
- @response_status = @raw_response.env[:status]
21
- member = Rhapsody::Member.new(@json_response)
22
- end
23
- end
@@ -1,18 +0,0 @@
1
- module Rhapsody::FaradayConnection
2
- require 'faraday'
3
-
4
- def self.prepare_authentication
5
- Faraday.new(:url => Rhapsody::HOST_URL) do |faraday|
6
- faraday.request :url_encoded
7
- faraday.adapter Faraday.default_adapter
8
- end
9
- end
10
-
11
- def self.prepare_authorization(access_token)
12
- Faraday.new(:url => Rhapsody::HOST_URL) do |faraday|
13
- faraday.request :url_encoded
14
- faraday.adapter Faraday.default_adapter
15
- faraday.authorization :Bearer, access_token
16
- end
17
- end
18
- end
@@ -1,35 +0,0 @@
1
- class Rhapsody::Member
2
- require 'json'
3
-
4
- attr_accessor :attr_list
5
-
6
- class << self
7
- # TODO: This needs to be global / base
8
- def define_attr_accessor(key)
9
- __send__(:attr_accessor, key)
10
- end
11
-
12
- def to_camelcase(key)
13
- key.to_s.underscore
14
- end
15
- end
16
-
17
- def initialize(options)
18
- if options
19
- self.attr_list = []
20
-
21
- options.each do |key, value|
22
- key = Rhapsody::Member.to_camelcase(key)
23
-
24
- # Set attr_accessor dynamically
25
- Rhapsody::Member.define_attr_accessor(key)
26
- self.attr_list << key
27
-
28
- # Set value for the attribute
29
- send("#{key}=", value)
30
- end
31
- end
32
- end
33
-
34
-
35
- end
@@ -1,14 +0,0 @@
1
- require 'yaml'
2
- require_relative '../lib/rhapsody'
3
-
4
- module ConfigHelper
5
- def ConfigHelper.load
6
- config_path = Dir.pwd.to_s + '/spec/config.yml'
7
-
8
- if File.exist?(config_path)
9
- YAML.load_file(config_path)
10
- else
11
- raise 'spec/config.yml not found.'
12
- end
13
- end
14
- end
@@ -1,78 +0,0 @@
1
- require 'json'
2
-
3
- module AuthenticationHelper
4
-
5
- # using password grant get an access token
6
- def AuthenticationHelper.get_access_token
7
- oauth_path = 'https://api.rhapsody.com/oauth/token'
8
- yaml = ConfigHelper.load
9
- config_variables = yaml['config_variables']
10
- api_key = config_variables['API_KEY']
11
- api_secret = config_variables['API_SECRET']
12
- username = config_variables['USERNAME']
13
- password = config_variables['PASSWORD']
14
-
15
- connection = Faraday.new(:url => Rhapsody::HOST_URL) do |faraday|
16
- faraday.request :url_encoded
17
- faraday.basic_auth(api_key, api_secret)
18
- faraday.adapter Faraday.default_adapter
19
- end
20
-
21
- post_hash = {
22
- username: username,
23
- password: password,
24
- grant_type: 'password'
25
- }
26
-
27
- raw_response = connection.post(oauth_path, post_hash)
28
- json_response = JSON.parse(raw_response.env[:body])
29
- access_token = json_response['access_token']
30
- end
31
-
32
- def AuthenticationHelper.get_connected_client
33
- oauth_path = 'https://api.rhapsody.com/oauth/token'
34
- yaml = ConfigHelper.load
35
- config_variables = yaml['config_variables']
36
- api_key = config_variables['API_KEY']
37
- api_secret = config_variables['API_SECRET']
38
- username = config_variables['USERNAME']
39
- password = config_variables['PASSWORD']
40
-
41
- connection = Faraday.new(:url => Rhapsody::HOST_URL) do |faraday|
42
- faraday.request :url_encoded
43
- faraday.basic_auth(api_key, api_secret)
44
- faraday.adapter Faraday.default_adapter
45
- end
46
-
47
- post_hash = {
48
- username: username,
49
- password: password,
50
- grant_type: 'password'
51
- }
52
-
53
- raw_response = connection.post(oauth_path, post_hash)
54
- json_response = JSON.parse(raw_response.env[:body])
55
-
56
- client = Rhapsody::ClientsController.new({
57
- api_key: config_variables['API_KEY'],
58
- api_secret: config_variables['API_SECRET'],
59
- access_token: json_response['access_token'],
60
- refresh_token: json_response['refresh_token']
61
- })
62
- end
63
-
64
- # typical post hash
65
- def AuthenticationHelper.post_hash
66
- yaml = ConfigHelper.load
67
- config_variables = yaml['config_variables']
68
- api_key = config_variables['API_KEY']
69
- api_secret = config_variables['API_SECRET']
70
-
71
- options = {
72
- api_key: api_key,
73
- api_secret: api_secret,
74
- auth_code: 'fakeauthcode',
75
- redirect_url: 'http://api.soundtracking.dev:3000/auth/rhapsody/authorize'
76
- }
77
- end
78
- end
@@ -1,84 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rhapsody::ClientsController do
4
- it 'has HOST_URL' do
5
- host_url = Rhapsody::HOST_URL
6
- expect(host_url).to eql('https://api.rhapsody.com')
7
- end
8
-
9
- it 'has attributes' do
10
- options = AuthenticationHelper.post_hash
11
- client_controller = Rhapsody::ClientsController.new(options)
12
-
13
- expect(client_controller).to respond_to(:api_key)
14
- expect(client_controller).to respond_to(:api_secret)
15
- expect(client_controller).to respond_to(:auth_code)
16
- expect(client_controller).to respond_to(:redirect_url)
17
- expect(client_controller).to respond_to(:raw_reponse)
18
- expect(client_controller).to respond_to(:json_response)
19
- expect(client_controller).to respond_to(:response_status)
20
- expect(client_controller).to respond_to(:access_token)
21
- expect(client_controller).to respond_to(:refresh_token)
22
- expect(client_controller).to respond_to(:expires_in)
23
- end
24
-
25
- it '#me_account' do
26
- options = AuthenticationHelper.post_hash
27
- client_controller = Rhapsody::ClientsController.new(options)
28
- client_controller.access_token = AuthenticationHelper.get_access_token
29
-
30
- member = client_controller.me_account
31
-
32
- member_attributes = [
33
- :cobrand,
34
- :cocat,
35
- :email,
36
- :logon,
37
- :firstName,
38
- :id,
39
- :lastName,
40
- :locale,
41
- :country,
42
- :isPublic,
43
- :billingPartnerCode,
44
- :catalog,
45
- :createDate,
46
- :isSuspended,
47
- :tierCode,
48
- :tierName,
49
- :productCode,
50
- :productName,
51
- :expirationDate,
52
- :trialLengthDays,
53
- :isTrial,
54
- :state,
55
- :canStreamOnWeb,
56
- :canStreamOnMobile,
57
- :canStreamOnHomeDevice,
58
- :canStreamOnPC,
59
- :canUpgradeStreams,
60
- :canPlayPremiumRadio,
61
- :maxStreamCount,
62
- :isPlayBasedTier,
63
- :isMonthlyPlayBasedTier,
64
- :isOneTimePlayBasedTier,
65
- :totalPlays,
66
- :playsRemaining,
67
- :skipLimit,
68
- :skipLimitMinutes
69
- ]
70
- member_attributes.each do |attr|
71
- expect(member).to respond_to(attr.to_s.underscore)
72
- end
73
-
74
- expect(member).to respond_to(:attr_list)
75
- expect(member.attr_list).to eql(member_attributes.map {|attr| attr.to_s.underscore })
76
- end
77
-
78
- it '#renew' do
79
- client_controller = AuthenticationHelper.get_connected_client
80
- client_controller.renew
81
-
82
- expect(client_controller.response_status).to eql(200)
83
- end
84
- end
@@ -1,6 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rhapsody::MembersController do
4
- it '.new' do
5
- end
6
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rhapsody::FaradayConnection do
4
- it '#prepare_authentication' do
5
- faraday_obj = Rhapsody::FaradayConnection.prepare_authentication
6
- expect(faraday_obj.class.name).to eql('Faraday::Connection')
7
- end
8
-
9
- it '#prepare_authorization' do
10
- faraday_obj = Rhapsody::FaradayConnection.prepare_authorization('fake')
11
- expect(faraday_obj.class.name).to eql('Faraday::Connection')
12
- end
13
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rhapsody::MembersController do
4
- it '.new' do
5
- end
6
-
7
- it '#account' do
8
- end
9
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rhapsody do
4
- it 'loads spec/config.yml' do
5
- yaml = ConfigHelper.load
6
- config_variables = yaml['config_variables']
7
-
8
- expect(config_variables).not_to be_empty
9
- expect(config_variables['API_KEY'].length).not_to eql(0)
10
- expect(config_variables['API_SECRET'].length).not_to eql(0)
11
- expect(config_variables['USERNAME'].length).not_to eql(0)
12
- expect(config_variables['PASSWORD'].length).not_to eql(0)
13
- end
14
-
15
- it 'checks version' do
16
- expect(Rhapsody::VERSION).to eql('0.0.11')
17
- end
18
-
19
- it 'has a helper for getting an access token' do
20
- expect(AuthenticationHelper.get_access_token).not_to eql(0)
21
- end
22
- end
@@ -1,17 +0,0 @@
1
- require 'rubygems'
2
- require 'factory_girl'
3
-
4
- # Load config.yml
5
- require_relative './config_helper'
6
-
7
- # Load helpers
8
- require_relative './helpers/authentication_helper'
9
-
10
- # Load gem files
11
- require_relative '../lib/rhapsody/controllers/clients_controller'
12
-
13
- RSpec.configure do |config|
14
- config.include FactoryGirl::Syntax::Methods
15
- config.include ConfigHelper
16
- config.include AuthenticationHelper
17
- end