Class: Rhapsody::ClientsController
- Inherits:
-
Object
- Object
- Rhapsody::ClientsController
- Defined in:
- lib/rhapsody/controllers/clients_controller.rb
Constant Summary collapse
- OAUTH_PATH =
'/oauth/access_token'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#auth_code ⇒ Object
Returns the value of attribute auth_code.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#json_response ⇒ Object
Returns the value of attribute json_response.
-
#raw_reponse ⇒ Object
Returns the value of attribute raw_reponse.
-
#redirect_url ⇒ Object
Returns the value of attribute redirect_url.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#response_status ⇒ Object
Returns the value of attribute response_status.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(options) ⇒ ClientsController
constructor
A new instance of ClientsController.
- #me_account ⇒ Object
- #renew ⇒ Object
Constructor Details
#initialize(options) ⇒ ClientsController
Returns a new instance of ClientsController.
15 16 17 18 19 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 15 def initialize() .each do |name, value| instance_variable_set("@#{name}", value) end end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
2 3 4 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 2 def access_token @access_token end |
#api_key ⇒ Object
Returns the value of attribute api_key.
2 3 4 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 2 def api_key @api_key end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
2 3 4 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 2 def api_secret @api_secret end |
#auth_code ⇒ Object
Returns the value of attribute auth_code.
2 3 4 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 2 def auth_code @auth_code end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
2 3 4 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 2 def expires_in @expires_in end |
#json_response ⇒ Object
Returns the value of attribute json_response.
2 3 4 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 2 def json_response @json_response end |
#raw_reponse ⇒ Object
Returns the value of attribute raw_reponse.
2 3 4 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 2 def raw_reponse @raw_reponse end |
#redirect_url ⇒ Object
Returns the value of attribute redirect_url.
2 3 4 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 2 def redirect_url @redirect_url end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
2 3 4 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 2 def refresh_token @refresh_token end |
#response_status ⇒ Object
Returns the value of attribute response_status.
2 3 4 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 2 def response_status @response_status end |
Instance Method Details
#connect ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 21 def connect connection = Rhapsody::FaradayConnection.prepare_authentication post_hash = { client_id: @api_key, client_secret: @api_secret, response_type: 'code', grant_type: 'authorization_code', code: @auth_code, redirect_uri: @redirect_url } @raw_response = connection.post(OAUTH_PATH, post_hash) @json_response = JSON.parse(@raw_response.env[:body]) @response_status = @raw_response.env[:status] @access_token = @json_response['access_token'] @refresh_token = @json_response['refresh_token'] @expires_in = @json_response['expires_in'] self end |
#me_account ⇒ Object
64 65 66 67 68 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 64 def me_account = { access_token: @access_token } members_controller = Rhapsody::MembersController.new() member = members_controller.account end |
#renew ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rhapsody/controllers/clients_controller.rb', line 43 def renew connection = Rhapsody::FaradayConnection.prepare_authentication post_hash = { client_id: @api_key, client_secret: @api_secret, response_type: 'code', grant_type: 'refresh_token', refresh_token: @refresh_token } @raw_response = connection.post(OAUTH_PATH, post_hash) @json_response = JSON.parse(@raw_response.env[:body]) @response_status = @raw_response.env[:status] @access_token = @json_response['access_token'] @refresh_token = @json_response['refresh_token'] @expires_in = @json_response['expires_in'] self end |