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})


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

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



39
40
41
# File 'lib/fat_zebra/config.rb', line 39

def api_version
  @api_version
end

#gatewayString

Returns Gateway url.

Returns:

  • (String)

    Gateway url



27
28
29
# File 'lib/fat_zebra/config.rb', line 27

def gateway
  @gateway
end

#global_optionsString

Returns global request options.

Returns:

  • (String)

    global request options



43
44
45
# File 'lib/fat_zebra/config.rb', line 43

def global_options
  @global_options
end

#http_secureString

Returns http secure.

Returns:

  • (String)

    http secure



35
36
37
# File 'lib/fat_zebra/config.rb', line 35

def http_secure
  @http_secure
end

#proxyString

Returns Proxy url.

Returns:

  • (String)

    Proxy url



31
32
33
# File 'lib/fat_zebra/config.rb', line 31

def proxy
  @proxy
end

#test_modeString

Returns Test mode.

Returns:

  • (String)

    Test mode



23
24
25
# File 'lib/fat_zebra/config.rb', line 23

def test_mode
  @test_mode
end

#tokenString

Returns Token.

Returns:

  • (String)

    Token



19
20
21
# File 'lib/fat_zebra/config.rb', line 19

def token
  @token
end

#usernameString

Returns Username.

Returns:

  • (String)

    Username



15
16
17
# File 'lib/fat_zebra/config.rb', line 15

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



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

def valid!
  format!

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

  true
end