avatax 22.5.0 → 22.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +31 -0
- data/.gitignore +55 -55
- data/.rspec +1 -1
- data/.vs/VSWorkspaceState.json +5 -5
- data/.yardopts +4 -4
- data/Gemfile +2 -2
- data/LICENSE +201 -201
- data/README.md +98 -98
- data/Rakefile +9 -9
- data/avatax.gemspec +38 -38
- data/example/avatax.rb +47 -47
- data/example/credentials.example.yaml +5 -5
- data/lib/avatax/api.rb +27 -27
- data/lib/avatax/client/accounts.rb +22 -22
- data/lib/avatax/client/addresses.rb +4 -4
- data/lib/avatax/client/advancedrules.rb +5 -5
- data/lib/avatax/client/avafileforms.rb +7 -7
- data/lib/avatax/client/batches.rb +16 -16
- data/lib/avatax/client/certexpressinvites.rb +6 -6
- data/lib/avatax/client/certificates.rb +30 -30
- data/lib/avatax/client/companies.rb +47 -45
- data/lib/avatax/client/compliance.rb +1 -1
- data/lib/avatax/client/contacts.rb +12 -12
- data/lib/avatax/client/customers.rb +26 -26
- data/lib/avatax/client/datasources.rb +12 -12
- data/lib/avatax/client/definitions.rb +90 -75
- data/lib/avatax/client/distancethresholds.rb +12 -12
- data/lib/avatax/client/ecms.rb +73 -73
- data/lib/avatax/client/ecommercetoken.rb +4 -4
- data/lib/avatax/client/errortransactions.rb +61 -61
- data/lib/avatax/client/firmclientlinkages.rb +17 -17
- data/lib/avatax/client/free.rb +1 -1
- data/lib/avatax/client/fundingrequests.rb +10 -6
- data/lib/avatax/client/items.rb +64 -64
- data/lib/avatax/client/jurisdictionoverrides.rb +12 -12
- data/lib/avatax/client/locations.rb +24 -24
- data/lib/avatax/client/multidocument.rb +20 -20
- data/lib/avatax/client/nexus.rb +30 -30
- data/lib/avatax/client/notices.rb +8 -8
- data/lib/avatax/client/notifications.rb +6 -6
- data/lib/avatax/client/onboarding.rb +55 -55
- data/lib/avatax/client/pointofsale.rb +21 -21
- data/lib/avatax/client/provisioning.rb +4 -4
- data/lib/avatax/client/registrar.rb +19 -19
- data/lib/avatax/client/reports.rb +7 -7
- data/lib/avatax/client/settings.rb +12 -12
- data/lib/avatax/client/subscriptions.rb +6 -6
- data/lib/avatax/client/taxcodes.rb +12 -12
- data/lib/avatax/client/taxcontent.rb +8 -8
- data/lib/avatax/client/taxprofiles.rb +42 -42
- data/lib/avatax/client/taxrules.rb +12 -12
- data/lib/avatax/client/transactions.rb +41 -41
- data/lib/avatax/client/upcs.rb +12 -12
- data/lib/avatax/client/userdefinedfields.rb +6 -6
- data/lib/avatax/client/users.rb +16 -16
- data/lib/avatax/client/utilities.rb +3 -3
- data/lib/avatax/client.rb +37 -37
- data/lib/avatax/configuration.rb +76 -76
- data/lib/avatax/connection.rb +53 -53
- data/lib/avatax/request.rb +51 -51
- data/lib/avatax/version.rb +3 -3
- data/lib/avatax.rb +26 -26
- data/spec/avatax/client/accounts_spec.rb +13 -13
- data/spec/avatax/client/transactions_spec.rb +80 -80
- data/spec/avatax/request_spec.rb +25 -25
- data/spec/avatax_spec.rb +45 -45
- data/spec/credentials.yaml.example +4 -4
- data/spec/fixtures/accounts.json +15 -15
- data/spec/spec_helper.rb +27 -27
- metadata +6 -6
- data/.travis.yml +0 -19
@@ -17,7 +17,7 @@ module AvaTax
|
|
17
17
|
# @param serviceTypeId [String] The service to check
|
18
18
|
# @return [Object]
|
19
19
|
def get_my_subscription(serviceTypeId) path = "/api/v2/utilities/subscriptions/#{serviceTypeId}"
|
20
|
-
get(path, {}, "22.
|
20
|
+
get(path, {}, "22.8.0") end
|
21
21
|
|
22
22
|
# List all services to which the current user is subscribed
|
23
23
|
#
|
@@ -32,7 +32,7 @@ module AvaTax
|
|
32
32
|
# Swagger Name: AvaTaxClient
|
33
33
|
# @return [FetchResult]
|
34
34
|
def list_my_subscriptions() path = "/api/v2/utilities/subscriptions"
|
35
|
-
get(path, {}, "22.
|
35
|
+
get(path, {}, "22.8.0") end
|
36
36
|
|
37
37
|
# Tests connectivity and version of the service
|
38
38
|
#
|
@@ -59,7 +59,7 @@ module AvaTax
|
|
59
59
|
# Swagger Name: AvaTaxClient
|
60
60
|
# @return [Object]
|
61
61
|
def ping() path = "/api/v2/utilities/ping"
|
62
|
-
get(path, {}, "22.
|
62
|
+
get(path, {}, "22.8.0") end
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
data/lib/avatax/client.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
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::CertExpressInvites
|
9
|
-
include AvaTax::Client::Companies
|
10
|
-
include AvaTax::Client::Contacts
|
11
|
-
include AvaTax::Client::Customers
|
12
|
-
include AvaTax::Client::Definitions
|
13
|
-
include AvaTax::Client::FilingCalendars
|
14
|
-
include AvaTax::Client::Filings
|
15
|
-
include AvaTax::Client::Free
|
16
|
-
include AvaTax::Client::FundingRequests
|
17
|
-
include AvaTax::Client::Items
|
18
|
-
include AvaTax::Client::JurisdictionOverrides
|
19
|
-
include AvaTax::Client::Locations
|
20
|
-
include AvaTax::Client::Nexus
|
21
|
-
include AvaTax::Client::Notices
|
22
|
-
include AvaTax::Client::Onboarding
|
23
|
-
include AvaTax::Client::PointOfSale
|
24
|
-
include AvaTax::Client::Registrar
|
25
|
-
include AvaTax::Client::Settings
|
26
|
-
include AvaTax::Client::Subscriptions
|
27
|
-
include AvaTax::Client::TaxCodes
|
28
|
-
include AvaTax::Client::TaxContent
|
29
|
-
include AvaTax::Client::TaxRules
|
30
|
-
include AvaTax::Client::Transactions
|
31
|
-
include AvaTax::Client::Upcs
|
32
|
-
include AvaTax::Client::Users
|
33
|
-
include AvaTax::Client::Utilities
|
34
|
-
include AvaTax::Client::ShippingVerification
|
35
|
-
include AvaTax::Client::AgeVerification
|
36
|
-
end
|
37
|
-
end
|
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::CertExpressInvites
|
9
|
+
include AvaTax::Client::Companies
|
10
|
+
include AvaTax::Client::Contacts
|
11
|
+
include AvaTax::Client::Customers
|
12
|
+
include AvaTax::Client::Definitions
|
13
|
+
include AvaTax::Client::FilingCalendars
|
14
|
+
include AvaTax::Client::Filings
|
15
|
+
include AvaTax::Client::Free
|
16
|
+
include AvaTax::Client::FundingRequests
|
17
|
+
include AvaTax::Client::Items
|
18
|
+
include AvaTax::Client::JurisdictionOverrides
|
19
|
+
include AvaTax::Client::Locations
|
20
|
+
include AvaTax::Client::Nexus
|
21
|
+
include AvaTax::Client::Notices
|
22
|
+
include AvaTax::Client::Onboarding
|
23
|
+
include AvaTax::Client::PointOfSale
|
24
|
+
include AvaTax::Client::Registrar
|
25
|
+
include AvaTax::Client::Settings
|
26
|
+
include AvaTax::Client::Subscriptions
|
27
|
+
include AvaTax::Client::TaxCodes
|
28
|
+
include AvaTax::Client::TaxContent
|
29
|
+
include AvaTax::Client::TaxRules
|
30
|
+
include AvaTax::Client::Transactions
|
31
|
+
include AvaTax::Client::Upcs
|
32
|
+
include AvaTax::Client::Users
|
33
|
+
include AvaTax::Client::Utilities
|
34
|
+
include AvaTax::Client::ShippingVerification
|
35
|
+
include AvaTax::Client::AgeVerification
|
36
|
+
end
|
37
|
+
end
|
data/lib/avatax/configuration.rb
CHANGED
@@ -1,76 +1,76 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require File.expand_path('../version', __FILE__)
|
3
|
-
|
4
|
-
module AvaTax
|
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
|
-
:custom_logger,
|
19
|
-
:custom_logger_options,
|
20
|
-
:proxy,
|
21
|
-
:faraday_response,
|
22
|
-
:response_big_decimal_conversion
|
23
|
-
].freeze
|
24
|
-
|
25
|
-
DEFAULT_APP_NAME = nil
|
26
|
-
DEFAULT_APP_VERSION = nil
|
27
|
-
DEFAULT_MACHINE_NAME = nil
|
28
|
-
DEFAULT_ENDPOINT = 'https://rest.avatax.com'
|
29
|
-
DEFAULT_USER_AGENT = "AvaTax Ruby Gem #{AvaTax::VERSION}".freeze
|
30
|
-
DEFAULT_USERNAME = nil
|
31
|
-
DEFAULT_PASSWORD = nil
|
32
|
-
DEFAULT_CONNECTION_OPTIONS = {request: {timeout: 1200}} # timeout in seconds
|
33
|
-
DEFAULT_LOGGER = false
|
34
|
-
DEFAULT_CUSTOM_LOGGER = nil
|
35
|
-
DEFAULT_CUSTOM_LOGGER_OPTIONS = {}
|
36
|
-
DEFAULT_PROXY = nil
|
37
|
-
DEFAULT_FARADAY_RESPONSE = false
|
38
|
-
DEFAULT_RESPONSE_BIG_DECIMAL_CONVERSION = false
|
39
|
-
|
40
|
-
attr_accessor *VALID_OPTIONS_KEYS
|
41
|
-
|
42
|
-
# Reset config values when extended
|
43
|
-
def self.extended(base)
|
44
|
-
base.reset
|
45
|
-
end
|
46
|
-
|
47
|
-
# Allow configuration options to be set in a block
|
48
|
-
def configure
|
49
|
-
yield self
|
50
|
-
end
|
51
|
-
|
52
|
-
def options
|
53
|
-
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
54
|
-
option.merge!(key => send(key))
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def reset
|
59
|
-
self.app_name = DEFAULT_APP_NAME
|
60
|
-
self.app_version = DEFAULT_APP_VERSION
|
61
|
-
self.machine_name = DEFAULT_MACHINE_NAME
|
62
|
-
self.endpoint = DEFAULT_ENDPOINT
|
63
|
-
self.user_agent = DEFAULT_USER_AGENT
|
64
|
-
self.username = DEFAULT_USERNAME
|
65
|
-
self.password = DEFAULT_PASSWORD
|
66
|
-
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
67
|
-
self.logger = DEFAULT_LOGGER
|
68
|
-
self.custom_logger = DEFAULT_CUSTOM_LOGGER
|
69
|
-
self.custom_logger_options = DEFAULT_CUSTOM_LOGGER_OPTIONS
|
70
|
-
self.proxy = DEFAULT_PROXY
|
71
|
-
self.faraday_response = DEFAULT_FARADAY_RESPONSE
|
72
|
-
self.response_big_decimal_conversion = DEFAULT_RESPONSE_BIG_DECIMAL_CONVERSION
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
end
|
1
|
+
require 'faraday'
|
2
|
+
require File.expand_path('../version', __FILE__)
|
3
|
+
|
4
|
+
module AvaTax
|
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
|
+
:custom_logger,
|
19
|
+
:custom_logger_options,
|
20
|
+
:proxy,
|
21
|
+
:faraday_response,
|
22
|
+
:response_big_decimal_conversion
|
23
|
+
].freeze
|
24
|
+
|
25
|
+
DEFAULT_APP_NAME = nil
|
26
|
+
DEFAULT_APP_VERSION = nil
|
27
|
+
DEFAULT_MACHINE_NAME = nil
|
28
|
+
DEFAULT_ENDPOINT = 'https://rest.avatax.com'
|
29
|
+
DEFAULT_USER_AGENT = "AvaTax Ruby Gem #{AvaTax::VERSION}".freeze
|
30
|
+
DEFAULT_USERNAME = nil
|
31
|
+
DEFAULT_PASSWORD = nil
|
32
|
+
DEFAULT_CONNECTION_OPTIONS = {request: {timeout: 1200}} # timeout in seconds
|
33
|
+
DEFAULT_LOGGER = false
|
34
|
+
DEFAULT_CUSTOM_LOGGER = nil
|
35
|
+
DEFAULT_CUSTOM_LOGGER_OPTIONS = {}
|
36
|
+
DEFAULT_PROXY = nil
|
37
|
+
DEFAULT_FARADAY_RESPONSE = false
|
38
|
+
DEFAULT_RESPONSE_BIG_DECIMAL_CONVERSION = false
|
39
|
+
|
40
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
41
|
+
|
42
|
+
# Reset config values when extended
|
43
|
+
def self.extended(base)
|
44
|
+
base.reset
|
45
|
+
end
|
46
|
+
|
47
|
+
# Allow configuration options to be set in a block
|
48
|
+
def configure
|
49
|
+
yield self
|
50
|
+
end
|
51
|
+
|
52
|
+
def options
|
53
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
54
|
+
option.merge!(key => send(key))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def reset
|
59
|
+
self.app_name = DEFAULT_APP_NAME
|
60
|
+
self.app_version = DEFAULT_APP_VERSION
|
61
|
+
self.machine_name = DEFAULT_MACHINE_NAME
|
62
|
+
self.endpoint = DEFAULT_ENDPOINT
|
63
|
+
self.user_agent = DEFAULT_USER_AGENT
|
64
|
+
self.username = DEFAULT_USERNAME
|
65
|
+
self.password = DEFAULT_PASSWORD
|
66
|
+
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
67
|
+
self.logger = DEFAULT_LOGGER
|
68
|
+
self.custom_logger = DEFAULT_CUSTOM_LOGGER
|
69
|
+
self.custom_logger_options = DEFAULT_CUSTOM_LOGGER_OPTIONS
|
70
|
+
self.proxy = DEFAULT_PROXY
|
71
|
+
self.faraday_response = DEFAULT_FARADAY_RESPONSE
|
72
|
+
self.response_big_decimal_conversion = DEFAULT_RESPONSE_BIG_DECIMAL_CONVERSION
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
data/lib/avatax/connection.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
require 'faraday_middleware'
|
2
|
-
|
3
|
-
module AvaTax
|
4
|
-
|
5
|
-
module Connection
|
6
|
-
private
|
7
|
-
AUTHORIZATION_FILTER_REGEX = /(Authorization\:\ \"Basic\ )(\w+)\=/
|
8
|
-
REMOVED_LABEL = '\1[REMOVED]'
|
9
|
-
|
10
|
-
def connection
|
11
|
-
client_id = "#{app_name};#{app_version};RubySdk;API_VERSION;#{machine_name}"
|
12
|
-
options = {
|
13
|
-
:headers =>
|
14
|
-
{
|
15
|
-
'Accept' => "application/json; charset=utf-8",
|
16
|
-
'User-Agent' => user_agent,
|
17
|
-
'X-Avalara-Client' => client_id
|
18
|
-
},
|
19
|
-
:url => endpoint,
|
20
|
-
:proxy => proxy
|
21
|
-
}.merge(connection_options)
|
22
|
-
|
23
|
-
Faraday.new(options) do |faraday|
|
24
|
-
if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.2.2') and response_big_decimal_conversion
|
25
|
-
Oj.default_options = {
|
26
|
-
bigdecimal_load: :bigdecimal
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
faraday.response :json, content_type: /\bjson$/
|
31
|
-
faraday.request :basic_auth, username, password
|
32
|
-
|
33
|
-
# TODO: use the following after upgrading to faraday 2.0
|
34
|
-
# see https://github.com/lostisland/faraday/blob/main/docs/middleware/request/authentication.md
|
35
|
-
# faraday.request :authorization, :basic, username, password
|
36
|
-
|
37
|
-
if logger
|
38
|
-
faraday.response :logger do |logger|
|
39
|
-
logger.filter(AUTHORIZATION_FILTER_REGEX, REMOVED_LABEL)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
if custom_logger
|
44
|
-
faraday.response :logger, custom_logger, custom_logger_options do |logger|
|
45
|
-
logger.filter(AUTHORIZATION_FILTER_REGEX, REMOVED_LABEL)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
faraday.adapter Faraday.default_adapter
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
1
|
+
require 'faraday_middleware'
|
2
|
+
|
3
|
+
module AvaTax
|
4
|
+
|
5
|
+
module Connection
|
6
|
+
private
|
7
|
+
AUTHORIZATION_FILTER_REGEX = /(Authorization\:\ \"Basic\ )(\w+)\=/
|
8
|
+
REMOVED_LABEL = '\1[REMOVED]'
|
9
|
+
|
10
|
+
def connection
|
11
|
+
client_id = "#{app_name};#{app_version};RubySdk;API_VERSION;#{machine_name}"
|
12
|
+
options = {
|
13
|
+
:headers =>
|
14
|
+
{
|
15
|
+
'Accept' => "application/json; charset=utf-8",
|
16
|
+
'User-Agent' => user_agent,
|
17
|
+
'X-Avalara-Client' => client_id
|
18
|
+
},
|
19
|
+
:url => endpoint,
|
20
|
+
:proxy => proxy
|
21
|
+
}.merge(connection_options)
|
22
|
+
|
23
|
+
Faraday.new(options) do |faraday|
|
24
|
+
if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.2.2') and response_big_decimal_conversion
|
25
|
+
Oj.default_options = {
|
26
|
+
bigdecimal_load: :bigdecimal
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
faraday.response :json, content_type: /\bjson$/
|
31
|
+
faraday.request :basic_auth, username, password
|
32
|
+
|
33
|
+
# TODO: use the following after upgrading to faraday 2.0
|
34
|
+
# see https://github.com/lostisland/faraday/blob/main/docs/middleware/request/authentication.md
|
35
|
+
# faraday.request :authorization, :basic, username, password
|
36
|
+
|
37
|
+
if logger
|
38
|
+
faraday.response :logger do |logger|
|
39
|
+
logger.filter(AUTHORIZATION_FILTER_REGEX, REMOVED_LABEL)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if custom_logger
|
44
|
+
faraday.response :logger, custom_logger, custom_logger_options do |logger|
|
45
|
+
logger.filter(AUTHORIZATION_FILTER_REGEX, REMOVED_LABEL)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
faraday.adapter Faraday.default_adapter
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/avatax/request.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'json'
|
3
|
-
require "erb"
|
4
|
-
|
5
|
-
|
6
|
-
module AvaTax
|
7
|
-
module Request
|
8
|
-
|
9
|
-
def get(path, options={}, apiversion="", headers=Hash.new)
|
10
|
-
request(:get, path, nil, options, apiversion, headers)
|
11
|
-
end
|
12
|
-
|
13
|
-
def post(path, model, options={}, apiversion="", headers=Hash.new)
|
14
|
-
request(:post, path, model, options, apiversion, headers)
|
15
|
-
end
|
16
|
-
|
17
|
-
def put(path, model, options={}, apiversion="", headers=Hash.new)
|
18
|
-
request(:put, path, model, options, apiversion, headers)
|
19
|
-
end
|
20
|
-
|
21
|
-
def delete(path, options={}, apiversion="", headers=Hash.new)
|
22
|
-
request(:delete, path, nil, options, apiversion, headers)
|
23
|
-
end
|
24
|
-
|
25
|
-
def request(method, path, model, options={}, apiversion="", headers=Hash.new )
|
26
|
-
response = connection.send(method) do |request|
|
27
|
-
request.headers['X-Avalara-Client'] = request.headers['X-Avalara-Client'].gsub("API_VERSION", apiversion)
|
28
|
-
request.headers=request.headers.merge(headers) unless headers.empty?
|
29
|
-
case method
|
30
|
-
when :get, :delete
|
31
|
-
request.url("#{encode_path(path)}?#{URI.encode_www_form(options)}")
|
32
|
-
when :post, :put
|
33
|
-
request.url("#{encode_path(path)}?#{URI.encode_www_form(options)}")
|
34
|
-
request.headers['Content-Type'] = 'application/json'
|
35
|
-
request.body = model.to_json unless model.empty?
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
if faraday_response
|
40
|
-
response
|
41
|
-
else
|
42
|
-
response.body
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def encode_path(path)
|
49
|
-
path.split('/').map { |part| ERB::Util.url_encode(part) }.join('/')
|
50
|
-
end
|
51
|
-
end
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require "erb"
|
4
|
+
|
5
|
+
|
6
|
+
module AvaTax
|
7
|
+
module Request
|
8
|
+
|
9
|
+
def get(path, options={}, apiversion="", headers=Hash.new)
|
10
|
+
request(:get, path, nil, options, apiversion, headers)
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(path, model, options={}, apiversion="", headers=Hash.new)
|
14
|
+
request(:post, path, model, options, apiversion, headers)
|
15
|
+
end
|
16
|
+
|
17
|
+
def put(path, model, options={}, apiversion="", headers=Hash.new)
|
18
|
+
request(:put, path, model, options, apiversion, headers)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(path, options={}, apiversion="", headers=Hash.new)
|
22
|
+
request(:delete, path, nil, options, apiversion, headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def request(method, path, model, options={}, apiversion="", headers=Hash.new )
|
26
|
+
response = connection.send(method) do |request|
|
27
|
+
request.headers['X-Avalara-Client'] = request.headers['X-Avalara-Client'].gsub("API_VERSION", apiversion)
|
28
|
+
request.headers=request.headers.merge(headers) unless headers.empty?
|
29
|
+
case method
|
30
|
+
when :get, :delete
|
31
|
+
request.url("#{encode_path(path)}?#{URI.encode_www_form(options)}")
|
32
|
+
when :post, :put
|
33
|
+
request.url("#{encode_path(path)}?#{URI.encode_www_form(options)}")
|
34
|
+
request.headers['Content-Type'] = 'application/json'
|
35
|
+
request.body = model.to_json unless model.empty?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if faraday_response
|
40
|
+
response
|
41
|
+
else
|
42
|
+
response.body
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def encode_path(path)
|
49
|
+
path.split('/').map { |part| ERB::Util.url_encode(part) }.join('/')
|
50
|
+
end
|
51
|
+
end
|
52
52
|
end
|
data/lib/avatax/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module AvaTax
|
2
|
-
VERSION = '22.
|
3
|
-
end
|
1
|
+
module AvaTax
|
2
|
+
VERSION = '22.8.0'.freeze unless defined?(::AvaTax::VERSION)
|
3
|
+
end
|
data/lib/avatax.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
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
|
-
|
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
|
14
|
-
|
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)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Delegate to AvaTax::Client
|
22
|
-
def self.respond_to?(method, include_all=false)
|
23
|
-
return client.respond_to?(method, include_all) || super
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
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
|
+
|
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
|
14
|
+
|
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)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Delegate to AvaTax::Client
|
22
|
+
def self.respond_to?(method, include_all=false)
|
23
|
+
return client.respond_to?(method, include_all) || super
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe AvaTax::Client do
|
4
|
-
|
5
|
-
describe ".accounts" do
|
6
|
-
it "should return an array of accounts" do
|
7
|
-
accounts = @client.query_accounts
|
8
|
-
expect(accounts).to be_a Object
|
9
|
-
expect(accounts['value'].first['id']).to be_a Integer
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe AvaTax::Client do
|
4
|
+
|
5
|
+
describe ".accounts" do
|
6
|
+
it "should return an array of accounts" do
|
7
|
+
accounts = @client.query_accounts
|
8
|
+
expect(accounts).to be_a Object
|
9
|
+
expect(accounts['value'].first['id']).to be_a Integer
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|