Module: Paychex::Configuration

Included in:
Paychex
Defined in:
lib/paychex/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

[
  :access_token,
  :host,
  :endpoint,
  :format,
  :connection_options,
  :proxy,
  :environment,
  :user_agent,
  :per_page,
  :timeout,
  :open_timeout,
  :token_timeout,
].freeze
DEFAULT_ACCESS_TOKEN =

By default, don’t set an access_token

nil
DEFAULT_PER_PAGE =

By default, return 20 resources per page when there is an pagination.

100
DEFAULT_CONNECTION_OPTIONS =

By default, don’t set connection options.

{}
DEFAULT_TIMEOUT =

Default timeout time is 60 seconds

60
DEFAULT_OPEN_TIMEOUT =

By default, the open timeout is 60 seconds.

60
DEFAULT_TOKEN_TIMEOUT =
Time.new
DEFAULT_HOST =

By default, use sandbox environment

"https://sandbox.api.paychex.com".freeze
DEFAULT_ENDPOINT =

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

"https://sandbox.api.paychex.com/".freeze
DEFAULT_FORMAT =
Note:

JSON is the only available format at this time

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

:json
DEFAULT_PROXY =

By default, don’t use a proxy server

nil
DEFAULT_ENVIRONMENT =

By default, environment will be sandbox

"sandbox"
DEFAULT_USER_AGENT =

The user agent that will be sent to the API endpoint if none is set

"Paychex Ruby Gem #{Paychex::VERSION}".freeze
VALID_FORMATS =

An array of valid request/response formats

[:json].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



66
67
68
# File 'lib/paychex/configuration.rb', line 66

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:



71
72
73
# File 'lib/paychex/configuration.rb', line 71

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



76
77
78
79
80
# File 'lib/paychex/configuration.rb', line 76

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

Reset all configuration options to defaults



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/paychex/configuration.rb', line 83

def reset
  self.access_token = DEFAULT_ACCESS_TOKEN
  self.host = DEFAULT_HOST
  self.endpoint = DEFAULT_ENDPOINT
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.format = DEFAULT_FORMAT
  self.proxy = DEFAULT_PROXY
  self.environment = DEFAULT_ENVIRONMENT
  self.user_agent = DEFAULT_USER_AGENT
  self.per_page = DEFAULT_PER_PAGE
  self.timeout = DEFAULT_TIMEOUT
  self.open_timeout = DEFAULT_OPEN_TIMEOUT
  self.token_timeout = DEFAULT_TOKEN_TIMEOUT
end