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.



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

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.



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

def adapter
  @adapter
end

#api_versionObject (readonly)

Returns the value of attribute api_version.



48
49
50
# File 'lib/flex_commerce_api/config.rb', line 48

def api_version
  @api_version
end

#flex_accountObject

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/flex_commerce_api/config.rb', line 31

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

#flex_api_keyObject

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/flex_commerce_api/config.rb', line 31

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

#flex_root_urlObject

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



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

def flex_root_url
  @flex_root_url
end

#forwarded_forObject

Returns the value of attribute forwarded_for.



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

def forwarded_for
  @forwarded_for
end

#http_cacheObject

Returns the value of attribute http_cache.



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

def http_cache
  @http_cache
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#open_timeoutObject

Returns the value of attribute open_timeout.



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

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/flex_commerce_api/config.rb', line 31

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

#paypal_connection_errors_no_of_retriesObject

Returns the value of attribute paypal_connection_errors_no_of_retries.



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

def paypal_connection_errors_no_of_retries
  @paypal_connection_errors_no_of_retries
end

#paypal_loginObject

Returns the value of attribute paypal_login.



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

def 
  @paypal_login
end

#paypal_passwordObject

Returns the value of attribute paypal_password.



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

def paypal_password
  @paypal_password
end

#paypal_signatureObject

Returns the value of attribute paypal_signature.



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

def paypal_signature
  @paypal_signature
end

#timeoutObject

Returns the value of attribute timeout.



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

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



60
61
62
# File 'lib/flex_commerce_api/config.rb', line 60

def api_base_url
  "#{flex_root_url}/#{}"
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



67
68
69
# File 'lib/flex_commerce_api/config.rb', line 67

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