Class: PlentyClient::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/plenty_client/config.rb

Defined Under Namespace

Classes: InvalidCredentials, NoCredentials, NoPlentyId, NoToken

Constant Summary collapse

LOGIN_RENEW_BUFFER =

When expiry_date is less than this many seconds from now, it should renew API keys

60
ATTEMPT_COUNT =
3

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject

Returns the value of attribute access_token.



13
14
15
# File 'lib/plenty_client/config.rb', line 13

def access_token
  @access_token
end

.api_passwordObject

Returns the value of attribute api_password.



13
14
15
# File 'lib/plenty_client/config.rb', line 13

def api_password
  @api_password
end

.api_userObject

Returns the value of attribute api_user.



13
14
15
# File 'lib/plenty_client/config.rb', line 13

def api_user
  @api_user
end

.attempt_countObject



24
25
26
# File 'lib/plenty_client/config.rb', line 24

def attempt_count
  @attempt_count || ATTEMPT_COUNT
end

.expiry_dateObject

Returns the value of attribute expiry_date.



13
14
15
# File 'lib/plenty_client/config.rb', line 13

def expiry_date
  @expiry_date
end

.logObject

Returns the value of attribute log.



13
14
15
# File 'lib/plenty_client/config.rb', line 13

def log
  @log
end

.plenty_idObject

Returns the value of attribute plenty_id.



13
14
15
# File 'lib/plenty_client/config.rb', line 13

def plenty_id
  @plenty_id
end

.refresh_tokenObject

Returns the value of attribute refresh_token.



13
14
15
# File 'lib/plenty_client/config.rb', line 13

def refresh_token
  @refresh_token
end

.site_urlObject

Returns the value of attribute site_url.



13
14
15
# File 'lib/plenty_client/config.rb', line 13

def site_url
  @site_url
end

Class Method Details

.tokens_present?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/plenty_client/config.rb', line 20

def tokens_present?
  !access_token.nil? && !refresh_token.nil?
end

.tokens_valid?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/plenty_client/config.rb', line 28

def tokens_valid?
  tokens_present? &&
    expiry_date.instance_of?(Time) &&
    expiry_date > Time.now &&
    (expiry_date - Time.now > LOGIN_RENEW_BUFFER)
end

.validate_credentialsObject

Raises:



16
17
18
# File 'lib/plenty_client/config.rb', line 16

def validate_credentials
  raise NoCredentials if site_url.nil? || api_user.nil? || api_password.nil?
end