Class: Zara4::API::Communication::Authentication::UserAuthenticator

Inherits:
Authenticator
  • Object
show all
Defined in:
lib/zara4/api/communication/authentication/user_authenticator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Authenticator

#with_image_processing, #with_usage

Constructor Details

#initialize(client_id, client_secret, username, password) ⇒ UserAuthenticator

Constructor



11
12
13
14
15
# File 'lib/zara4/api/communication/authentication/user_authenticator.rb', line 11

def initialize(client_id, client_secret, username, password)
  super.initialize(client_id, client_secret)
  @username = username
  @password = password
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



5
6
7
# File 'lib/zara4/api/communication/authentication/user_authenticator.rb', line 5

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



5
6
7
# File 'lib/zara4/api/communication/authentication/user_authenticator.rb', line 5

def client_secret
  @client_secret
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/zara4/api/communication/authentication/user_authenticator.rb', line 5

def password
  @password
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/zara4/api/communication/authentication/user_authenticator.rb', line 5

def username
  @username
end

Instance Method Details

#acquire_access_tokenObject

Acquire an AccessToken using this UserAuthenticator.



21
22
23
24
25
26
27
28
29
30
# File 'lib/zara4/api/communication/authentication/user_authenticator.rb', line 21

def acquire_access_token
  grant = Zara4::API::Communication::Grant::ClientCredentialsGrantRequest.new(@client_id, @clint_secret, @scopes)
  tokens = grant.getTokens()
    
  access_token  = tokens['access_token']
  refresh_token = tokens['refresh_token']
  expires_at    = Zara4::API::Communication::Util::calculate_expiry_time(tokens['expires_in'])
  
  return Zara4::API::Communication::AccessToken::RefreshableAccessToken.new(@client_id, @client_secret, access_token, expires_at, refresh_token)
end