Class: FlexCommerceApi::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/flex_commerce_api/config.rb

Overview

Global configuration object

This is not accessed directly but using code similar to this example :-

FlexCommerceApi.config do |config|
  config.flex_root_url=ENV["FLEX_ROOT_URL"]
  config.=ENV["FLEX_ACCOUNT"]
  config.flex_api_key=ENV["FLEX_API_KEY"]
  config.logger = Rails.logger
  config.order_test_mode = ENV.key?("ORDER_TEST_MODE")
end

The above code would typically be found in a rails initializer as an example.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



33
34
35
36
37
38
# File 'lib/flex_commerce_api/config.rb', line 33

def initialize
  self.order_test_mode = false
  self.http_cache = {}
  self.open_timeout = ENV.fetch('SHIFT_OPEN_TIMEOUT', 2).to_i
  self.timeout = ENV.fetch('SHIFT_TIMEOUT', 15).to_i
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



30
31
32
# File 'lib/flex_commerce_api/config.rb', line 30

def adapter
  @adapter
end

#api_versionObject (readonly)

Returns the value of attribute api_version.



31
32
33
# File 'lib/flex_commerce_api/config.rb', line 31

def api_version
  @api_version
end

#flex_accountObject

The account to be used on the flex server. For example myaccount



30
# File 'lib/flex_commerce_api/config.rb', line 30

attr_accessor :flex_root_url, :flex_api_key, :flex_account, :logger, :adapter, :order_test_mode, :http_cache, :open_timeout, :timeout, :paypal_login, :paypal_password, :paypal_signature, :order_test_mode, :paypal_connection_errors_no_of_retries

#flex_api_keyObject

The API key to access the flex server with. This comes from the ‘Access Keys’ section of the admin panel



30
# File 'lib/flex_commerce_api/config.rb', line 30

attr_accessor :flex_root_url, :flex_api_key, :flex_account, :logger, :adapter, :order_test_mode, :http_cache, :open_timeout, :timeout, :paypal_login, :paypal_password, :paypal_signature, :order_test_mode, :paypal_connection_errors_no_of_retries

#flex_root_urlObject

The root url for the flex server. Must NOT include the account name at the end For example api.flexcommerce.com



30
31
32
# File 'lib/flex_commerce_api/config.rb', line 30

def flex_root_url
  @flex_root_url
end

#http_cacheObject

Returns the value of attribute http_cache.



30
31
32
# File 'lib/flex_commerce_api/config.rb', line 30

def http_cache
  @http_cache
end

#loggerObject

Returns the value of attribute logger.



30
31
32
# File 'lib/flex_commerce_api/config.rb', line 30

def logger
  @logger
end

#open_timeoutObject

Returns the value of attribute open_timeout.



30
31
32
# File 'lib/flex_commerce_api/config.rb', line 30

def open_timeout
  @open_timeout
end

#order_test_modeObject

The order test mode.This config determines if orders are processed as test or real orders



30
# File 'lib/flex_commerce_api/config.rb', line 30

attr_accessor :flex_root_url, :flex_api_key, :flex_account, :logger, :adapter, :order_test_mode, :http_cache, :open_timeout, :timeout, :paypal_login, :paypal_password, :paypal_signature, :order_test_mode, :paypal_connection_errors_no_of_retries

#paypal_connection_errors_no_of_retriesObject

Returns the value of attribute paypal_connection_errors_no_of_retries.



30
31
32
# File 'lib/flex_commerce_api/config.rb', line 30

def paypal_connection_errors_no_of_retries
  @paypal_connection_errors_no_of_retries
end

#paypal_loginObject

Returns the value of attribute paypal_login.



30
31
32
# File 'lib/flex_commerce_api/config.rb', line 30

def 
  
end

#paypal_passwordObject

Returns the value of attribute paypal_password.



30
31
32
# File 'lib/flex_commerce_api/config.rb', line 30

def paypal_password
  @paypal_password
end

#paypal_signatureObject

Returns the value of attribute paypal_signature.



30
31
32
# File 'lib/flex_commerce_api/config.rb', line 30

def paypal_signature
  @paypal_signature
end

#timeoutObject

Returns the value of attribute timeout.



30
31
32
# File 'lib/flex_commerce_api/config.rb', line 30

def timeout
  @timeout
end

Instance Method Details

#api_base_urlString

The api base URL

Returns:

  • (String)

    The base URL for the flex system. Calculated from the flex_root_url and _api_verision



43
44
45
# File 'lib/flex_commerce_api/config.rb', line 43

def api_base_url
  "#{flex_root_url}/#{flex_account}"
end

#reconfigure_all!Object

Informs all models that the configuration may have changed but only if ApiBase is defined - else nothing has loaded yet so they wont need reconfiguring



50
51
52
# File 'lib/flex_commerce_api/config.rb', line 50

def reconfigure_all!
  FlexCommerceApi::BaseResource.reconfigure_all if FlexCommerceApi.const_defined? "ApiBase"
end