module Avalara

Constants

Error
NotImplementedError
TimeoutError
VERSION

Public Class Methods

configuration() { |_configuration| ... } click to toggle source
# File lib/avalara.rb, line 15
def self.configuration
  @@_configuration ||= Avalara::Configuration.new
  yield @@_configuration if block_given?
  @@_configuration
end
configuration=(configuration) click to toggle source
# File lib/avalara.rb, line 21
def self.configuration=(configuration)
  raise ArgumentError, 'Expected a Avalara::Configuration instance' unless configuration.kind_of?(Configuration)
  @@_configuration = configuration
end
configure(&block) click to toggle source
# File lib/avalara.rb, line 26
def self.configure(&block)
  configuration(&block)
end
endpoint() click to toggle source
# File lib/avalara.rb, line 54
def self.endpoint
  configuration.endpoint
end
endpoint=(endpoint) click to toggle source
# File lib/avalara.rb, line 57
def self.endpoint=(endpoint)
  configuration.endpoint = endpoint
end
geographical_tax(latitude, longitude, sales_amount) click to toggle source
# File lib/avalara.rb, line 82
def self.geographical_tax(latitude, longitude, sales_amount)
  uri = [
    configuration.endpoint,
    configuration.version,
    "tax",
    "#{latitude},#{longitude}",
    "get"
  ].join("/")

  response = API.get(
    uri,
    {
      :headers    => API.headers_for('0'),
      :query      => {:saleamount => sales_amount},
      :basic_auth => authentication
    }.merge!(net_settings)
  )

  Avalara::Response::Tax.new(response)
rescue Timeout::Error
  puts "Timed out"
  raise TimeoutError
end
get_tax(invoice) click to toggle source
# File lib/avalara.rb, line 106
def self.get_tax(invoice)
  uri = [endpoint, version, 'tax', 'get'].join('/')

  response = API.post(
    uri,
    {
      :body => invoice.to_json,
      :headers => API.headers_for(invoice.to_json.length),
      :basic_auth => authentication
    }.merge!(net_settings)
  )

  case response.code
  when 200..299
    Response::Invoice.new(response)
  when 400..599
    raise ApiError.new(Response::Invoice.new(response))
  else
    raise ApiError.new(response)
  end
rescue Timeout::Error => e
  raise TimeoutError.new(e)
rescue ApiError => e
  raise e
rescue Exception => e
  raise Error.new(e)
end
open_timeout() click to toggle source
# File lib/avalara.rb, line 46
def self.open_timeout
  configuration.open_timeout
end
open_timeout=(open_timeout) click to toggle source
# File lib/avalara.rb, line 50
def self.open_timeout=(open_timeout)
  configuration.open_timeout = open_timeout
end
password() click to toggle source
# File lib/avalara.rb, line 68
def self.password
  configuration.password
end
password=(password) click to toggle source
# File lib/avalara.rb, line 71
def self.password=(password)
  configuration.password = password
end
read_timeout() click to toggle source
# File lib/avalara.rb, line 38
def self.read_timeout
  configuration.read_timeout
end
read_timeout=(read_timeout) click to toggle source
# File lib/avalara.rb, line 42
def self.read_timeout=(read_timeout)
  configuration.read_timeout = read_timeout
end
timeout() click to toggle source
# File lib/avalara.rb, line 30
def self.timeout
  configuration.timeout
end
timeout=(timeout) click to toggle source
# File lib/avalara.rb, line 34
def self.timeout=(timeout)
  configuration.timeout = timeout
end
username() click to toggle source
# File lib/avalara.rb, line 61
def self.username
  configuration.username
end
username=(username) click to toggle source
# File lib/avalara.rb, line 64
def self.username=(username)
  configuration.username = username
end
validate_address(address_hash) click to toggle source
# File lib/avalara.rb, line 134
def self.validate_address(address_hash)
  uri = [endpoint, version, "address", "validate"].join("/")
  response = API.get(
    uri,
    {
      query: address_hash,
      headers: API.headers_for('0'),
      basic_auth: authentication
    }.merge!(net_settings)
  )
  case response.code
  when 200..299
    Response::Address.new(response)
  when 400..599
    fail ApiError.new(Response::Address.new(response))
  else
    fail ApiError.new(response)
  end
rescue Timeout::Error => e
  raise TimeoutError.new(e)
end
version() click to toggle source
# File lib/avalara.rb, line 75
def self.version
  configuration.version
end
version=(version) click to toggle source
# File lib/avalara.rb, line 78
def self.version=(version)
  configuration.version = version
end

Private Class Methods

authentication() click to toggle source
# File lib/avalara.rb, line 169
def self.authentication
  { :username => username, :password => password}
end
net_settings() click to toggle source
# File lib/avalara.rb, line 158
def self.net_settings
  settings = {}
  if timeout
    settings[:read_timeout] = timeout
    settings[:open_timeout] = timeout
  end
  settings[:read_timeout] = read_timeout if read_timeout
  settings[:open_timeout] = open_timeout if open_timeout
  settings
end

Public Instance Methods

message() click to toggle source
# File lib/avalara/errors.rb, line 13
def message
  @message
end