Class: Makeleaps::Request::BasicAuth

Inherits:
Base
  • Object
show all
Includes:
ErrorHandler
Defined in:
lib/makeleaps/request/basic_auth.rb

Constant Summary collapse

AUTH_ENDPOINT =
'user/oauth2/token/'
REVOCATKON_ENDPOINT =
'user/oauth2/revoke-token/'

Constants inherited from Base

Makeleaps::Request::Base::ENDPOINT

Instance Attribute Summary

Attributes inherited from Base

#connection

Instance Method Summary collapse

Methods included from ErrorHandler

#handle_api_response

Constructor Details

#initialize(username, password) ⇒ BasicAuth

Returns a new instance of BasicAuth.



11
12
13
14
15
# File 'lib/makeleaps/request/basic_auth.rb', line 11

def initialize(username, password)
  super() do |conn|
    conn.basic_auth(username, password)
  end
end

Instance Method Details

#authenticate!Object



17
18
19
20
21
22
# File 'lib/makeleaps/request/basic_auth.rb', line 17

def authenticate!
  response = handle_api_response do
    connection.post(AUTH_ENDPOINT) { |req| req.params['grant_type'] = 'client_credentials' }
  end
  Makeleaps::Response::TokenStore.new response
end

#revoke!(token) ⇒ Object



24
25
26
27
28
# File 'lib/makeleaps/request/basic_auth.rb', line 24

def revoke!(token)
  handle_api_response do
    connection.post(REVOCATKON_ENDPOINT) { |req| req.params['token'] = token }
  end
end