Class: Icalia::Artanis::ClientAuth

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/icalia/artanis/client_auth.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



10
11
12
# File 'lib/icalia/artanis/client_auth.rb', line 10

def access_token
  @access_token
end

#created_atObject

Returns the value of attribute created_at.



10
11
12
# File 'lib/icalia/artanis/client_auth.rb', line 10

def created_at
  @created_at
end

#token_typeObject

Returns the value of attribute token_type.



10
11
12
# File 'lib/icalia/artanis/client_auth.rb', line 10

def token_type
  @token_type
end

Class Method Details

.fetchObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/icalia/artanis/client_auth.rb', line 50

def self.fetch
  store.fetch 'my-artanis-client-token' do
    response = http.post do |req|
      req.url '/oauth/token'
      req.headers['Authorization'] = client_credentials_authorization_header
      req.params['grant_type'] = 'client_credentials'
    end
    # Return a new instance of the Client Auth:
    new ActiveSupport::JSON.decode(response.body)
  end
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
# File 'lib/icalia/artanis/client_auth.rb', line 17

def ==(other)
  other.is_a?(self.class) && other.access_token == access_token
end

#to_authorization_headerObject



25
26
27
# File 'lib/icalia/artanis/client_auth.rb', line 25

def to_authorization_header
  "Bearer #{to_s}"
end

#to_sObject



21
22
23
# File 'lib/icalia/artanis/client_auth.rb', line 21

def to_s
  access_token
end