Class: Rhapsody::ClientsController

Inherits:
Object
  • Object
show all
Defined in:
lib/rhapsody/controllers/clients_controller.rb

Constant Summary collapse

OAUTH_PATH =
'/oauth/access_token'

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  options.each do |name, value|
    instance_variable_set("@#{name}", value)
  end
end

Instance Attribute Details

#access_tokenObject

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_keyObject

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_secretObject

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_codeObject

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_inObject

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_responseObject

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_reponseObject

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_urlObject

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_tokenObject

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_statusObject

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

#connectObject



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_accountObject



64
65
66
67
68
# File 'lib/rhapsody/controllers/clients_controller.rb', line 64

def 
  options = { access_token: @access_token }
  members_controller = Rhapsody::MembersController.new(options)
  member = members_controller.
end

#renewObject



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