Module: Teachable::Jg::Configuration

Included in:
Teachable::Jg
Defined in:
lib/teachable/jg/configuration.rb

Constant Summary collapse

VALID_CONNECTION_KEYS =
[:method, :status_message, :delivered].freeze
VALID_OPTIONS_KEYS =
[:format, :headers, :authorized].freeze
VALID_CONFIG_KEYS =
VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
DEFAULT_ENDPOINT =
"http://secure.localhost.com:3000/users"
CURRENT_USER_ENDPOINT =
"http://secure.localhost.com:3000/api/users/current_user/edit"
ORDERS_ENDPOINT =
"http://secure.localhost.com:3000/api/orders"
DEFAULT_HEADERS =
{ "Content-Type"  => "application/json",
"Accept"       => "application/json" }
DEFAULT_METHOD =
:post
DEFAULT_FORMAT =
:json
DEFAULT_USER_AGENT =
"Teachable Mock API Ruby Gem #{Teachable::Jg::VERSION}".freeze
DEFAULT_DELIVERED =
false
DEFAULT_AUTHORIZED =
false
DEFAULT_STATUS_MESSAGE =
""

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Make sure we have the default values set when we get ‘extended’



29
30
31
# File 'lib/teachable/jg/configuration.rb', line 29

def self.extended(base)
  base.reset
end

Instance Method Details

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

Yields:

  • (_self)

Yield Parameters:



49
50
51
# File 'lib/teachable/jg/configuration.rb', line 49

def configure
  yield self
end

#optionsObject



33
34
35
36
37
38
# File 'lib/teachable/jg/configuration.rb', line 33

def options
  Hash[ * VALID_CONFIG_KEYS.map do |key|
    self.reset
    [key, send(key)]
  end.flatten ]
end

#resetObject



40
41
42
43
44
45
46
47
# File 'lib/teachable/jg/configuration.rb', line 40

def reset
  self.headers               = DEFAULT_HEADERS
  self.method                = DEFAULT_METHOD
  self.format                = DEFAULT_FORMAT
  self.delivered             = DEFAULT_DELIVERED
  self.status_message        = DEFAULT_STATUS_MESSAGE
  self.authorized            = DEFAULT_AUTHORIZED
end