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.set_basic_auth(username, password)
  end
end

Instance Method Details

#authenticate!Object



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

def authenticate!
  response = handle_api_response do
    connection.post(AUTH_ENDPOINT) do |req|
      req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
      data = { grant_type: 'client_credentials' }
      req.body = URI.encode_www_form(data)
    end
  end
  Makeleaps::Response::TokenStore.new response
end

#revoke!(token) ⇒ Object



28
29
30
31
32
# File 'lib/makeleaps/request/basic_auth.rb', line 28

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