avatax 14.4.4 → 17.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +54 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +7 -0
  5. data/.yardopts +5 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +201 -191
  8. data/README.md +63 -61
  9. data/Rakefile +9 -0
  10. data/avatax.gemspec +39 -0
  11. data/example/avatax.rb +14 -0
  12. data/example/credentials.example.yaml +5 -0
  13. data/lib/avatax.rb +19 -13
  14. data/lib/avatax/api.rb +27 -0
  15. data/lib/avatax/client.rb +32 -0
  16. data/lib/avatax/client/accounts.rb +110 -0
  17. data/lib/avatax/client/addresses.rb +52 -0
  18. data/lib/avatax/client/batches.rb +117 -0
  19. data/lib/avatax/client/companies.rb +218 -0
  20. data/lib/avatax/client/contacts.rb +115 -0
  21. data/lib/avatax/client/definitions.rb +569 -0
  22. data/lib/avatax/client/filingcalendars.rb +313 -0
  23. data/lib/avatax/client/filings.rb +417 -0
  24. data/lib/avatax/client/free.rb +104 -0
  25. data/lib/avatax/client/fundingrequests.rb +53 -0
  26. data/lib/avatax/client/items.rb +111 -0
  27. data/lib/avatax/client/jurisdictionoverrides.rb +125 -0
  28. data/lib/avatax/client/locations.rb +158 -0
  29. data/lib/avatax/client/nexus.rb +157 -0
  30. data/lib/avatax/client/notices.rb +297 -0
  31. data/lib/avatax/client/onboarding.rb +23 -0
  32. data/lib/avatax/client/pointofsale.rb +24 -0
  33. data/lib/avatax/client/registrar.rb +216 -0
  34. data/lib/avatax/client/settings.rb +137 -0
  35. data/lib/avatax/client/subscriptions.rb +66 -0
  36. data/lib/avatax/client/taxcodes.rb +127 -0
  37. data/lib/avatax/client/taxrules.rb +127 -0
  38. data/lib/avatax/client/transactions.rb +473 -0
  39. data/lib/avatax/client/upcs.rb +112 -0
  40. data/lib/avatax/client/users.rb +112 -0
  41. data/lib/avatax/client/utilities.rb +52 -0
  42. data/lib/avatax/configuration.rb +53 -18
  43. data/lib/avatax/connection.rb +28 -0
  44. data/lib/avatax/request.rb +38 -0
  45. data/lib/avatax/version.rb +3 -0
  46. data/spec/avatax/client/accounts_spec.rb +26 -0
  47. data/spec/avatax_spec.rb +59 -0
  48. data/spec/fixtures/accounts.json +16 -0
  49. data/spec/spec_helper.rb +47 -0
  50. metadata +143 -30
  51. data/lib/avatax/address_service.rb +0 -31
  52. data/lib/avatax/tax_service.rb +0 -61
@@ -0,0 +1,112 @@
1
+ module AvaTax
2
+ class Client
3
+ module Upcs
4
+
5
+
6
+ # Create a new UPC
7
+ #
8
+ # Create one or more new UPC objects attached to this company.
9
+ # A UPC represents a single UPC code in your catalog and matches this product to the tax code identified by this UPC.
10
+ #
11
+ # @param int companyId The ID of the company that owns this UPC.
12
+ # @param UPCModel[] model The UPC you wish to create.
13
+ # @return UPCModel[]
14
+ def create_u_p_cs(companyId, model)
15
+ path = "/api/v2/companies/#{companyId}/upcs"
16
+
17
+ post(path, model)
18
+ end
19
+
20
+
21
+ # Delete a single UPC
22
+ #
23
+ # Marks the UPC object identified by this URL as deleted.
24
+ #
25
+ # @param int companyId The ID of the company that owns this UPC.
26
+ # @param int id The ID of the UPC you wish to delete.
27
+ # @return ErrorDetail[]
28
+ def delete_u_p_c(companyId, id)
29
+ path = "/api/v2/companies/#{companyId}/upcs/#{id}"
30
+
31
+ delete(path)
32
+ end
33
+
34
+
35
+ # Retrieve a single UPC
36
+ #
37
+ # Get the UPC object identified by this URL.
38
+ # A UPC represents a single UPC code in your catalog and matches this product to the tax code identified by this UPC.
39
+ #
40
+ # @param int companyId The ID of the company that owns this UPC
41
+ # @param int id The primary key of this UPC
42
+ # @return UPCModel
43
+ def get_u_p_c(companyId, id)
44
+ path = "/api/v2/companies/#{companyId}/upcs/#{id}"
45
+
46
+ get(path)
47
+ end
48
+
49
+
50
+ # Retrieve UPCs for this company
51
+ #
52
+ # List all UPC objects attached to this company.
53
+ # A UPC represents a single UPC code in your catalog and matches this product to the tax code identified by this UPC.
54
+ #
55
+ # Search for specific objects using the criteria in the `$filter` parameter; full documentation is available on [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/) .
56
+ # Paginate your results using the `$top`, `$skip`, and `$orderby` parameters.
57
+ #
58
+ # @param int companyId The ID of the company that owns these UPCs
59
+ # @param string filter A filter statement to identify specific records to retrieve. For more information on filtering, see [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/) .
60
+ # @param string include A comma separated list of child objects to return underneath the primary object.
61
+ # @param int top If nonzero, return no more than this number of results. Used with $skip to provide pagination for large datasets.
62
+ # @param int skip If nonzero, skip this number of results before returning data. Used with $top to provide pagination for large datasets.
63
+ # @param string orderBy A comma separated list of sort statements in the format `(fieldname) [ASC|DESC]`, for example `id ASC`.
64
+ # @return FetchResult
65
+ def list_u_p_cs_by_company(companyId, options={})
66
+ path = "/api/v2/companies/#{companyId}/upcs"
67
+
68
+ get(path, options)
69
+ end
70
+
71
+
72
+ # Retrieve all UPCs
73
+ #
74
+ # Get multiple UPC objects across all companies.
75
+ # A UPC represents a single UPC code in your catalog and matches this product to the tax code identified by this UPC.
76
+ #
77
+ # Search for specific objects using the criteria in the `$filter` parameter; full documentation is available on [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/) .
78
+ # Paginate your results using the `$top`, `$skip`, and `$orderby` parameters.
79
+ #
80
+ # @param string filter A filter statement to identify specific records to retrieve. For more information on filtering, see [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/) .
81
+ # @param string include A comma separated list of child objects to return underneath the primary object.
82
+ # @param int top If nonzero, return no more than this number of results. Used with $skip to provide pagination for large datasets.
83
+ # @param int skip If nonzero, skip this number of results before returning data. Used with $top to provide pagination for large datasets.
84
+ # @param string orderBy A comma separated list of sort statements in the format `(fieldname) [ASC|DESC]`, for example `id ASC`.
85
+ # @return FetchResult
86
+ def query_u_p_cs(options={})
87
+ path = "/api/v2/upcs"
88
+
89
+ get(path, options)
90
+ end
91
+
92
+
93
+ # Update a single UPC
94
+ #
95
+ # Replace the existing UPC object at this URL with an updated object.
96
+ # A UPC represents a single UPC code in your catalog and matches this product to the tax code identified by this UPC.
97
+ # All data from the existing object will be replaced with data in the object you PUT.
98
+ # To set a field's value to null, you may either set its value to null or omit that field from the object you post.
99
+ #
100
+ # @param int companyId The ID of the company that this UPC belongs to.
101
+ # @param int id The ID of the UPC you wish to update
102
+ # @param UPCModel model The UPC you wish to update.
103
+ # @return UPCModel
104
+ def update_u_p_c(companyId, id, model)
105
+ path = "/api/v2/companies/#{companyId}/upcs/#{id}"
106
+
107
+ put(path, model)
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,112 @@
1
+ module AvaTax
2
+ class Client
3
+ module Users
4
+
5
+
6
+ # Retrieve a single user
7
+ #
8
+ # Get the user object identified by this URL.
9
+ # A user represents one person with access privileges to make API calls and work with a specific account.
10
+ #
11
+ # @param int id The ID of the user to retrieve.
12
+ # @param int accountId The accountID of the user you wish to get.
13
+ # @param string include A comma separated list of child objects to return underneath the primary object.
14
+ # @return UserModel
15
+ def get_user(id, accountId, options={})
16
+ path = "/api/v2/accounts/#{accountId}/users/#{id}"
17
+
18
+ get(path, options)
19
+ end
20
+
21
+
22
+ # Retrieve all entitlements for a single user
23
+ #
24
+ # Return a list of all entitlements to which this user has rights to access.
25
+ # Entitlements are a list of specified API calls the user is permitted to make, a list of identifier numbers for companies the user is
26
+ # allowed to use, and an access level identifier that indicates what types of access roles the user is allowed to use.
27
+ # This API call is intended to provide a validation endpoint to determine, before making an API call, whether this call is likely to succeed.
28
+ # For example, if user 567 within account 999 is attempting to create a new child company underneath company 12345, you could preview the user's
29
+ # entitlements and predict whether this call would succeed:
30
+ #
31
+ # * Retrieve entitlements by calling '/api/v2/accounts/999/users/567/entitlements' . If the call fails, you do not have accurate
32
+ # credentials for this user.
33
+ # * If the 'accessLevel' field within entitlements is 'None', the call will fail.
34
+ # * If the 'accessLevel' field within entitlements is 'SingleCompany' or 'SingleAccount', the call will fail if the companies
35
+ # table does not contain the ID number 12345.
36
+ # * If the 'permissions' array within entitlements does not contain 'AccountSvc.CompanySave', the call will fail.
37
+ #
38
+ # For a full list of defined permissions, please use '/api/v2/definitions/permissions' .
39
+ #
40
+ # @param int id The ID of the user to retrieve.
41
+ # @param int accountId The accountID of the user you wish to get.
42
+ # @return UserEntitlementModel
43
+ def get_user_entitlements(id, accountId)
44
+ path = "/api/v2/accounts/#{accountId}/users/#{id}/entitlements"
45
+
46
+ get(path)
47
+ end
48
+
49
+
50
+ # Retrieve users for this account
51
+ #
52
+ # List all user objects attached to this account.
53
+ # A user represents one person with access privileges to make API calls and work with a specific account.
54
+ #
55
+ # Search for specific objects using the criteria in the `$filter` parameter; full documentation is available on [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/) .
56
+ # Paginate your results using the `$top`, `$skip`, and `$orderby` parameters.
57
+ #
58
+ # @param int accountId The accountID of the user you wish to list.
59
+ # @param string include A comma separated list of child objects to return underneath the primary object.
60
+ # @param string filter A filter statement to identify specific records to retrieve. For more information on filtering, see [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/) .
61
+ # @param int top If nonzero, return no more than this number of results. Used with $skip to provide pagination for large datasets.
62
+ # @param int skip If nonzero, skip this number of results before returning data. Used with $top to provide pagination for large datasets.
63
+ # @param string orderBy A comma separated list of sort statements in the format `(fieldname) [ASC|DESC]`, for example `id ASC`.
64
+ # @return FetchResult
65
+ def list_users_by_account(accountId, options={})
66
+ path = "/api/v2/accounts/#{accountId}/users"
67
+
68
+ get(path, options)
69
+ end
70
+
71
+
72
+ # Retrieve all users
73
+ #
74
+ # Get multiple user objects across all accounts.
75
+ # A user represents one person with access privileges to make API calls and work with a specific account.
76
+ #
77
+ # Search for specific objects using the criteria in the `$filter` parameter; full documentation is available on [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/) .
78
+ # Paginate your results using the `$top`, `$skip`, and `$orderby` parameters.
79
+ #
80
+ # @param string include A comma separated list of child objects to return underneath the primary object.
81
+ # @param string filter A filter statement to identify specific records to retrieve. For more information on filtering, see [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/) .
82
+ # @param int top If nonzero, return no more than this number of results. Used with $skip to provide pagination for large datasets.
83
+ # @param int skip If nonzero, skip this number of results before returning data. Used with $top to provide pagination for large datasets.
84
+ # @param string orderBy A comma separated list of sort statements in the format `(fieldname) [ASC|DESC]`, for example `id ASC`.
85
+ # @return FetchResult
86
+ def query_users(options={})
87
+ path = "/api/v2/users"
88
+
89
+ get(path, options)
90
+ end
91
+
92
+
93
+ # Update a single user
94
+ #
95
+ # Replace the existing user object at this URL with an updated object.
96
+ # A user represents one person with access privileges to make API calls and work with a specific account.
97
+ # All data from the existing object will be replaced with data in the object you PUT.
98
+ # To set a field's value to null, you may either set its value to null or omit that field from the object you post.
99
+ #
100
+ # @param int id The ID of the user you wish to update.
101
+ # @param int accountId The accountID of the user you wish to update.
102
+ # @param UserModel model The user object you wish to update.
103
+ # @return UserModel
104
+ def update_user(id, accountId, model)
105
+ path = "/api/v2/accounts/#{accountId}/users/#{id}"
106
+
107
+ put(path, model)
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,52 @@
1
+ module AvaTax
2
+ class Client
3
+ module Utilities
4
+
5
+
6
+ # Checks if the current user is subscribed to a specific service
7
+ #
8
+ # Returns a subscription object for the current account, or 404 Not Found if this subscription is not enabled for this account.
9
+ # This API call is intended to allow you to identify whether you have the necessary account configuration to access certain
10
+ # features of AvaTax, and would be useful in debugging access privilege problems.
11
+ #
12
+ # @param string serviceTypeId The service to check (See ServiceTypeId::* for a list of allowable values)
13
+ # @return SubscriptionModel
14
+ def get_my_subscription(serviceTypeId)
15
+ path = "/api/v2/utilities/subscriptions/#{serviceTypeId}"
16
+
17
+ get(path)
18
+ end
19
+
20
+
21
+ # List all services to which the current user is subscribed
22
+ #
23
+ # Returns the list of all subscriptions enabled for the current account.
24
+ # This API is intended to help you determine whether you have the necessary subscription to use certain API calls
25
+ # within AvaTax.
26
+ #
27
+ # @return FetchResult
28
+ def list_my_subscriptions()
29
+ path = "/api/v2/utilities/subscriptions"
30
+
31
+ get(path)
32
+ end
33
+
34
+
35
+ # Tests connectivity and version of the service
36
+ #
37
+ # This API helps diagnose connectivity problems between your application and AvaTax; you may call this API even
38
+ # if you do not have verified connection credentials.
39
+ # The results of this API call will help you determine whether your computer can contact AvaTax via the network,
40
+ # whether your authentication credentials are recognized, and the roundtrip time it takes to communicate with
41
+ # AvaTax.
42
+ #
43
+ # @return PingResultModel
44
+ def ping()
45
+ path = "/api/v2/utilities/ping"
46
+
47
+ get(path)
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -1,29 +1,64 @@
1
- require 'singleton'
1
+ require 'faraday'
2
+ require File.expand_path('../version', __FILE__)
2
3
 
3
4
  module AvaTax
4
- class Configuration
5
- include Singleton
6
-
7
- def initialize
8
- @account_number = ENV['AVATAX_ACCOUNT_NUMBER'] || " "
9
- @license_key = ENV['AVATAX_LICENSE_KEY'] || " "
10
- @service_url = ENV['AVATAX_SERVICE_URL'] || " "
11
- super
5
+ module Configuration
6
+
7
+ VALID_OPTIONS_KEYS = [
8
+ :app_name,
9
+ :app_version,
10
+ :machine_name,
11
+ :environment,
12
+ :endpoint,
13
+ :user_agent,
14
+ :username,
15
+ :password,
16
+ :connection_options,
17
+ :logger,
18
+ :proxy,
19
+ ].freeze
20
+
21
+ DEFAULT_APP_NAME = nil
22
+ DEFAULT_APP_VERSION = nil
23
+ DEFAULT_MACHINE_NAME = nil
24
+ DEFAULT_ENDPOINT = 'https://rest.avatax.com'
25
+ DEFAULT_USER_AGENT = "AvaTax Ruby Gem #{AvaTax::VERSION}".freeze
26
+ DEFAULT_USERNAME = nil
27
+ DEFAULT_PASSWORD = nil
28
+ DEFAULT_CONNECTION_OPTIONS = {}
29
+ DEFAULT_LOGGER = false
30
+ DEFAULT_PROXY = nil
31
+
32
+ attr_accessor *VALID_OPTIONS_KEYS
33
+
34
+ # Reset config values when extended
35
+ def self.extended(base)
36
+ base.reset
12
37
  end
13
38
 
14
- def account_number(acct_num = nil)
15
- return @account_number if @account_number and acct_num.nil?
16
- @account_number = acct_num.to_s
39
+ # Allow configuration options to be set in a block
40
+ def configure
41
+ yield self
17
42
  end
18
43
 
19
- def license_key(license = nil)
20
- return @license_key if @license_key and license.nil?
21
- @license_key = license
44
+ def options
45
+ VALID_OPTIONS_KEYS.inject({}) do |option, key|
46
+ option.merge!(key => send(key))
47
+ end
22
48
  end
23
49
 
24
- def service_url(url = nil)
25
- return @service_url if @service_url and url.nil?
26
- @service_url = url
50
+ def reset
51
+ self.app_name = DEFAULT_APP_NAME
52
+ self.app_version = DEFAULT_APP_VERSION
53
+ self.machine_name = DEFAULT_MACHINE_NAME
54
+ self.endpoint = DEFAULT_ENDPOINT
55
+ self.user_agent = DEFAULT_USER_AGENT
56
+ self.username = DEFAULT_USERNAME
57
+ self.password = DEFAULT_PASSWORD
58
+ self.connection_options = DEFAULT_CONNECTION_OPTIONS
59
+ self.logger = DEFAULT_LOGGER
60
+ self.proxy = DEFAULT_PROXY
27
61
  end
62
+
28
63
  end
29
64
  end
@@ -0,0 +1,28 @@
1
+ require 'faraday_middleware'
2
+
3
+ module AvaTax
4
+
5
+ module Connection
6
+ private
7
+
8
+ def connection
9
+ options = {
10
+ :headers => {'Accept' => "application/json; charset=utf-8", 'User-Agent' => user_agent},
11
+ :url => endpoint,
12
+ :proxy => proxy,
13
+ }.merge(connection_options)
14
+
15
+ c = Faraday::Connection.new(options)
16
+ if logger
17
+ c.response :logger do |logger|
18
+ logger.filter(/(Authorization\:\ \"Basic\ )(\w+)\=/, '\1[REMOVED]')
19
+ end
20
+ end
21
+ c.use Faraday::Request::UrlEncoded
22
+ c.use Faraday::Response::ParseJson
23
+ c.basic_auth(username, password)
24
+
25
+ c
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ require 'hashie'
2
+
3
+ module AvaTax
4
+ module Request
5
+
6
+ def get(path, options={})
7
+ request(:get, path, options)
8
+ end
9
+
10
+ def post(path, options={})
11
+ request(:post, path, options)
12
+ end
13
+
14
+ def put(path, options={})
15
+ request(:put, path, options)
16
+ end
17
+
18
+ def delete(path, options={})
19
+ request(:delete, path, options)
20
+ end
21
+
22
+ def request(method, path, options)
23
+ response = connection.send(method) do |request|
24
+ case method
25
+ when :get, :delete
26
+ request.url(URI.encode(path), options)
27
+ when :post, :put
28
+ request.path = URI.encode(path)
29
+ puts "BODY", options
30
+ request.body = options unless options.empty?
31
+ end
32
+ end
33
+
34
+ ::Hashie::Mash.new response.body
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module AvaTax
2
+ VERSION = '17.5.0'.freeze unless defined?(::AvaTax::VERSION)
3
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe AvaTax::Client do
4
+ before do
5
+ @client = AvaTax::Client.new()
6
+ end
7
+
8
+ describe ".accounts" do
9
+ before do
10
+ stub_get("/api/v2/accounts").
11
+ to_return(:body => fixture("accounts.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
+ end
13
+
14
+ it "should get the correct resource" do
15
+ @client.query_accounts()
16
+ expect(a_get("/api/v2/accounts")).to have_been_made
17
+ end
18
+
19
+ it "should return an array of accounts" do
20
+ accounts = @client.query_accounts
21
+ expect(accounts).to be_a Object
22
+ expect(accounts['value'].first['id']).to equal 200000251
23
+ expect(accounts.value.first.id).to equal 200000251
24
+ end
25
+ end
26
+ end