Module: BillysBilling::Config

Included in:
BillysBilling
Defined in:
lib/billys_billing/config.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

VALID_QUERIES =
[
  "contact",
  "invoice",
  "organization",
  "payment",
  "product",
  "vat_model",
  "account"
]
VALID_ACTIONS =
[
  "show",
  # "get",
  "index",
  "list",
  "create",
  "add",
  "update",
  "destroy",
  "delete"
]
DEFAULT_API_KEY =

The api key if none is set

nil
DEFAULT_ENDPOINT =

The endpoint that will be used to connect if none is set

'https://api.billysbilling.dk/v1'
VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a BillysBilling::Client

[
  :api_key,
  :endpoint,
  :valid_actions,
  :valid_queries
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values



47
48
49
# File 'lib/billys_billing/config.rb', line 47

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



52
53
54
55
# File 'lib/billys_billing/config.rb', line 52

def configure
  yield self
  self
end

#optionsObject

Create a hash of options and their values



58
59
60
61
62
# File 'lib/billys_billing/config.rb', line 58

def options
  options = {}
  VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
  options
end

#resetObject

Reset all configuration options to defaults



65
66
67
68
69
70
# File 'lib/billys_billing/config.rb', line 65

def reset
  self.api_key            = DEFAULT_API_KEY
  self.endpoint           = DEFAULT_ENDPOINT
  self.valid_actions      = VALID_ACTIONS
  self.valid_queries      = VALID_QUERIES
end