Module: Avalara

Defined in:
lib/avalara.rb,
lib/avalara/api.rb,
lib/avalara/types.rb,
lib/avalara/errors.rb,
lib/avalara/parser.rb,
lib/avalara/request.rb,
lib/avalara/version.rb,
lib/avalara/response.rb,
lib/avalara/types/date.rb,
lib/avalara/types/stash.rb,
lib/avalara/request/line.rb,
lib/avalara/request/address.rb,
lib/avalara/request/invoice.rb,
lib/avalara/response/invoice.rb,
lib/avalara/response/message.rb,
lib/avalara/response/tax_line.rb,
lib/avalara/response/tax_detail.rb,
lib/avalara/request/detail_level.rb,
lib/avalara/response/tax_address.rb

Defined Under Namespace

Modules: Request, Response, Types Classes: API, Configuration, Parser

Constant Summary collapse

Error =
Class.new(StandardError)
TimeoutError =
Class.new(Error)
NotImplementedError =
Class.new(Error)
ApiError =
Class.new(Error)
VERSION =
'0.0.2'

Class Method Summary collapse

Class Method Details

.configuration {|@@_configuration| ... } ⇒ Object

Yields:

  • (@@_configuration)


15
16
17
18
19
# File 'lib/avalara.rb', line 15

def self.configuration
  @@_configuration ||= Avalara::Configuration.new
  yield @@_configuration if block_given?
  @@_configuration
end

.configuration=(configuration) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
# 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) ⇒ Object



26
27
28
# File 'lib/avalara.rb', line 26

def self.configure(&block)
  configuration(&block)
end

.endpointObject



30
31
32
# File 'lib/avalara.rb', line 30

def self.endpoint
  configuration.endpoint
end

.endpoint=(endpoint) ⇒ Object



33
34
35
# File 'lib/avalara.rb', line 33

def self.endpoint=(endpoint)
  configuration.endpoint = endpoint
end

.geographical_tax(latitude, longitude, sales_amount) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/avalara.rb', line 58

def self.geographical_tax(latitude, longitude, sales_amount)
  raise NotImplementedError
  uri = [configuration.endpoint, configuration.version, "tax", "#{latitude},#{longitude}", "get"].join["/"]

  response = API.get(uri, 
    :headers => API.headers_for('0'),
    :query => { :saleamount => sales_amount }
  )
rescue Timeout::Error
  puts "Timed out"
  raise TimeoutError
end

.get_tax(invoice) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/avalara.rb', line 71

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
  )

  return 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

.passwordObject



44
45
46
# File 'lib/avalara.rb', line 44

def self.password
  configuration.password
end

.password=(password) ⇒ Object



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

def self.password=(password)
  configuration.password = password
end

.usernameObject



37
38
39
# File 'lib/avalara.rb', line 37

def self.username
  configuration.username
end

.username=(username) ⇒ Object



40
41
42
# File 'lib/avalara.rb', line 40

def self.username=(username)
  configuration.username = username
end

.versionObject



51
52
53
# File 'lib/avalara.rb', line 51

def self.version
  configuration.version
end

.version=(version) ⇒ Object



54
55
56
# File 'lib/avalara.rb', line 54

def self.version=(version)
  configuration.version = version
end