Class: PaymentRails::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/paymentrails/Configuration.rb

Defined Under Namespace

Classes: InvalidProxyAddress

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(publicKey, privateKey, environment = 'production', proxy_uri: nil) ⇒ Configuration

Returns a new instance of Configuration.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/paymentrails/Configuration.rb', line 5

def initialize(publicKey, privateKey, environment = 'production', proxy_uri: nil)
  raise ArgumentError, 'Both key/secret must be a nonempty string' if publicKey.to_s&.empty? || privateKey.to_s&.empty?

  @publicKey = publicKey
  @privateKey = privateKey
  @environment = environment
  # failfast on a bad proxy
  begin
    @proxy = proxy_uri.nil? ? nil : URI.parse(proxy_uri)
  rescue URI::InvalidURIError
    raise InvalidProxyAddress, "Invalid proxy provided to configuration: #{proxy_uri}"
  end
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



46
47
48
# File 'lib/paymentrails/Configuration.rb', line 46

def environment
  @environment
end

#privateKeyObject

Returns the value of attribute privateKey.



42
43
44
# File 'lib/paymentrails/Configuration.rb', line 42

def privateKey
  @privateKey
end

#proxyObject (readonly)

Returns the value of attribute proxy.



36
37
38
# File 'lib/paymentrails/Configuration.rb', line 36

def proxy
  @proxy
end

#publicKeyObject

Returns the value of attribute publicKey.



38
39
40
# File 'lib/paymentrails/Configuration.rb', line 38

def publicKey
  @publicKey
end

Instance Method Details

#apiBaseObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/paymentrails/Configuration.rb', line 19

def apiBase
  case environment
  when 'production'
    'https://api.paymentrails.com'
  when 'development'
    'https://api.railz.io'
  when 'integration'
    'http://api.local.dev:3000'
  else
    'https://api.paymentrails.com'
  end
end

#useSsl?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/paymentrails/Configuration.rb', line 32

def useSsl?
  apiBase.start_with? 'https'
end