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.



9
10
11
# File 'lib/buckaruby/configuration.rb', line 9

def initialize(options)
  @options = options
end

Instance Method Details

#api_urlObject



21
22
23
# File 'lib/buckaruby/configuration.rb', line 21

def api_url
  live? ? LIVE_URL : TEST_URL
end

#hash_methodObject

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



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

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)


17
18
19
# File 'lib/buckaruby/configuration.rb', line 17

def live?
  !test?
end

#loggerObject

Use the logger from either the options or the global config.



57
58
59
# File 'lib/buckaruby/configuration.rb', line 57

def logger
  @options.fetch(:logger) { Buckaruby.config.logger }
end

#open_timeoutObject

Returns the Net::HTTP open timeout value, fallback to global config.



62
63
64
# File 'lib/buckaruby/configuration.rb', line 62

def open_timeout
  @options.fetch(:open_timeout) { Buckaruby.config.open_timeout }
end

#read_timeoutObject

Returns the Net::HTTP read timeout value, fallback to global config.



67
68
69
# File 'lib/buckaruby/configuration.rb', line 67

def read_timeout
  @options.fetch(:read_timeout) { Buckaruby.config.read_timeout }
end

#secretObject



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

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)


13
14
15
# File 'lib/buckaruby/configuration.rb', line 13

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

#websiteObject



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

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

    website
  end
end