class Buckaruby::Configuration

Configuration settings for the Buckaruby Gateway.

Constants

PRODUCTION_URL
TEST_URL

Attributes

hash_method[R]
logger[R]
mode[R]
secret[R]
website[R]

Public Class Methods

new(options) click to toggle source
# File lib/buckaruby/configuration.rb, line 13
def initialize(options)
  set_website(options)
  set_secret(options)
  set_buckaroo_mode(options)
  set_hash_method(options)
  set_logger(options)
end

Public Instance Methods

api_url() click to toggle source
# File lib/buckaruby/configuration.rb, line 29
def api_url
  test? ? TEST_URL : PRODUCTION_URL
end
production?() click to toggle source
# File lib/buckaruby/configuration.rb, line 25
def production?
  @mode == :production
end
test?() click to toggle source
# File lib/buckaruby/configuration.rb, line 21
def test?
  @mode == :test
end

Private Instance Methods

set_buckaroo_mode(options) click to toggle source

Set Buckaroo mode from options, class setting or the default (test).

# File lib/buckaruby/configuration.rb, line 48
def set_buckaroo_mode(options)
  @mode = options.key?(:mode) ? options[:mode] : Gateway.mode
  @mode ||= :test

  if @mode != :test && @mode != :production
    raise ArgumentError, "Invalid Buckaroo mode provided: #{@mode} (expected :test or :production)"
  end
end
set_hash_method(options) click to toggle source

Set the hash method from options or default (SHA-1).

# File lib/buckaruby/configuration.rb, line 58
def set_hash_method(options)
  @hash_method = (options[:hash_method] || "SHA1").downcase.to_sym

  unless [:sha1, :sha256, :sha512].include?(@hash_method)
    raise ArgumentError, "Invalid hash method provided: #{@hash_method} (expected :sha1, :sha256 or :sha512)"
  end
end
set_logger(options) click to toggle source

Set the logger from options, to Rails or to stdout.

# File lib/buckaruby/configuration.rb, line 67
def set_logger(options)
  @logger   = options[:logger]
  @logger ||= Rails.logger if defined?(Rails)
  @logger ||= Logger.new(STDOUT)
end
set_secret(options) click to toggle source
# File lib/buckaruby/configuration.rb, line 41
def set_secret(options)
  @secret = options[:secret]

  raise ArgumentError, "Missing required parameter: secret" if @secret.to_s.empty?
end
set_website(options) click to toggle source
# File lib/buckaruby/configuration.rb, line 35
def set_website(options)
  @website = options[:website]

  raise ArgumentError, "Missing required parameter: website" if @website.to_s.empty?
end