Class: AvaTax::API

Inherits:
Object
  • Object
show all
Includes:
Connection, Request
Defined in:
lib/avatax/api.rb

Direct Known Subclasses

Client

Instance Method Summary collapse

Methods included from Request

#delete, #get, #post, #put, #request

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/avatax/api.rb', line 11

def initialize(options={})
  options = AvaTax.options.merge(options)
  # The default logger in Faraday is configured exactly the same as this one, but we cannot get a reference to it, so we will instantiate our own.
  default_logger =  Logger.new(STDOUT)
  Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
  ActiveSupport::Notifications.subscribe("request.faraday") do |name, starts, ends, _, env|
    url      = env[:url]
    duration = (ends - starts) * 1000

    if custom_logger
      custom_logger.info "The request to #{url} took #{duration} ms."
    elsif logger
      default_logger.info "The request to #{url} took #{duration} ms."
    end
  end
end

Instance Method Details

#configObject



30
31
32
33
34
35
36
# File 'lib/avatax/api.rb', line 30

def config
  conf = {}
  Configuration::VALID_OPTIONS_KEYS.each do |key|
    conf[key] = send key
  end
  conf
end