Class: Akeneo::AuthorizationService

Inherits:
ServiceBase show all
Defined in:
lib/akeneo/authorization_service.rb

Constant Summary collapse

REFRESH_RATE_IN_SECONDS =
2000

Constants inherited from ServiceBase

ServiceBase::API_VERSION, ServiceBase::DEFAULT_PAGINATION_LIMIT, ServiceBase::DEFAULT_PAGINATION_TYPE

Constants included from Cache

Cache::DEFAULT_EXPIRES_IN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cache

disabled=, #get_request, prepended

Constructor Details

#initialize(url:) ⇒ AuthorizationService

Returns a new instance of AuthorizationService.



11
12
13
# File 'lib/akeneo/authorization_service.rb', line 11

def initialize(url:)
  @url = url
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



9
10
11
# File 'lib/akeneo/authorization_service.rb', line 9

def access_token
  @access_token
end

#last_refreshObject

Returns the value of attribute last_refresh.



9
10
11
# File 'lib/akeneo/authorization_service.rb', line 9

def last_refresh
  @last_refresh
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



9
10
11
# File 'lib/akeneo/authorization_service.rb', line 9

def refresh_token
  @refresh_token
end

Instance Method Details

#authorize!(client_id:, secret:, username:, password:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/akeneo/authorization_service.rb', line 15

def authorize!(client_id:, secret:, username:, password:)
  @client_id = client_id
  @secret = secret
  options = {
    body: authorization_body(username, password),
    headers: json_headers.merge(basic_authorization_header)
  }
  response = HTTParty.post("#{@url}/api/oauth/v1/token", options)
  store_tokens!(response)
  response
end

#fresh_access_tokenObject



27
28
29
30
# File 'lib/akeneo/authorization_service.rb', line 27

def fresh_access_token
  refresh!
  @access_token
end