Class: ExvoAuth::Autonomous::Consumer

Inherits:
Base
  • Object
show all
Includes:
Http
Defined in:
lib/exvo_auth/autonomous/consumer.rb

Instance Attribute Summary

Attributes inherited from Base

#params

Instance Method Summary collapse

Methods included from Http

#delete, #get, #head, #options, #post, #put

Constructor Details

#initialize(params = {}) ⇒ Consumer

Returns a new instance of Consumer


4
5
6
7
# File 'lib/exvo_auth/autonomous/consumer.rb', line 4

def initialize(params = {})
  super
  validate_params!(:app_id)
end

Instance Method Details

#authorizationObject


21
22
23
24
25
# File 'lib/exvo_auth/autonomous/consumer.rb', line 21

def authorization
  @@cache.fetch(params) do
    authorization!
  end
end

#authorization!Object


27
28
29
30
31
32
33
34
35
# File 'lib/exvo_auth/autonomous/consumer.rb', line 27

def authorization!
  response = auth.get("/apps/consumer/authorizations/#{URI.escape(params[:app_id])}.json")
  
  if response["authorization"]
    @@cache.write(params, response["authorization"])
  else
    raise "Authorization not found. You need an auhorization to contact provider app (#{ params[:app_id] })"
  end
end

#base_uriObject


9
10
11
# File 'lib/exvo_auth/autonomous/consumer.rb', line 9

def base_uri
  authorization["url"]
end

#passwordObject


17
18
19
# File 'lib/exvo_auth/autonomous/consumer.rb', line 17

def password
  authorization["access_token"]
end

#usernameObject


13
14
15
# File 'lib/exvo_auth/autonomous/consumer.rb', line 13

def username
  ExvoAuth::Config.client_id
end