rhapsody 0.0.6 → 0.0.7

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,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTdjMGFkMTc2M2I2YjM1MzJhZTU1MTU2NDhhMWZhMjEwNzJiM2U1MA==
4
+ YTI4NTFkYTdiZGZiNDZmMTE3MjU1YjVjZjEyNmFhNWM4MWUyYTNjOA==
5
5
  data.tar.gz: !binary |-
6
- ZDFmMmVkMTgyMjgwYjdjZTQ3ZDI2ZTkwNWJhYmI0YWMzMjA1Y2Y3Nw==
6
+ ZjNiNDJmYTI2M2M2YzdhNDg2MWZiODhjYWE1NWJjZDU4NjZiM2Q3Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjVkNGE3NjdlNTE4NWNhZjgzNzFlOTU1MWMzNTQxMWYyODhmZWY5YzRiMGIz
10
- Yzk0NTE3YjY1NTgwMTI0YWI0NDhhZjU3ZDVlNWQ4ZmJjNTEyNTc2NjY4YTk0
11
- OGY0MmU0NThhZGQ2Y2M5OWY0MjQ2NTFlNzE5ODI1MjE0NzY4OTA=
9
+ MDVjZjI4YTI0NjIxZTMzYWNjMTk4MzZhNjUxNGIzMTIwZDgxMzE3ZjBkM2E0
10
+ ZGVmYWJmOWNlMzMwMjUwMjAwZDg2NWZkM2RkY2I0YWI5NjJlNTlhMGQwNDFm
11
+ ODYzNWUzNTNiNWQ0MTRmMTYwNTliYTlmMDI1YWFmZGEyNDFiNDY=
12
12
  data.tar.gz: !binary |-
13
- MDI2OWZiNTZjNWVmNWM2NmVmNzAxYzZhYzI3MWFiNTVhMDY4MWJiZjRmZjY4
14
- YzdkNTczZDQ3N2JkMGZiNjc1ZmEyZmRiYjUzNTU0OTc4M2QwNDU5ZGNjMjNl
15
- MzBmMzQxMWJkNzE1NjRhMjM2Y2NmY2EwMTE2ZTkwNDRmNTlhY2I=
13
+ NWIwM2M0NzIzYzUyYjRjNDZmMjA4NWYwNjRmYTljODE3MTczY2Q4NmU5MTU3
14
+ MGQ0ZWYyMjdmZjhhZWZjNDZiY2ZjNWMxNzk2MTMzNDc4ZDYzMmQzODNkNGY4
15
+ MDBjZmEyYjI1YzYyMDhiMGQ0YTRjMDU5MzRiNzZmMzY3NjllYjA=
@@ -4,7 +4,6 @@ module Rhapsody::FaradayConnection
4
4
  def self.prepare_authentication
5
5
  Faraday.new(:url => Rhapsody::HOST_URL) do |faraday|
6
6
  faraday.request :url_encoded
7
- faraday.response :logger
8
7
  faraday.adapter Faraday.default_adapter
9
8
  end
10
9
  end
@@ -12,7 +11,6 @@ module Rhapsody::FaradayConnection
12
11
  def self.prepare_authorization(access_token)
13
12
  Faraday.new(:url => Rhapsody::HOST_URL) do |faraday|
14
13
  faraday.request :url_encoded
15
- faraday.response :logger
16
14
  faraday.adapter Faraday.default_adapter
17
15
  faraday.authorization :Bearer, access_token
18
16
  end
@@ -1,37 +1,41 @@
1
1
  class Rhapsody::Member
2
- attr_accessor :cobrand,
3
- :cocat,
4
- :email,
5
- :logon,
6
- :firstName,
7
- :id,
8
- :lastName,
9
- :locale,
10
- :country,
11
- :isPublic,
12
- :billingPartnerCode,
13
- :catalog,
14
- :createDate,
15
- :isSuspended,
16
- :tierCode,
17
- :tierName,
18
- :productCode,
19
- :productName,
20
- :expirationDate,
21
- :trialLengthDays,
22
- :isTrial,
23
- :state,
24
- :canStreamOnWeb,
25
- :canStreamOnMobile,
26
- :canStreamOnHomeDevice,
27
- :canStreamOnPC,
28
- :canUpgradeStreams,
29
- :maxStreamCount,
30
- :isPlayBasedTier,
31
- :isMonthlyPlayBasedTier,
32
- :isOneTimePlayBasedTier,
33
- :totalPlays,
34
- :playsRemaining
2
+ ATTR_LIST = [
3
+ :cobrand,
4
+ :cocat,
5
+ :email,
6
+ :logon,
7
+ :firstName,
8
+ :id,
9
+ :lastName,
10
+ :locale,
11
+ :country,
12
+ :isPublic,
13
+ :billingPartnerCode,
14
+ :catalog,
15
+ :createDate,
16
+ :isSuspended,
17
+ :tierCode,
18
+ :tierName,
19
+ :productCode,
20
+ :productName,
21
+ :expirationDate,
22
+ :trialLengthDays,
23
+ :isTrial,
24
+ :state,
25
+ :canStreamOnWeb,
26
+ :canStreamOnMobile,
27
+ :canStreamOnHomeDevice,
28
+ :canStreamOnPC,
29
+ :canUpgradeStreams,
30
+ :maxStreamCount,
31
+ :isPlayBasedTier,
32
+ :isMonthlyPlayBasedTier,
33
+ :isOneTimePlayBasedTier,
34
+ :totalPlays,
35
+ :playsRemaining
36
+ ]
37
+
38
+ attr_accessor *ATTR_LIST
35
39
 
36
40
  def initialize(options)
37
41
  if options
@@ -40,4 +44,5 @@ class Rhapsody::Member
40
44
  end
41
45
  end
42
46
  end
47
+
43
48
  end
@@ -1,3 +1,3 @@
1
1
  module Rhapsody
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,46 @@
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
+ # typical post hash
33
+ def AuthenticationHelper.post_hash
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
+
39
+ options = {
40
+ api_key: api_key,
41
+ api_secret: api_secret,
42
+ auth_code: 'fakeauthcode',
43
+ redirect_url: 'http://api.soundtracking.dev:3000/auth/rhapsody/authorize'
44
+ }
45
+ end
46
+ end
@@ -5,4 +5,67 @@ describe Rhapsody::ClientsController do
5
5
  host_url = Rhapsody::HOST_URL
6
6
  expect(host_url).to eql('https://api.rhapsody.com')
7
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
+ :maxStreamCount,
61
+ :isPlayBasedTier,
62
+ :isMonthlyPlayBasedTier,
63
+ :isOneTimePlayBasedTier,
64
+ :totalPlays,
65
+ :playsRemaining
66
+ ]
67
+ member_attributes.each do |attr|
68
+ expect(member).to respond_to(attr)
69
+ end
70
+ end
8
71
  end
@@ -8,9 +8,15 @@ describe Rhapsody do
8
8
  expect(config_variables).not_to be_empty
9
9
  expect(config_variables['API_KEY'].length).not_to eql(0)
10
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)
11
13
  end
12
14
 
13
15
  it 'checks version' do
14
- expect(Rhapsody::VERSION).to eql('0.0.6')
16
+ expect(Rhapsody::VERSION).to eql('0.0.7')
17
+ end
18
+
19
+ it 'has a helper for getting an access token' do
20
+ expect(AuthenticationHelper.get_access_token).not_to eql(0)
15
21
  end
16
22
  end
data/spec/spec_helper.rb CHANGED
@@ -4,10 +4,14 @@ require 'factory_girl'
4
4
  # Load config.yml
5
5
  require_relative './config_helper'
6
6
 
7
+ # Load helpers
8
+ require_relative './helpers/authentication_helper'
9
+
7
10
  # Load gem files
8
11
  require_relative '../lib/rhapsody/controllers/clients_controller'
9
12
 
10
13
  RSpec.configure do |config|
11
14
  config.include FactoryGirl::Syntax::Methods
12
15
  config.include ConfigHelper
16
+ config.include AuthenticationHelper
13
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhapsody
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Kim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-13 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,6 +59,7 @@ files:
59
59
  - lib/rhapsody/version.rb
60
60
  - rhapsody.gemspec
61
61
  - spec/config_helper.rb
62
+ - spec/helpers/authentication_helper.rb
62
63
  - spec/rhapsody/controllers/clients_controller_spec.rb
63
64
  - spec/rhapsody/controllers/members_controller_spec.rb
64
65
  - spec/rhapsody/helpers/faraday_connection_spec.rb
@@ -91,6 +92,7 @@ specification_version: 4
91
92
  summary: ! 'NOT READY: A Ruby object-oriented interface to the Rhapsody REST API'
92
93
  test_files:
93
94
  - spec/config_helper.rb
95
+ - spec/helpers/authentication_helper.rb
94
96
  - spec/rhapsody/controllers/clients_controller_spec.rb
95
97
  - spec/rhapsody/controllers/members_controller_spec.rb
96
98
  - spec/rhapsody/helpers/faraday_connection_spec.rb