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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

.api_passwordObject

Returns the value of attribute api_password.



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

def api_password
  @api_password
end

.api_userObject

Returns the value of attribute api_user.



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

def api_user
  @api_user
end

.expiry_dateObject

Returns the value of attribute expiry_date.



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

def expiry_date
  @expiry_date
end

.logObject

Returns the value of attribute log.



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

def log
  @log
end

.plenty_idObject

Returns the value of attribute plenty_id.



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

def plenty_id
  @plenty_id
end

.refresh_tokenObject

Returns the value of attribute refresh_token.



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

def refresh_token
  @refresh_token
end

.site_urlObject

Returns the value of attribute site_url.



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

def site_url
  @site_url
end

Class Method Details

.tokens_present?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/plenty_client/config.rb', line 18

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

.tokens_valid?Boolean

Returns:

  • (Boolean)


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

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:



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

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