Module: LoyaltyLabSDK

Defined in:
lib/loyalty_lab_sdk/config.rb,
lib/loyalty_lab_sdk/version.rb,
lib/loyalty_lab_sdk/exceptions.rb,
lib/loyalty_lab_sdk/loyalty_api.rb,
lib/loyalty_lab_sdk.rb

Defined Under Namespace

Classes: AuthenticationError, ConnectionError, Error, LoyaltyAPI, UnknownError

Constant Summary collapse

DEFAULT_TIMEOUT =
15
DEFAULT_RETRIES =
2
VERSION =
'0.0.3'

Class Method Summary collapse

Class Method Details

.config(options = nil) ⇒ Object

Globally configures and retrieves configuration for the Loyalty Lab SDK.

Environment Variables

For convenience in a command-line environment, configuration may be skipped by setting the LOYALTY_LAB_SDK_USERNAME and LOYALTY_LAB_SDK_PASSWORD environment variables, which are self-explanatory.

Rails

If running in a rails environment, this configuration will automatically use the global Rails.logger instance. This behavior may be overridden by passing in a :logger option.

Parameters:

  • options (Hash) (defaults to: nil)

Options Hash (options):

  • :username (String) — default: nil

    Loyalty Lab account username

  • :password (String) — default: nil

    Loyalty Lab account password

  • :logger (Logger) — default: Rails.logger

    Logger to use

  • :open_timeout (Numeric) — default: LoyaltyLabSDK::DEFAULT_TIMEOUT

    Number of seconds to wait for the connection to open (see Net::HTTP#open_timeout)

  • :read_timeout (Numeric) — default: LoyaltyLabSDK::DEFAULT_TIMEOUT

    Number of seconds to wait for one block to be read (see Net::HTTP#read_timeout)

  • :connection_error_retries (Integer) — default: LoyaltyLabSDK::DEFAULT_RETRIES

    Number of retries that will be attempted if a connection error (timeout) occurs



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/loyalty_lab_sdk/config.rb', line 35

def self.config(options = nil)
  @config ||= {
    :username => ENV['LOYALTY_LAB_SDK_USERNAME'],
    :password => ENV['LOYALTY_LAB_SDK_PASSWORD'],
    :logger => default_logger,
    :open_timeout => DEFAULT_TIMEOUT,
    :read_timeout => DEFAULT_TIMEOUT,
    :connection_error_retries => DEFAULT_RETRIES,
  }
  
  @config.merge!(options) if options

  @config
end