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
data/README.md CHANGED
@@ -1,61 +1,63 @@
1
- avatax.rb
2
- =====================
3
- [Other Samples](http://developer.avalara.com/api-docs/api-sample-code)
4
-
5
- This is a Ruby client library for the [AvaTax REST API](http://developer.avalara.com/api-docs/rest)
6
- methods:
7
- [tax/get POST](http://developer.avalara.com/api-docs/rest/tax/post/),
8
- [tax/get GET](http://developer.avalara.com/api-docs/rest/tax/get),
9
- [tax/cancel POST](http://developer.avalara.com/api-docs/rest/tax/cancel), and
10
- [address/validate GET](http://developer.avalara.com/api-docs/rest/address-validation).
11
-
12
- For more information on the use of these methods and the AvaTax product, please
13
- visit our [developer site](http://developer.avalara.com/) or [homepage](http://www.avalara.com/)
14
-
15
- Dependencies
16
- -----------
17
- - Ruby 1.9.2 or later
18
- - [Bundler](http://bundler.io)
19
-
20
- Requirements
21
- ----------
22
- - Add the `avatax` gem to your Gemfile with `gem 'avatax'`
23
- - Run `bundle install` to retrieve `avatax` and all its dependencies
24
- - Authentication requires an valid **Account Number** and **License Key**. If you do not have an AvaTax account, a free trial account can be acquired through our [developer site](http://developer.avalara.com/api-get-started)
25
- - Specify your authentication credentials as
26
- - environment variables,
27
- - YAML file (see `credentials.yml.example`), or
28
- - in source
29
-
30
- Credentials as environment variables
31
- ------------------------------------
32
- ```shell
33
- $ AVATAX_ACCOUNT_NUMBER=1234567890 AVATAX_LICENSE_KEY=A1B2C3D4E5F6G7H8 AVATAX_SERVICE_URL=https://development.avalara.net bundle exec ruby examples/PingTest.rb
34
- ```
35
-
36
- Credentials from YAML file
37
- --------------------------
38
- ```ruby
39
- AvaTax.configure_from 'credentials.yml.example'
40
- ```
41
-
42
- Credentials in source
43
- ---------------------
44
- ```ruby
45
- AvaTax.configure do
46
- account_number '1234567890'
47
- license_key 'A1B2C3D4E5F6G7H8'
48
- service_url 'https://development.avalara.net'
49
- end
50
- ```
51
-
52
- Examples
53
- --------
54
-
55
- | Filename | Description |
56
- | :----------------- | :---------- |
57
- | CancelTaxTest.rb | Demonstrates [AvaTax::TaxService.cancel](http://developer.avalara.com/api-docs/rest/tax/cancel) used to [void a document](http://developer.avalara.com/api-docs/api-reference/canceltax) |
58
- | EstimateTaxTest.rb | Demonstrates the [AvaTax::TaxService.estimate](http://developer.avalara.com/api-docs/rest/tax/get) method used for product- and line- indifferent tax estimates. |
59
- | GetTaxTest.rb | Demonstrates the [AvaTax::TaxService.get](http://developer.avalara.com/api-docs/rest/tax/post) method used for product- and line- specific [calculation](http://developer.avalara.com/api-docs/api-reference/gettax). **NOTE:** This will generate a new transaction/document each time. |
60
- | PingTest.rb | Uses a hardcoded `AvaTax::TaxService.estimate` call to test connectivity and credential information. |
61
- | ValidateTest.rb | Demonstrates the [AvaTax::AddressService.validate](http://developer.avalara.com/api-docs/rest/address-validation) method to [normalize an address](http://developer.avalara.com/api-docs/api-reference/address-validation). |
1
+ The AvaTax Ruby Gem
2
+ ====================
3
+ A Ruby wrapper for the AvaTax REST V2 APIs
4
+
5
+ Installation
6
+ ------------
7
+ gem install avatax (coming soon)
8
+
9
+ AvaTax REST and Search APIs
10
+ ------------------------------
11
+ Our [developer site](https://developer.avalara.com/) documents all the AvaTax REST and other APIs. Subscribe to the [RSS feed](developer.avalara.com/feed.xml) to stay up to date on the lates news and announcements.
12
+
13
+
14
+ Blog
15
+ ----------------------------
16
+ The [Developer Blog](https://developer.avalara.com/blog/) features news and important announcements about the AvaTax Platform and SDKs. You will also find tutorials and best practices to help you build great platform integrations.
17
+
18
+ Contributing
19
+ ------------
20
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
21
+
22
+ Here are some ways *you* can contribute:
23
+
24
+ * by using alpha, beta, and prerelease versions
25
+ * by reporting bugs
26
+ * by suggesting new features
27
+ * by writing or editing documentation
28
+ * by writing specifications
29
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
30
+ * by refactoring code
31
+ * by closing [issues](https://github.com/avadev/AvaTax-REST-V2-Ruby-SDK/issues)
32
+ * by reviewing patches
33
+
34
+
35
+ Submitting an Issue
36
+ -------------------
37
+ We use the [GitHub issue tracker](https://github.com/avadev/AvaTax-REST-V2-Ruby-SDK/issues) to track bugs and
38
+ features. Before submitting a bug report or feature request, check to make sure it hasn't already
39
+ been submitted. You can indicate support for an existing issue by voting it up. When submitting a
40
+ bug report, please include a [Gist](http://gist.github.com/) that includes a stack trace and any
41
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
42
+ operating system. Ideally, a bug report should include a pull request with failing specs.
43
+
44
+ Submitting a Pull Request
45
+ -------------------------
46
+ 1. Fork the project.
47
+ 2. Create a topic branch.
48
+ 3. Implement your feature or bug fix.
49
+ 4. Add documentation for your feature or bug fix.
50
+ 5. Run <tt>rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
51
+ 6. Add specs for your feature or bug fix.
52
+ 7. Commit and push your changes.
53
+ 8. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
54
+
55
+ Build Status
56
+ ------------
57
+ [![Build Status](https://travis-ci.org/avadev/AvaTax-REST-V2-Ruby-SDK.svg?branch=master)](https://travis-ci.org/avadev/AvaTax-REST-V2-Ruby-SDK)
58
+
59
+ Copyright
60
+ ---------
61
+ Copyright (c) 2017, Avalara, Inc. All rights reserved.
62
+ By contributing to AvaTax Ruby Gem, you agree that your contributions will be licensed under its Apache License.
63
+ See [LICENSE](https://github.com/avadev/AvaTax-REST-V2-Ruby-SDK/) for details.
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ rescue LoadError
8
+ # no rspec available
9
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path('../lib/avatax/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.add_development_dependency('rake', '~> 12.0.0')
5
+ s.add_development_dependency('rspec', '~> 3.5.0')
6
+ s.add_development_dependency('webmock', '>= 2.0.0')
7
+ s.add_runtime_dependency('faraday', '>= 0.10')
8
+ s.add_runtime_dependency('faraday_middleware', '>= 0.10')
9
+ s.add_runtime_dependency('multi_json', '>= 1.0.3')
10
+ s.add_runtime_dependency('hashie', '>= 3.0.0')
11
+ s.authors = ["Marcus Vorwaller"]
12
+ s.description = %q{A Ruby wrapper for the AvaTax REST and Search APIs}
13
+ s.post_install_message =<<eos
14
+ ********************************************************************************
15
+
16
+ AvaTax REST API
17
+ ------------------------------
18
+ Our developer site documents the AvaTax REST API.
19
+ (http://developer.avatax.com).
20
+ Blog
21
+ ----------------------------
22
+ The Developer Blog is a great place to learn more about the API and AvaTax integrations
23
+ Subscribe to the RSS feed be notified of new posts:
24
+ (http://developer.avatax.com/blog).
25
+
26
+ ********************************************************************************
27
+ eos
28
+ s.email = ['marcus.vorwaller@avalara.com']
29
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
30
+ s.files = `git ls-files`.split("\n")
31
+ s.homepage = 'https://github.com/avadev/AvaTax-REST-V2-Ruby-SDK'
32
+ s.name = 'avatax'
33
+ s.platform = Gem::Platform::RUBY
34
+ s.require_paths = ['lib']
35
+ s.required_rubygems_version = Gem::Requirement.new('>= 2.0.0') if s.respond_to? :required_rubygems_version=
36
+ s.summary = %q{Ruby wrapper for the AvaTax API}
37
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
38
+ s.version = AvaTax::VERSION.dup
39
+ end
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ require File.expand_path('../../lib/avatax', __FILE__)
3
+
4
+ credentials = YAML.load_file(File.expand_path('../credentials.yaml', __FILE__))
5
+
6
+ AvaTax.configure do |config|
7
+ config.endpoint = credentials['endpoint']
8
+ config.username = credentials['username']
9
+ config.password = credentials['password']
10
+ end
11
+
12
+ @client = AvaTax::Client.new(:logger => true)
13
+
14
+ puts @client.query_companies
@@ -0,0 +1,5 @@
1
+ # Copy this file as credentials.yaml and update the values to match your account
2
+ ---
3
+ endpoint: https://sandbox-rest.avatax.com
4
+ username: 'example_user'
5
+ password: 'abcd1234'
@@ -1,20 +1,26 @@
1
- require_relative 'avatax/configuration'
1
+ require File.expand_path('../avatax/configuration', __FILE__)
2
+ require File.expand_path('../avatax/api', __FILE__)
3
+ require File.expand_path('../avatax/client', __FILE__)
4
+
2
5
  module AvaTax
6
+ extend Configuration
7
+
8
+ # Alias for Avatax::Client.new
9
+ #
10
+ # @return [Avatax::Client]
11
+ def self.client(options={})
12
+ AvaTax::Client.new(options)
13
+ end
3
14
 
4
- def self.configure(&block)
5
- Configuration.instance.instance_eval(&block)
15
+ # Delegate to AvaTax::Client
16
+ def self.method_missing(method, *args, &block)
17
+ return super unless client.respond_to?(method)
18
+ client.send(method, *args, &block)
6
19
  end
7
20
 
8
- def self.configure_from(yaml_file)
9
- require 'yaml'
10
- config = YAML.load_file yaml_file
11
- configure do
12
- account_number config['account_number']
13
- license_key config['license_key']
14
- service_url config['service_url']
15
- end
21
+ # Delegate to AvaTax::Client
22
+ def self.respond_to?(method, include_all=false)
23
+ return client.respond_to?(method, include_all) || super
16
24
  end
17
25
 
18
26
  end
19
- require_relative 'avatax/tax_service'
20
- require_relative 'avatax/address_service'
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../connection', __FILE__)
2
+ require File.expand_path('../request', __FILE__)
3
+
4
+ module AvaTax
5
+ class API
6
+
7
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
8
+
9
+ def initialize(options={})
10
+ options = AvaTax.options.merge(options)
11
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
12
+ send("#{key}=", options[key])
13
+ end
14
+ end
15
+
16
+ def config
17
+ conf = {}
18
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
19
+ conf[key] = send key
20
+ end
21
+ conf
22
+ end
23
+
24
+ include Connection
25
+ include Request
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ module AvaTax
2
+ class Client < API
3
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
4
+
5
+ include AvaTax::Client::Accounts
6
+ include AvaTax::Client::Addresses
7
+ include AvaTax::Client::Batches
8
+ include AvaTax::Client::Companies
9
+ include AvaTax::Client::Contacts
10
+ include AvaTax::Client::Definitions
11
+ include AvaTax::Client::FilingCalendars
12
+ include AvaTax::Client::Filings
13
+ include AvaTax::Client::Free
14
+ include AvaTax::Client::FundingRequests
15
+ include AvaTax::Client::Items
16
+ include AvaTax::Client::JurisdictionOverrides
17
+ include AvaTax::Client::Locations
18
+ include AvaTax::Client::Nexus
19
+ include AvaTax::Client::Notices
20
+ include AvaTax::Client::Onboarding
21
+ include AvaTax::Client::PointOfSale
22
+ include AvaTax::Client::Registrar
23
+ include AvaTax::Client::Settings
24
+ include AvaTax::Client::Subscriptions
25
+ include AvaTax::Client::TaxCodes
26
+ include AvaTax::Client::TaxRules
27
+ include AvaTax::Client::Transactions
28
+ include AvaTax::Client::Upcs
29
+ include AvaTax::Client::Users
30
+ include AvaTax::Client::Utilities
31
+ end
32
+ end
@@ -0,0 +1,110 @@
1
+ module AvaTax
2
+ class Client
3
+ module Accounts
4
+
5
+
6
+ # Reset this account's license key
7
+ #
8
+ # Resets the existing license key for this account to a new key.
9
+ # To reset your account, you must specify the ID of the account you wish to reset and confirm the action.
10
+ # Resetting a license key cannot be undone. Any previous license keys will immediately cease to work when a new key is created.
11
+ #
12
+ # @param int id The ID of the account you wish to update.
13
+ # @param ResetLicenseKeyModel model A request confirming that you wish to reset the license key of this account.
14
+ # @return LicenseKeyModel
15
+ def account_reset_license_key(id, model)
16
+ path = "/api/v2/accounts/#{id}/resetlicensekey"
17
+
18
+ post(path, model)
19
+ end
20
+
21
+
22
+ # Activate an account by accepting terms and conditions
23
+ #
24
+ # Activate the account specified by the unique accountId number.
25
+ #
26
+ # This activation request can only be called by account administrators. You must indicate
27
+ # that you have read and accepted Avalara's terms and conditions to call this API.
28
+ #
29
+ # If you have not read or accepted the terms and conditions, this API call will return the
30
+ # unchanged account model.
31
+ #
32
+ # @param int id The ID of the account to activate
33
+ # @param ActivateAccountModel model The activation request
34
+ # @return AccountModel
35
+ def activate_account(id, model)
36
+ path = "/api/v2/accounts/#{id}/activate"
37
+
38
+ post(path, model)
39
+ end
40
+
41
+
42
+ # Retrieve a single account
43
+ #
44
+ # Get the account object identified by this URL.
45
+ # You may use the '$include' parameter to fetch additional nested data:
46
+ #
47
+ # * Subscriptions
48
+ # * Users
49
+ #
50
+ # @param int id The ID of the account to retrieve
51
+ # @param string include A comma separated list of child objects to return underneath the primary object.
52
+ # @return AccountModel
53
+ def get_account(id, options={})
54
+ path = "/api/v2/accounts/#{id}"
55
+
56
+ get(path, options)
57
+ end
58
+
59
+
60
+ # Get configuration settings for this account
61
+ #
62
+ # Retrieve a list of all configuration settings tied to this account.
63
+ #
64
+ # Configuration settings provide you with the ability to control features of your account and of your
65
+ # tax software. The category names `TaxServiceConfig` and `AddressServiceConfig` are reserved for
66
+ # Avalara internal software configuration values; to store your own account-level settings, please
67
+ # create a new category name that begins with `X-`, for example, `X-MyCustomCategory`.
68
+ #
69
+ # Account settings are permanent settings that cannot be deleted. You can set the value of an
70
+ # account setting to null if desired.
71
+ #
72
+ # Avalara-based account settings for `TaxServiceConfig` and `AddressServiceConfig` affect your account's
73
+ # tax calculation and address resolution, and should only be changed with care.
74
+ #
75
+ # @param int id
76
+ # @return AccountConfigurationModel[]
77
+ def get_account_configuration(id)
78
+ path = "/api/v2/accounts/#{id}/configuration"
79
+
80
+ get(path)
81
+ end
82
+
83
+
84
+ # Change configuration settings for this account
85
+ #
86
+ # Update configuration settings tied to this account.
87
+ #
88
+ # Configuration settings provide you with the ability to control features of your account and of your
89
+ # tax software. The category names `TaxServiceConfig` and `AddressServiceConfig` are reserved for
90
+ # Avalara internal software configuration values; to store your own account-level settings, please
91
+ # create a new category name that begins with `X-`, for example, `X-MyCustomCategory`.
92
+ #
93
+ # Account settings are permanent settings that cannot be deleted. You can set the value of an
94
+ # account setting to null if desired.
95
+ #
96
+ # Avalara-based account settings for `TaxServiceConfig` and `AddressServiceConfig` affect your account's
97
+ # tax calculation and address resolution, and should only be changed with care.
98
+ #
99
+ # @param int id
100
+ # @param AccountConfigurationModel[] model
101
+ # @return AccountConfigurationModel[]
102
+ def set_account_configuration(id, model)
103
+ path = "/api/v2/accounts/#{id}/configuration"
104
+
105
+ post(path, model)
106
+ end
107
+
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,52 @@
1
+ module AvaTax
2
+ class Client
3
+ module Addresses
4
+
5
+
6
+ # Retrieve geolocation information for a specified address
7
+ #
8
+ # Resolve an address against Avalara's address-validation system. If the address can be resolved, this API
9
+ # provides the latitude and longitude of the resolved location. The value 'resolutionQuality' can be used
10
+ # to identify how closely this address can be located. If the address cannot be clearly located, use the
11
+ # 'messages' structure to learn more about problems with this address.
12
+ # This is the same API as the POST /api/v2/addresses/resolve endpoint.
13
+ # Both verbs are supported to provide for flexible implementation.
14
+ #
15
+ # @param string line1 Line 1
16
+ # @param string line2 Line 2
17
+ # @param string line3 Line 3
18
+ # @param string city City
19
+ # @param string region State / Province / Region
20
+ # @param string postalCode Postal Code / Zip Code
21
+ # @param string country Two character ISO 3166 Country Code (see /api/v2/definitions/countries for a full list)
22
+ # @param string textCase selectable text case for address validation (See TextCase::* for a list of allowable values)
23
+ # @param float latitude Geospatial latitude measurement
24
+ # @param float longitude Geospatial longitude measurement
25
+ # @return AddressResolutionModel
26
+ def resolve_address(options={})
27
+ path = "/api/v2/addresses/resolve"
28
+
29
+ get(path, options)
30
+ end
31
+
32
+
33
+ # Retrieve geolocation information for a specified address
34
+ #
35
+ # Resolve an address against Avalara's address-validation system. If the address can be resolved, this API
36
+ # provides the latitude and longitude of the resolved location. The value 'resolutionQuality' can be used
37
+ # to identify how closely this address can be located. If the address cannot be clearly located, use the
38
+ # 'messages' structure to learn more about problems with this address.
39
+ # This is the same API as the GET /api/v2/addresses/resolve endpoint.
40
+ # Both verbs are supported to provide for flexible implementation.
41
+ #
42
+ # @param AddressValidationInfo model The address to resolve
43
+ # @return AddressResolutionModel
44
+ def resolve_address_post(model)
45
+ path = "/api/v2/addresses/resolve"
46
+
47
+ post(path, model)
48
+ end
49
+
50
+ end
51
+ end
52
+ end