Class: Taxjar::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/taxjar/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
# File 'lib/taxjar/client.rb', line 11

def initialize(options={})
  options = Taxjar.options.merge(options)

  Configuration::VALID_CONFIG_KEYS.each do |key|
    send("#{key}=", options[key])
  end

  check_configuration
  setup_conn
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



9
10
11
# File 'lib/taxjar/client.rb', line 9

def conn
  @conn
end

Instance Method Details

#create_order_transaction(options = {}) ⇒ Object



48
49
50
51
52
# File 'lib/taxjar/client.rb', line 48

def create_order_transaction(options={})
  check_availability(method_api_version: 2, method_api_tier: 'enhanced')
  response = @conn.post api_path('transactions', 'orders'), options
  response.body
end

#create_refund_transaction(options = {}) ⇒ Object



66
67
68
69
70
# File 'lib/taxjar/client.rb', line 66

def create_refund_transaction(options={})
  check_availability(method_api_version: 2, method_api_tier: 'enhanced')
  response = @conn.post api_path('transactions', 'refunds'), options
  response.body
end

#delete_order_transaction(options = {}) ⇒ Object



60
61
62
63
64
# File 'lib/taxjar/client.rb', line 60

def delete_order_transaction(options={})
  check_availability(method_api_version: 2, method_api_tier: 'enhanced')
  response = @conn.delete api_path('transactions', 'orders', options.delete(:transaction_id)), options
  response.body
end

#delete_refund_transaction(options = {}) ⇒ Object



78
79
80
81
82
# File 'lib/taxjar/client.rb', line 78

def delete_refund_transaction(options={})
  check_availability(method_api_version: 2, method_api_tier: 'enhanced')
  response = @conn.delete api_path('transactions', 'refunds', options.delete(:transaction_id)), options
  response.body
end

#list_categoriesObject



42
43
44
45
46
# File 'lib/taxjar/client.rb', line 42

def list_categories()
  check_availability(method_api_version: 2, method_api_tier: 'enhanced')
  response = @conn.get api_path('categories')
  response.body
end

#sales_tax(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/taxjar/client.rb', line 22

def sales_tax(options={})
  case api_version
  when 1
    response = @conn.get api_path('sales_tax'), options
  when 2
    response = @conn.post api_path('taxes'), options
  end
  response.body
end

#tax_rate(options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/taxjar/client.rb', line 32

def tax_rate(options={})
  case api_version
  when 1
    response = @conn.get "/locations/#{options.delete(:zip)}", options
  when 2
    response = @conn.get api_path('rates', options.delete(:zip)), options
  end
  response.body
end

#update_order_transaction(options = {}) ⇒ Object



54
55
56
57
58
# File 'lib/taxjar/client.rb', line 54

def update_order_transaction(options={})
  check_availability(method_api_version: 2, method_api_tier: 'enhanced')
  response = @conn.put api_path('transactions', 'orders', options.delete(:transaction_id)), options
  response.body
end

#update_refund_transaction(options = {}) ⇒ Object



72
73
74
75
76
# File 'lib/taxjar/client.rb', line 72

def update_refund_transaction(options={})
  check_availability(method_api_version: 2, method_api_tier: 'enhanced')
  response = @conn.put api_path('transactions', 'refunds', options.delete(:transaction_id)), options
  response.body
end