Class: Buckaruby::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/buckaruby/configuration.rb

Overview

Configuration settings for the Buckaruby Gateway.

Constant Summary collapse

TEST_URL =
'https://testcheckout.buckaroo.nl/nvp/'
LIVE_URL =
'https://checkout.buckaroo.nl/nvp/'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Configuration

Returns a new instance of Configuration.



11
12
13
# File 'lib/buckaruby/configuration.rb', line 11

def initialize(options)
  @options = options
end

Instance Method Details

#api_urlObject



23
24
25
# File 'lib/buckaruby/configuration.rb', line 23

def api_url
  live? ? LIVE_URL : TEST_URL
end

#hash_methodObject

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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/buckaruby/configuration.rb', line 46

def hash_method
  @hash_method ||= begin
    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

    hash_method
  end
end

#live?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/buckaruby/configuration.rb', line 19

def live?
  !test?
end

#loggerObject

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



59
60
61
62
63
64
65
66
# File 'lib/buckaruby/configuration.rb', line 59

def logger
  @logger ||= begin
    logger   = @options[:logger]
    logger ||= Rails.logger if defined?(Rails)
    logger ||= Logger.new($stdout)
    logger
  end
end

#secretObject



36
37
38
39
40
41
42
43
# File 'lib/buckaruby/configuration.rb', line 36

def secret
  @secret ||= begin
    secret = @options[:secret]
    raise ArgumentError, 'Missing required parameter: secret' if secret.to_s.empty?

    secret
  end
end

#test?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/buckaruby/configuration.rb', line 15

def test?
  @options.fetch(:test, false)
end

#websiteObject



27
28
29
30
31
32
33
34
# File 'lib/buckaruby/configuration.rb', line 27

def website
  @website ||= begin
    website = @options[:website]
    raise ArgumentError, 'Missing required parameter: website' if website.to_s.empty?

    website
  end
end