Class: Twinfield::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/twinfield/configuration.rb

Overview

Used for configuration of the Twinfield gem.

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



20
21
22
# File 'lib/twinfield/configuration.rb', line 20

def access_token
  @access_token
end

#clusterObject

in case Twinfield::Api::OAuthSession is used



19
20
21
# File 'lib/twinfield/configuration.rb', line 19

def cluster
  @cluster
end

#companyObject

Returns the value of attribute company.



16
17
18
# File 'lib/twinfield/configuration.rb', line 16

def company
  @company
end

#log_levelObject

Log level, e.g. :info, :debug; currently only forwarded to Savon



23
24
25
# File 'lib/twinfield/configuration.rb', line 23

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



24
25
26
# File 'lib/twinfield/configuration.rb', line 24

def logger
  @logger
end

#organisationObject

Returns the value of attribute organisation.



15
16
17
# File 'lib/twinfield/configuration.rb', line 15

def organisation
  @organisation
end

#passwordObject

Returns the value of attribute password.



14
15
16
# File 'lib/twinfield/configuration.rb', line 14

def password
  @password
end

#session_typeObject

Twinfield::Api::OAuthSession or Twinfield::Api::Session



10
11
12
# File 'lib/twinfield/configuration.rb', line 10

def session_type
  @session_type
end

#usernameObject

in case Twinfield::Api::Session is used



13
14
15
# File 'lib/twinfield/configuration.rb', line 13

def username
  @username
end

Instance Method Details

#access_token_expired?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# File 'lib/twinfield/configuration.rb', line 34

def access_token_expired?
  Time.at(JSON.parse(Base64.decode64(access_token.split(".")[1]))["exp"]) < Time.now
rescue => e
  raise Twinfield::Configuration::Error, "No valid access token provided (#{e.message})"
end

#session_classObject



40
41
42
43
44
45
46
47
# File 'lib/twinfield/configuration.rb', line 40

def session_class
  case session_type
  when "Twinfield::Api::OAuthSession"
    Twinfield::Api::OAuthSession
  else
    Twinfield::Api::Session
  end
end

#to_logon_hashObject



26
27
28
29
30
31
32
# File 'lib/twinfield/configuration.rb', line 26

def to_logon_hash
  {
    "user" => @username,
    "password" => @password,
    "organisation" => @organisation
  }
end