avatax 17.8.1 → 17.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ff123feb21d5c4095101de3bd2374dd451eb3dd
4
- data.tar.gz: 8d30daf442c6dc18fa66195e305c128d83cdc6a2
3
+ metadata.gz: '0680587db1990a807285ce4440ee7ab4c2b6038c'
4
+ data.tar.gz: 8b57b3f6eab1e7ad9db997186e2ea8c890ad6149
5
5
  SHA512:
6
- metadata.gz: 36a96bbe9fa0cddb55147de9f7be3a14cf911537e6ae6327dafe10451b0df9ed9aee082d7246951cbcb645909aa705b918f46f88bc868e515fc6b16c04e06a54
7
- data.tar.gz: 6879d45e224836daddd1e4869bc2c6871e00e3926d924d8c84dfae254035687edaa4a7b959238a09bf0dd0d42df9f346c891d0785b97b8dcd554dbbc736a8dd6
6
+ metadata.gz: 64b065f5aecbc0d52212ce81ca68e4106e92e0f5ce9b702ad28b7bac6a8a6b7733b0c5721e9a499a976fcf0a405ea4e75898ff1f8d81afab0c334d4ea65fe14c
7
+ data.tar.gz: 1a21be078475e0781f14d183b2c79a7696c2c838a95f6da867df3642ccfb64955976441d87df713ebb14ce8d16ee7b2411e9238f89586ea642fad736a4c869ba
data/.gitignore CHANGED
@@ -10,6 +10,7 @@
10
10
  /test/version_tmp/
11
11
  /tmp/
12
12
  /example/credentials.yaml
13
+ /spec/credentials.yaml
13
14
 
14
15
  # Used by dotenv library to load environment variables.
15
16
  # .env
data/example/avatax.rb CHANGED
@@ -4,11 +4,44 @@ require File.expand_path('../../lib/avatax', __FILE__)
4
4
  credentials = YAML.load_file(File.expand_path('../credentials.yaml', __FILE__))
5
5
 
6
6
  AvaTax.configure do |config|
7
- config.endpoint = credentials['endpoint']
8
- config.username = credentials['username']
9
- config.password = credentials['password']
7
+ begin
8
+ credentials = YAML.load_file(File.expand_path('../credentials.yaml', __FILE__))
9
+ config.endpoint = credentials['endpoint']
10
+ config.username = credentials['username']
11
+ config.password = credentials['password']
12
+ rescue
13
+ config.endpoint = 'https://sandbox-rest.avatax.com'
14
+ config.username = ENV['SANDBOX_USERNAME']
15
+ config.password = ENV['SANDBOX_PASSWORD']
16
+ end
10
17
  end
11
18
 
12
19
  @client = AvaTax::Client.new(:logger => true)
13
20
 
14
- puts @client.query_companies
21
+ #puts @client.query_companies
22
+
23
+ createTransactionModel = {
24
+ type: 'SalesInvoice',
25
+ companyCode: 'DEFAULT',
26
+ date: '2017-06-05',
27
+ customerCode: 'ABC',
28
+ "addresses": {
29
+ "ShipFrom": {
30
+ "line1": "123 Main Street",
31
+ "city": "Irvine",
32
+ "region": "CA",
33
+ "country": "US",
34
+ "postalCode": "92615"
35
+ },
36
+ "ShipTo": {
37
+ "line1": "100 Market Street",
38
+ "city": "San Francisco",
39
+ "region": "CA",
40
+ "country": "US",
41
+ "postalCode": "94105"
42
+ }
43
+ },
44
+ lines: [{amount: 100}]
45
+ }
46
+ transaction = @client.create_transaction(createTransactionModel)
47
+ puts transaction
@@ -6,8 +6,17 @@ module AvaTax
6
6
  # Reset this account's license key
7
7
  #
8
8
  # Resets the existing license key for this account to a new key.
9
+ #
9
10
  # To reset your account, you must specify the ID of the account you wish to reset and confirm the action.
11
+ #
12
+ # This API is only available to account administrators for the account in question, and may only be called after
13
+ # an account has been activated by reading and accepting Avalara's terms and conditions. To activate your account
14
+ # please log onto the AvaTax website or call the `ActivateAccount` API.
15
+ #
10
16
  # Resetting a license key cannot be undone. Any previous license keys will immediately cease to work when a new key is created.
17
+ #
18
+ # When you call this API, all account administrators for this account will receive an email with the newly updated license key.
19
+ # The email will specify which user reset the license key and it will contain the new key to use to update your connectors.
11
20
  # @param id [Integer] The ID of the account you wish to update.
12
21
  # @param model [Object] A request confirming that you wish to reset the license key of this account.
13
22
  # @return [Object]
@@ -24,6 +33,9 @@ module AvaTax
24
33
  # This activation request can only be called by account administrators. You must indicate
25
34
  # that you have read and accepted Avalara's terms and conditions to call this API.
26
35
  #
36
+ # Once you have activated your account, use the `AccountResetLicenseKey` API to generate
37
+ # a license key for your account.
38
+ #
27
39
  # If you have not read or accepted the terms and conditions, this API call will return the
28
40
  # unchanged account model.
29
41
  # @param id [Integer] The ID of the account to activate
@@ -40,6 +40,7 @@ module AvaTax
40
40
  #
41
41
  # This API only provides a limited subset of functionality compared to the 'Create Company' API call.
42
42
  # If you need additional features or options not present in this 'Quick Setup' API call, please use the full 'Create Company' call instead.
43
+ # Please allow 1 minute before making transactions using the company.
43
44
  # @param model [Object] Information about the company you wish to create.
44
45
  # @return [Object]
45
46
  def company_initialize(model)
@@ -48,6 +48,19 @@ module AvaTax
48
48
  end
49
49
 
50
50
 
51
+ # Create a filing calendar
52
+ #
53
+ # This API is available by invitation only and only available for users with Compliance access
54
+ # A "filing request" represents information that compliance uses to file a return
55
+ # @param companyId [Integer] The unique ID of the company that will add the new filing calendar
56
+ # @param model [FilingCalendarModel[]] Filing calendars that will be added
57
+ # @return [Object]
58
+ def create_filing_calendars(companyId, model)
59
+ path = "/api/v2/companies/#{companyId}/filingcalendars"
60
+ post(path, model)
61
+ end
62
+
63
+
51
64
  # Create a new filing request to create a filing calendar
52
65
  #
53
66
  # This API is available by invitation only.
@@ -255,11 +268,9 @@ module AvaTax
255
268
  end
256
269
 
257
270
 
258
- # Edit existing Filing Calendar's Notes
271
+ # Edit existing Filing Calendar
259
272
  #
260
273
  # This API is available by invitation only.
261
- # This API only allows updating of internal notes and company filing instructions.
262
- # All other updates must go through a filing request at this time.
263
274
  # @param companyId [Integer] The unique ID of the company that owns the filing request object
264
275
  # @param id [Integer] The unique ID of the filing calendar object
265
276
  # @param model [Object] The filing calendar model you are wishing to update with.
@@ -388,7 +388,7 @@ module AvaTax
388
388
 
389
389
  # Rebuild a set of filings for the specified company in the given filing period, country and region.
390
390
  #
391
- # This API is available by invitation only.
391
+ # This API is available by invitation only.audit.CheckAuthorizationReturns(null, companyId);
392
392
  # Rebuilding a return means re-creating or updating the amounts to be filed for a filing.
393
393
  # Rebuilding has to be done whenever a customer adds transactions to a filing.
394
394
  # A "filing period" is the year and month of the date of the latest customer transaction allowed to be reported on a filing,
@@ -13,6 +13,7 @@ module AvaTax
13
13
  # Note that not all fields within a nexus can be updated; Avalara publishes a list of all defined nexus at the
14
14
  # '/api/v2/definitions/nexus' endpoint.
15
15
  # You may only define nexus matching the official list of declared nexus.
16
+ # Please allow 1 minute before start using the created Nexus in your transactions.
16
17
  # @param companyId [Integer] The ID of the company that owns this nexus.
17
18
  # @param model [NexusModel[]] The nexus you wish to create.
18
19
  # @return [NexusModel[]]
@@ -25,6 +26,7 @@ module AvaTax
25
26
  # Delete a single nexus
26
27
  #
27
28
  # Marks the existing nexus object at this URL as deleted.
29
+ # Please allow 1 minute to stop collecting tax in your transaction on the deleted Nexus.
28
30
  # @param companyId [Integer] The ID of the company that owns this nexus.
29
31
  # @param id [Integer] The ID of the nexus you wish to delete.
30
32
  # @return [ErrorDetail[]]
@@ -129,6 +131,7 @@ module AvaTax
129
131
  # You may only define nexus matching the official list of declared nexus.
130
132
  # All data from the existing object will be replaced with data in the object you PUT.
131
133
  # 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.
134
+ # Please allow 1 minute to start seeing your updated Nexus taking effect on your transactions.
132
135
  # @param companyId [Integer] The ID of the company that this nexus belongs to.
133
136
  # @param id [Integer] The ID of the nexus you wish to update
134
137
  # @param model [Object] The nexus object you wish to update.
@@ -18,7 +18,7 @@ module AvaTax
18
18
  # terms and conditions. If they do so, they can receive a license key as part of this API and their
19
19
  # API will be created in `Active` status. If the customer has not yet read and accepted these terms and
20
20
  # conditions, the account will be created in `New` status and they can receive a license key by logging
21
- # onto AvaTax and reviewing terms and conditions online.
21
+ # onto the AvaTax website and reviewing terms and conditions online.
22
22
  # @param model [Object] Information about the account you wish to create and the selected product offerings.
23
23
  # @return [Object]
24
24
  def request_new_account(model)
@@ -191,4 +191,4 @@ module AvaTax
191
191
 
192
192
  end
193
193
  end
194
- end
194
+ end
@@ -3,17 +3,111 @@ module AvaTax
3
3
  module Reports
4
4
 
5
5
 
6
- # Export a report accurate to the line level
6
+ # Download a report
7
7
  #
8
- #
9
- # @param companyId [Integer]
10
- # @param model [Object]
8
+ # This API downloads the file associated with a report.
9
+ #
10
+ # If the report is not yet complete, you will receive a `ReportNotFinished` error. To check if a report is complete,
11
+ # use the `GetReport` API.
12
+ #
13
+ # Reports are run as asynchronous report tasks on the server. When complete, the report file will be available for download
14
+ # for up to 30 days after completion. To run an asynchronous report, you should follow these steps:
15
+ #
16
+ # * Begin a report by calling the report's Initiate API. There is a separate initiate API call for each report type.
17
+ # * In the result of the Initiate API, you receive back a report's `id` value.
18
+ # * Check the status of a report by calling `GetReport` and passing in the report's `id` value.
19
+ # * When a report's status is `Completed`, call `DownloadReport` to retrieve the file.
20
+ #
21
+ # This API works for all report types.
22
+ # @param id [Integer] The unique ID number of this report
23
+ # @return [Object]
24
+ def download_report(id)
25
+ path = "/api/v2/reports/#{id}/attachment"
26
+ get(path)
27
+ end
28
+
29
+
30
+ # Intiate and download an ExportDocumentLine report
31
+ #
32
+ # This API is deprecated.
33
+ #
34
+ # Please use the asynchronous reports APIs:
35
+ #
36
+ # * Begin a report by calling the report's Initiate API. There is a separate initiate API call for each report type.
37
+ # * In the result of the Initiate API, you receive back a report's `id` value.
38
+ # * Check the status of a report by calling `GetReport` and passing in the report's `id` value.
39
+ # * When a report's status is `Completed`, call `DownloadReport` to retrieve the file.
40
+ # @param companyId [Integer] The unique ID number of the company to report on.
41
+ # @param model [Object] Options that may be configured to customize the report.
11
42
  # @return [Object]
12
43
  def export_document_line(companyId, model)
13
44
  path = "/api/v2/companies/#{companyId}/reports/exportdocumentline"
14
45
  post(path, model)
15
46
  end
16
47
 
48
+
49
+ # Retrieve a single report
50
+ #
51
+ # Retrieve a single report by its unique ID number.
52
+ #
53
+ # Reports are run as asynchronous report tasks on the server. When complete, the report file will be available for download
54
+ # for up to 30 days after completion. To run an asynchronous report, you should follow these steps:
55
+ #
56
+ # * Begin a report by calling the report's Initiate API. There is a separate initiate API call for each report type.
57
+ # * In the result of the Initiate API, you receive back a report's `id` value.
58
+ # * Check the status of a report by calling `GetReport` and passing in the report's `id` value.
59
+ # * When a report's status is `Completed`, call `DownloadReport` to retrieve the file.
60
+ #
61
+ # This API call returns information about any report type.
62
+ # @param id [Integer] The unique ID number of the report to retrieve
63
+ # @return [Object]
64
+ def get_report(id)
65
+ path = "/api/v2/reports/#{id}"
66
+ get(path)
67
+ end
68
+
69
+
70
+ # Initiate an ExportDocumentLine report task
71
+ #
72
+ # Begins running an `ExportDocumentLine` report task and returns the identity of the report.
73
+ #
74
+ # Reports are run as asynchronous report tasks on the server. When complete, the report file will be available for download
75
+ # for up to 30 days after completion. To run an asynchronous report, you should follow these steps:
76
+ #
77
+ # * Begin a report by calling the report's Initiate API. There is a separate initiate API call for each report type.
78
+ # * In the result of the Initiate API, you receive back a report's `id` value.
79
+ # * Check the status of a report by calling `GetReport` and passing in the report's `id` value.
80
+ # * When a report's status is `Completed`, call `DownloadReport` to retrieve the file.
81
+ #
82
+ # The `ExportDocumentLine` report produces information about invoice lines recorded within your account.
83
+ # @param companyId [Integer] The unique ID number of the company to report on.
84
+ # @param model [Object] Options that may be configured to customize the report.
85
+ # @return [Object]
86
+ def initiate_export_document_line_report(companyId, model)
87
+ path = "/api/v2/companies/#{companyId}/reports/exportdocumentline/initiate"
88
+ post(path, model)
89
+ end
90
+
91
+
92
+ # List all report tasks for account
93
+ #
94
+ # List all report tasks for your account.
95
+ #
96
+ # Reports are run as asynchronous report tasks on the server. When complete, the report file will be available for download
97
+ # for up to 30 days after completion. To run an asynchronous report, you should follow these steps:
98
+ #
99
+ # * Begin a report by calling the report's Initiate API. There is a separate initiate API call for each report type.
100
+ # * In the result of the Initiate API, you receive back a report's `id` value.
101
+ # * Check the status of a report by calling `GetReport` and passing in the report's `id` value.
102
+ # * When a report's status is `Completed`, call `DownloadReport` to retrieve the file.
103
+ #
104
+ # This API call returns information about all report types across your entire account.
105
+ # @return [FetchResult]
106
+ def list_reports()
107
+ path = "/api/v2/reports"
108
+ get(path)
109
+ end
110
+
17
111
  end
18
112
  end
19
113
  end
@@ -16,6 +16,8 @@ module AvaTax
16
16
  #
17
17
  # This API builds the file on demand, and is limited to files with no more than 7500 scenarios. To build a tax content
18
18
  # file for a single location at a time, please use `BuildTaxContentFileForLocation`.
19
+ #
20
+ # NOTE: This API does not work for Tennessee tax holiday scenarios.
19
21
  # @param model [Object] Parameters about the desired file format and report format, specifying which company, locations and TaxCodes to include.
20
22
  # @return [Object]
21
23
  def build_tax_content_file(model)
@@ -37,6 +39,8 @@ module AvaTax
37
39
  #
38
40
  # This API builds the file on demand, and is limited to files with no more than 7500 scenarios. To build a tax content
39
41
  # file for a multiple locations in a single file, please use `BuildTaxContentFile`.
42
+ #
43
+ # NOTE: This API does not work for Tennessee tax holiday scenarios.
40
44
  # @param companyId [Integer] The ID number of the company that owns this location.
41
45
  # @param id [Integer] The ID number of the location to retrieve point-of-sale data.
42
46
  # @param date [DateTime] The date for which point-of-sale data would be calculated (today by default)
@@ -61,7 +61,7 @@ module AvaTax
61
61
  #
62
62
  # Retrieve audit information about a transaction stored in AvaTax.
63
63
  #
64
- # The 'AuditTransaction' endpoint retrieves audit information related to a specific transaction. This audit
64
+ # The `AuditTransaction` API retrieves audit information related to a specific transaction. This audit
65
65
  # information includes the following:
66
66
  #
67
67
  # * The `CompanyId` of the company that created the transaction
@@ -87,7 +87,7 @@ module AvaTax
87
87
  #
88
88
  # Retrieve audit information about a transaction stored in AvaTax.
89
89
  #
90
- # The 'AuditTransaction' endpoint retrieves audit information related to a specific transaction. This audit
90
+ # The `AuditTransaction` API retrieves audit information related to a specific transaction. This audit
91
91
  # information includes the following:
92
92
  #
93
93
  # * The `CompanyId` of the company that created the transaction
@@ -160,15 +160,22 @@ module AvaTax
160
160
  end
161
161
 
162
162
 
163
- # Create a new transaction
163
+ # Create or adjust a transaction
164
+ #
165
+ # Records a new transaction or adjust an existing transaction in AvaTax.
166
+ #
167
+ # The `CreateOrAdjustTransaction` endpoint is used to create a new transaction or update an existing one. This API
168
+ # can help you create an idempotent service that creates transactions
169
+ # If there exists a transaction identified by code, the original transaction will be adjusted by using the meta data
170
+ # in the input transaction.
164
171
  #
165
- # Records a new transaction or adjust an existing in AvaTax.
172
+ # The `CreateOrAdjustTransaction` API cannot modify any transaction that has been reported to a tax authority using
173
+ # the Avalara Managed Returns Service or any other tax filing service. If you call this API to attempt to modify
174
+ # a transaction that has been reported on a tax filing, you will receive the error `CannotModifyLockedTransaction`.
166
175
  #
167
- # The `CreateOrAdjustTransaction` endpoint is used to create a new transaction if the input transaction does not exist
168
- # or if there exists a transaction identified by code, the original transaction will be adjusted by using the meta data
169
- # in the input transaction
176
+ # To generate a refund for a transaction, use the `RefundTransaction` API.
170
177
  #
171
- # If you don't specify type in the provided data, a new transaction with type of SalesOrder will be recorded by default.
178
+ # If you don't specify the field `type` in your request, you will get an estimate of type `SalesOrder`, which will not be recorded in the database.
172
179
  #
173
180
  # A transaction represents a unique potentially taxable action that your company has recorded, and transactions include actions like
174
181
  # sales, purchases, inventory transfer, and returns (also called refunds).
@@ -180,10 +187,11 @@ module AvaTax
180
187
  # * Addresses
181
188
  # * SummaryOnly (omit lines and details - reduces API response size)
182
189
  # * LinesOnly (omit details - reduces API response size)
190
+ # * ForceTimeout - Simulates a timeout. This adds a 30 second delay and error to your API call. This can be used to test your code to ensure it can respond correctly in the case of a dropped connection.
183
191
  #
184
192
  # If you omit the `$include` parameter, the API will assume you want `Summary,Addresses`.
185
193
  # @param include [String] Specifies objects to include in the response after transaction is created
186
- # @param model [Object] The transaction you wish to create
194
+ # @param model [Object] The transaction you wish to create or adjust
187
195
  # @return [Object]
188
196
  def create_or_adjust_transaction(model, options={})
189
197
  path = "/api/v2/transactions/createoradjust"
@@ -199,7 +207,13 @@ module AvaTax
199
207
  # and rates to apply to all line items in this transaction, and reports the total tax calculated by AvaTax based on your
200
208
  # company's configuration and the data provided in this API call.
201
209
  #
202
- # If you don't specify type in the provided data, a new transaction with type of SalesOrder will be recorded by default.
210
+ # The `CreateTransaction` API will report an error if a committed transaction already exists with the same `code`. To
211
+ # avoid this error, use the `CreateOrAdjustTransaction` API - it will create the transaction if it does not exist, or
212
+ # update it if it does exist.
213
+ #
214
+ # To generate a refund for a transaction, use the `RefundTransaction` API.
215
+ #
216
+ # If you don't specify the field `type` in your request, you will get an estimate of type `SalesOrder`, which will not be recorded in the database.
203
217
  #
204
218
  # A transaction represents a unique potentially taxable action that your company has recorded, and transactions include actions like
205
219
  # sales, purchases, inventory transfer, and returns (also called refunds).
@@ -211,6 +225,7 @@ module AvaTax
211
225
  # * Addresses
212
226
  # * SummaryOnly (omit lines and details - reduces API response size)
213
227
  # * LinesOnly (omit details - reduces API response size)
228
+ # * ForceTimeout - Simulates a timeout. This adds a 30 second delay and error to your API call. This can be used to test your code to ensure it can respond correctly in the case of a dropped connection.
214
229
  #
215
230
  # If you omit the `$include` parameter, the API will assume you want `Summary,Addresses`.
216
231
  # @param include [String] Specifies objects to include in the response after transaction is created
@@ -252,10 +267,14 @@ module AvaTax
252
267
 
253
268
  # Retrieve a single transaction by code
254
269
  #
255
- # Get the current transaction identified by this URL.
270
+ # Get the current `SalesInvoice` transaction identified by this URL.
271
+ #
272
+ # To fetch other kinds of transactions, use `GetTransactionByCodeAndType`.
273
+ #
256
274
  # If this transaction was adjusted, the return value of this API will be the current transaction with this code, and previous revisions of
257
- # the transaction will be attached to the 'history' data field.
258
- # You may specify one or more of the following values in the '$include' parameter to fetch additional nested data, using commas to separate multiple values:
275
+ # the transaction will be attached to the `history` data field.
276
+ #
277
+ # You may specify one or more of the following values in the `$include` parameter to fetch additional nested data, using commas to separate multiple values:
259
278
  #
260
279
  # * Lines
261
280
  # * Details (implies lines)
@@ -276,9 +295,11 @@ module AvaTax
276
295
  # Retrieve a single transaction by code
277
296
  #
278
297
  # Get the current transaction identified by this URL.
298
+ #
279
299
  # If this transaction was adjusted, the return value of this API will be the current transaction with this code, and previous revisions of
280
- # the transaction will be attached to the 'history' data field.
281
- # You may specify one or more of the following values in the '$include' parameter to fetch additional nested data, using commas to separate multiple values:
300
+ # the transaction will be attached to the `history` data field.
301
+ #
302
+ # You may specify one or more of the following values in the `$include` parameter to fetch additional nested data, using commas to separate multiple values:
282
303
  #
283
304
  # * Lines
284
305
  # * Details (implies lines)
@@ -380,8 +401,21 @@ module AvaTax
380
401
  # for a previously created `SalesInvoice` transaction. You can choose to create a full or partial refund, and
381
402
  # specify individual line items from the original sale for refund.
382
403
  #
383
- # A transaction represents a unique potentially taxable action that your company has recorded, and transactions include actions like
384
- # sales, purchases, inventory transfer, and returns (also called refunds).
404
+ # The `RefundTransaction` API ensures that the tax amount you refund to the customer exactly matches the tax that
405
+ # was calculated during the original transaction, regardless of any changes to your company's configuration, rules,
406
+ # nexus, or any other setting.
407
+ #
408
+ # This API is intended to be a shortcut to allow you to quickly and accurately generate a refund for the following
409
+ # common refund scenarios:
410
+ #
411
+ # * A full refund of a previous sale
412
+ # * Refunding the tax that was charged on a previous sale, when the customer provides an exemption certificate after the purchase
413
+ # * Refunding one or more items (lines) from a previous sale
414
+ # * Granting a customer a percentage refund of a previous sale
415
+ #
416
+ # For more complex scenarios than the ones above, please use `CreateTransaction` with document type `ReturnInvoice` to
417
+ # create a custom refund transaction.
418
+ #
385
419
  # You may specify one or more of the following values in the '$include' parameter to fetch additional nested data, using commas to separate multiple values:
386
420
  #
387
421
  # * Lines
@@ -450,4 +484,4 @@ module AvaTax
450
484
 
451
485
  end
452
486
  end
453
- end
487
+ end
@@ -1,37 +1,39 @@
1
1
  require 'hashie'
2
+ require 'json'
2
3
 
3
4
  module AvaTax
4
5
  module Request
5
6
 
6
7
  def get(path, options={})
7
- request(:get, path, options)
8
+ request(:get, path, nil, options)
8
9
  end
9
10
 
10
- def post(path, options={})
11
- request(:post, path, options)
11
+ def post(path, model, options={})
12
+ request(:post, path, model, options)
12
13
  end
13
14
 
14
- def put(path, options={})
15
- request(:put, path, options)
15
+ def put(path, model, options={})
16
+ request(:put, path, model, options)
16
17
  end
17
18
 
18
19
  def delete(path, options={})
19
- request(:delete, path, options)
20
+ request(:delete, path, nil, options)
20
21
  end
21
22
 
22
- def request(method, path, options)
23
+ def request(method, path, model, options={})
23
24
  response = connection.send(method) do |request|
24
25
  case method
25
26
  when :get, :delete
26
- request.url(URI.encode(path), options)
27
+ request.url("#{URI.encode(path)}?#{URI.encode_www_form(options)}")
27
28
  when :post, :put
28
- request.path = URI.encode(path)
29
+ request.path = ("#{URI.encode(path)}?#{URI.encode_www_form(options)}")
29
30
  request.headers['Content-Type'] = 'application/json'
30
- request.body = options.to_json unless options.empty?
31
+ request.body = model.to_json unless model.empty?
31
32
  end
32
33
  end
33
34
 
34
- ::Hashie::Mash.new response.body
35
+ #::Hashie::Mash.new response.body
36
+ response.body
35
37
  end
36
38
 
37
39
  end
@@ -1,3 +1,3 @@
1
1
  module AvaTax
2
- VERSION = '17.8.1'.freeze unless defined?(::AvaTax::VERSION)
2
+ VERSION = '17.9.1'.freeze unless defined?(::AvaTax::VERSION)
3
3
  end
@@ -1,26 +1,13 @@
1
1
  require File.expand_path('../../../spec_helper', __FILE__)
2
2
 
3
3
  describe AvaTax::Client do
4
- before do
5
- @client = AvaTax::Client.new()
6
- end
7
4
 
8
5
  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
6
  it "should return an array of accounts" do
20
7
  accounts = @client.query_accounts
21
8
  expect(accounts).to be_a Object
22
- expect(accounts['value'].first['id']).to equal 200000251
23
- expect(accounts.value.first.id).to equal 200000251
9
+ expect(accounts['value'].first['id']).to be_a Integer
24
10
  end
25
11
  end
12
+
26
13
  end
@@ -0,0 +1,40 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe AvaTax::Client do
4
+
5
+ describe ".transactions" do
6
+ before do
7
+ @base_transaction = {
8
+ type: 'SalesInvoice',
9
+ companyCode: @company_code,
10
+ date: '2017-06-05',
11
+ customerCode: 'ABC',
12
+ addresses: {
13
+ ShipFrom: {
14
+ line1: "123 Main Street",
15
+ city: "Irvine",
16
+ region: "CA",
17
+ country: "US",
18
+ postalCode: "92615"
19
+ },
20
+ ShipTo: {
21
+ line1: "100 Market Street",
22
+ city: "San Francisco",
23
+ region: "CA",
24
+ country: "US",
25
+ postalCode: "94105"
26
+ }
27
+ },
28
+ lines: [{amount: 100}]
29
+ }
30
+ end
31
+
32
+ it "should create a transaction" do
33
+ transaction = @client.create_transaction(@base_transaction)
34
+ expect(transaction).to be_a Object
35
+ expect(transaction["id"]).to be_a Integer
36
+ expect(transaction["status"]).to eq "Saved"
37
+ end
38
+
39
+ end
40
+ end
data/spec/avatax_spec.rb CHANGED
@@ -1,27 +1,15 @@
1
1
  require File.expand_path('../spec_helper', __FILE__)
2
+ begin
3
+ credentials = YAML.load_file(File.expand_path('../credentials.yaml', __FILE__))
4
+ rescue
5
+ credentials = {
6
+ "endpoint" => 'https://sandbox-rest.avatax.com',
7
+ "username" => ENV['SANDBOX_USERNAME'],
8
+ "password" => ENV['SANDBOX_PASSWORD'],
9
+ }
10
+ end
2
11
 
3
12
  describe AvaTax do
4
- after do
5
- AvaTax.reset
6
- end
7
-
8
- context "when delegating to a client" do
9
-
10
- before do
11
- stub_get("/api/v2/accounts").
12
- to_return(:body => fixture("accounts.json"), :headers => {:content_type => "application/json; charset=utf-8"})
13
- end
14
-
15
- it "should get the correct resource" do
16
- AvaTax.query_accounts()
17
- expect(a_get("/api/v2/accounts")).to have_been_made
18
- end
19
-
20
- it "should return the same results as a client" do
21
- expect(AvaTax.query_accounts()).to eq AvaTax::Client.new().query_accounts()
22
- end
23
-
24
- end
25
13
 
26
14
  describe ".client" do
27
15
  it "should be a AvaTax::Client" do
@@ -31,7 +19,7 @@ describe AvaTax do
31
19
 
32
20
  describe ".endpoint" do
33
21
  it "should return the default endpoint" do
34
- expect(AvaTax.endpoint).to eq AvaTax::Configuration::DEFAULT_ENDPOINT
22
+ expect(AvaTax.endpoint).to eq credentials['endpoint']
35
23
  end
36
24
  end
37
25
 
@@ -0,0 +1,4 @@
1
+ ---
2
+ endpoint: https://sandbox-rest.avatax.com
3
+ username: ---
4
+ password: ---
data/spec/spec_helper.rb CHANGED
@@ -1,47 +1,27 @@
1
1
  require File.expand_path('../../lib/avatax', __FILE__)
2
2
  require 'rspec'
3
- require 'webmock/rspec'
3
+ require 'yaml'
4
4
 
5
- RSpec.configure do |config|
6
- config.include WebMock::API
7
- end
8
-
9
- def a_delete(path)
10
- a_request(:delete, AvaTax.endpoint + path)
11
- end
12
-
13
- def a_get(path)
14
- a_request(:get, AvaTax.endpoint + path)
15
- end
16
-
17
- def a_post(path)
18
- a_request(:post, AvaTax.endpoint + path)
19
- end
20
-
21
- def a_put(path)
22
- a_request(:put, AvaTax.endpoint + path)
23
- end
24
5
 
25
- def stub_delete(path)
26
- stub_request(:delete, AvaTax.endpoint + path)
6
+ AvaTax.configure do |config|
7
+ begin
8
+ credentials = YAML.load_file(File.expand_path('../credentials.yaml', __FILE__))
9
+ config.endpoint = credentials['endpoint']
10
+ config.username = credentials['username']
11
+ config.password = credentials['password']
12
+ rescue
13
+ config.endpoint = 'https://sandbox-rest.avatax.com'
14
+ config.username = ENV['SANDBOX_USERNAME']
15
+ config.password = ENV['SANDBOX_PASSWORD']
16
+ end
27
17
  end
28
18
 
29
- def stub_get(path)
30
- stub_request(:get, AvaTax.endpoint + path)
31
- end
19
+ client = AvaTax::Client.new()
20
+ companies = client.query_companies
32
21
 
33
- def stub_post(path)
34
- stub_request(:post, AvaTax.endpoint + path)
35
- end
36
-
37
- def stub_put(path)
38
- stub_request(:put, AvaTax.endpoint + path)
39
- end
40
-
41
- def fixture_path
42
- File.expand_path("../fixtures", __FILE__)
43
- end
44
-
45
- def fixture(file)
46
- File.new(fixture_path + '/' + file)
22
+ RSpec.configure do |config|
23
+ config.before {
24
+ @client = client
25
+ @company_code = companies["value"][1]["companyCode"]
26
+ }
47
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avatax
3
3
  version: !ruby/object:Gem::Version
4
- version: 17.8.1
4
+ version: 17.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Vorwaller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -179,7 +179,9 @@ files:
179
179
  - lib/avatax/request.rb
180
180
  - lib/avatax/version.rb
181
181
  - spec/avatax/client/accounts_spec.rb
182
+ - spec/avatax/client/transactions_spec.rb
182
183
  - spec/avatax_spec.rb
184
+ - spec/credentials.yaml.example
183
185
  - spec/fixtures/accounts.json
184
186
  - spec/spec_helper.rb
185
187
  homepage: https://github.com/avadev/AvaTax-REST-V2-Ruby-SDK
@@ -220,6 +222,8 @@ specification_version: 4
220
222
  summary: Ruby wrapper for the AvaTax API
221
223
  test_files:
222
224
  - spec/avatax/client/accounts_spec.rb
225
+ - spec/avatax/client/transactions_spec.rb
223
226
  - spec/avatax_spec.rb
227
+ - spec/credentials.yaml.example
224
228
  - spec/fixtures/accounts.json
225
229
  - spec/spec_helper.rb