Class: FatZebra::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/fat_zebra/config.rb

Overview

FatZebra Config

Represent the FatZebra configuration for the API

Constant Summary collapse

GATEWAY_URLS =
{
  production: 'gateway.fatzebra.com.au',
  sandbox: 'gateway.sandbox.fatzebra.com.au'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Initialize and validate the configuration

Parameters:

  • (Hash{Symbol=>Object})


50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fat_zebra/config.rb', line 50

def initialize(options = {})
  self.token          = options[:token]
  self.username       = options[:username]
  self.gateway        = options[:gateway] || :production
  self.test_mode      = options[:test_mode] || false
  self.http_secure    = options[:http_secure] || true
  self.api_version    = options[:api_version] || 'v1.0'
  self.proxy          = options[:proxy]
  self.global_options = options[:global_options] || {}

  valid! unless options.empty?
end

Instance Attribute Details

#api_versionString

Returns api version.

Returns:

  • (String)

    api version



41
42
43
# File 'lib/fat_zebra/config.rb', line 41

def api_version
  @api_version
end

#gatewayString

Returns Gateway url.

Returns:

  • (String)

    Gateway url



29
30
31
# File 'lib/fat_zebra/config.rb', line 29

def gateway
  @gateway
end

#global_optionsString

Returns global request options.

Returns:

  • (String)

    global request options



45
46
47
# File 'lib/fat_zebra/config.rb', line 45

def global_options
  @global_options
end

#http_secureString

Returns http secure.

Returns:

  • (String)

    http secure



37
38
39
# File 'lib/fat_zebra/config.rb', line 37

def http_secure
  @http_secure
end

#proxyString

Returns Proxy url.

Returns:

  • (String)

    Proxy url



33
34
35
# File 'lib/fat_zebra/config.rb', line 33

def proxy
  @proxy
end

#test_modeString

Returns Test mode.

Returns:

  • (String)

    Test mode



25
26
27
# File 'lib/fat_zebra/config.rb', line 25

def test_mode
  @test_mode
end

#tokenString

Returns Token.

Returns:

  • (String)

    Token



21
22
23
# File 'lib/fat_zebra/config.rb', line 21

def token
  @token
end

#usernameString

Returns Username.

Returns:

  • (String)

    Username



17
18
19
# File 'lib/fat_zebra/config.rb', line 17

def username
  @username
end

Instance Method Details

#valid!Boolean

validate the configuration Raise when configuration is not valid Remove “http://” or “https://” from urls

Returns:

  • (Boolean)

    true



69
70
71
72
73
74
75
76
77
# File 'lib/fat_zebra/config.rb', line 69

def valid!
  format!

  %i[username token gateway api_version].each do |field|
    validate_presence(field)
  end

  true
end