Module: Cashstar::Configuration

Included in:
Cashstar
Defined in:
lib/cashstar/configuration.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a API

[
:username,
:password,
:endpoint,
:return_card_numbers,
:format,
:user_agent,
:adapter,
:faraday_options].freeze
DEFAULT_ADAPTER =

The adapter that will be used to connect if none is set

:net_http
DEFAULT_USERNAME =

By default, don’t set a username

nil
DEFAULT_PASSWORD =

By default, don’t set a password

nil
DEFAULT_ENDPOINT =
Note:

This is configurable in case you want to connect to CashStar’s test environment at api-semiprod.cashstar.com

The endpoint that will be used to connect if none is set

'https://api-semiprod.cashstar.com'.freeze
DEFAULT_RETURN_CARD_NUMBERS =

By default, we do not pass card numbers and pins back, only url’s and challenge codes. This helps default to the most secure mode of usage.

false
DEFAULT_FORMAT =
Note:

JSON is preferred over XML because it is more concise and faster to parse.

The response format appended to the path and sent in the ‘Accept’ header if none is set

:json
DEFAULT_USER_AGENT =

The value sent in the ‘User-Agent’ header if none is set

"CashStar Ruby Gem #{Cashstar::VERSION}".freeze
DEFAULT_FARADAY_OPTIONS =
{}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values



49
50
51
# File 'lib/cashstar/configuration.rb', line 49

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



54
55
56
# File 'lib/cashstar/configuration.rb', line 54

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



64
65
66
67
68
# File 'lib/cashstar/configuration.rb', line 64

def options
  options = {}
  VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
  options
end

#resetObject

Reset all configuration options to defaults



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cashstar/configuration.rb', line 71

def reset
  self.adapter            = DEFAULT_ADAPTER
  self.username           = DEFAULT_USERNAME
  self.password           = DEFAULT_PASSWORD
  self.endpoint           = DEFAULT_ENDPOINT
  self.format             = DEFAULT_FORMAT
  self.user_agent         = DEFAULT_USER_AGENT
  self.faraday_options    = DEFAULT_FARADAY_OPTIONS
  self.return_card_numbers = DEFAULT_RETURN_CARD_NUMBERS
  self
end

#test?Boolean

Convienince method determining if pointed to the test env.

Returns:

  • (Boolean)


59
60
61
# File 'lib/cashstar/configuration.rb', line 59

def test?
  self.endpoint == DEFAULT_ENDPOINT
end