tax_cloud 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +29 -0
  3. data/.travis.yml +4 -7
  4. data/CHANGELOG.rdoc +6 -0
  5. data/Gemfile +6 -1
  6. data/README.rdoc +2 -2
  7. data/Rakefile +4 -1
  8. data/lib/hash.rb +2 -4
  9. data/lib/tax_cloud.rb +8 -12
  10. data/lib/tax_cloud/address.rb +3 -5
  11. data/lib/tax_cloud/cart_item.rb +0 -2
  12. data/lib/tax_cloud/client.rb +22 -21
  13. data/lib/tax_cloud/configuration.rb +2 -3
  14. data/lib/tax_cloud/errors/api_error.rb +6 -6
  15. data/lib/tax_cloud/errors/missing_config_error.rb +2 -2
  16. data/lib/tax_cloud/errors/missing_config_option_error.rb +5 -5
  17. data/lib/tax_cloud/errors/soap_error.rb +8 -10
  18. data/lib/tax_cloud/errors/tax_cloud_error.rb +45 -48
  19. data/lib/tax_cloud/errors/unexpected_soap_response_error.rb +7 -10
  20. data/lib/tax_cloud/record.rb +1 -1
  21. data/lib/tax_cloud/responses.rb +1 -1
  22. data/lib/tax_cloud/responses/authorized.rb +1 -1
  23. data/lib/tax_cloud/responses/authorized_with_capture.rb +1 -1
  24. data/lib/tax_cloud/responses/base.rb +26 -30
  25. data/lib/tax_cloud/responses/captured.rb +2 -3
  26. data/lib/tax_cloud/responses/cart_item.rb +2 -5
  27. data/lib/tax_cloud/responses/generic.rb +2 -6
  28. data/lib/tax_cloud/responses/lookup.rb +7 -10
  29. data/lib/tax_cloud/responses/ping.rb +2 -2
  30. data/lib/tax_cloud/responses/returned.rb +2 -2
  31. data/lib/tax_cloud/responses/tax_code_groups.rb +10 -13
  32. data/lib/tax_cloud/responses/tax_codes.rb +9 -12
  33. data/lib/tax_cloud/responses/tax_codes_by_group.rb +11 -14
  34. data/lib/tax_cloud/responses/verify_address.rb +6 -9
  35. data/lib/tax_cloud/tax_code.rb +1 -1
  36. data/lib/tax_cloud/tax_code_constants.rb +7 -9
  37. data/lib/tax_cloud/tax_code_group.rb +2 -4
  38. data/lib/tax_cloud/tax_code_groups.rb +2 -5
  39. data/lib/tax_cloud/tax_codes.rb +1 -5
  40. data/lib/tax_cloud/transaction.rb +6 -6
  41. data/lib/tax_cloud/version.rb +1 -1
  42. data/tax_cloud.gemspec +3 -3
  43. data/test/cassettes/authorized.yml +729 -2
  44. data/test/cassettes/authorized_with_capture.yml +729 -2
  45. data/test/cassettes/authorized_with_localized_time.yml +729 -2
  46. data/test/cassettes/captured.yml +730 -3
  47. data/test/cassettes/get_tic_groups.yml +154 -27
  48. data/test/cassettes/get_tics.yml +154 -27
  49. data/test/cassettes/get_tics_by_group.yml +728 -1
  50. data/test/cassettes/invalid_soap_call.yml +154 -27
  51. data/test/cassettes/lookup.yml +728 -1
  52. data/test/cassettes/lookup_ny.yml +728 -1
  53. data/test/cassettes/ping.yml +160 -31
  54. data/test/cassettes/ping_with_invalid_credentials.yml +154 -27
  55. data/test/cassettes/ping_with_invalid_response.yml +154 -27
  56. data/test/cassettes/returned.yml +730 -3
  57. data/test/cassettes/verify_bad_address.yml +680 -503
  58. data/test/cassettes/verify_good_address.yml +727 -0
  59. data/test/helper.rb +0 -4
  60. data/test/test_address.rb +4 -6
  61. data/test/test_cart_item.rb +1 -3
  62. data/test/test_client.rb +2 -4
  63. data/test/test_configuration.rb +3 -5
  64. data/test/test_setup.rb +0 -1
  65. data/test/test_soap.rb +2 -4
  66. data/test/test_tax_code_groups.rb +2 -4
  67. data/test/test_tax_codes.rb +1 -3
  68. data/test/test_transaction.rb +7 -9
  69. data/test/test_transaction_ny.rb +4 -6
  70. data/test/vcr_setup.rb +1 -1
  71. metadata +36 -41
  72. data/lib/savon_soap_xml.rb +0 -33
@@ -1,23 +1,20 @@
1
1
  # encoding: utf-8
2
2
  module TaxCloud #:nodoc:
3
3
  module Errors #:nodoc:
4
-
5
- # This error is raised when TaxCloud returns an
4
+ # This error is raised when TaxCloud returns an
6
5
  # unexpected SOAP response.
7
6
  class UnexpectedSoapResponse < TaxCloudError
8
-
9
7
  # === Parameters
10
8
  # [raw] Raw data from the SOAP response.
11
9
  # [key] Expected key in the SOAP response.
12
10
  # [chain] Complete SOAP response chain in which the key could not be found.
13
11
  def initialize(raw, key, chain)
14
- super(compose_message("unexpected_soap_response", {
15
- :key => key,
16
- :raw => raw,
17
- :chain => chain
18
- }))
12
+ super(compose_message('unexpected_soap_response',
13
+ key: key,
14
+ raw: raw,
15
+ chain: chain
16
+ ))
19
17
  end
20
-
21
18
  end
22
19
  end
23
- end
20
+ end
@@ -7,7 +7,7 @@ module TaxCloud #:nodoc:
7
7
  # [attrs] Attributes defined for this record.
8
8
  def initialize(attrs = {})
9
9
  attrs.each do |sym, val|
10
- self.send "#{sym}=", val
10
+ send "#{sym}=", val
11
11
  end
12
12
  end
13
13
  end
@@ -10,4 +10,4 @@ require 'tax_cloud/responses/captured'
10
10
  require 'tax_cloud/responses/returned'
11
11
  require 'tax_cloud/responses/tax_codes'
12
12
  require 'tax_cloud/responses/tax_code_groups'
13
- require 'tax_cloud/responses/tax_codes_by_group'
13
+ require 'tax_cloud/responses/tax_codes_by_group'
@@ -7,4 +7,4 @@ module TaxCloud #:nodoc:
7
7
  response_key :authorized
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -7,4 +7,4 @@ module TaxCloud #:nodoc:
7
7
  response_key :authorized_with_capture
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -1,10 +1,8 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
-
4
3
  # A base TaxCloud SOAP response.
5
4
  class Base
6
-
7
- # Raw response.
5
+ # Raw response.
8
6
  attr_accessor :raw
9
7
 
10
8
  # === Parameters
@@ -15,23 +13,22 @@ module TaxCloud #:nodoc:
15
13
  end
16
14
 
17
15
  class << self
18
-
19
16
  # === Parameters
20
17
  # [value] Location of the response type in the SOAP XML.
21
18
  def response_type(value)
22
- self.set_dsl(:response_type, value)
19
+ set_dsl(:response_type, value)
23
20
  end
24
21
 
25
22
  # === Parameters
26
23
  # [value] Location of the error message in the SOAP XML.
27
24
  def error_message(value)
28
- self.set_dsl(:error_message, value)
25
+ set_dsl(:error_message, value)
29
26
  end
30
27
 
31
28
  # === Parameters
32
29
  # [value] Location of the error number in the SOAP XML.
33
30
  def error_number(value)
34
- self.set_dsl(:error_number, value)
31
+ set_dsl(:error_number, value)
35
32
  end
36
33
 
37
34
  # Parse a SOAP response.
@@ -39,7 +36,7 @@ module TaxCloud #:nodoc:
39
36
  # === Parameters
40
37
  # [savon_response] SOAP response.
41
38
  def parse(savon_response)
42
- self.new(savon_response)
39
+ new(savon_response)
43
40
  end
44
41
  end
45
42
 
@@ -49,40 +46,39 @@ module TaxCloud #:nodoc:
49
46
  # [chain] XML path to match.
50
47
  def match(chain)
51
48
  current_value = raw
52
- chain.split("/").each do |key|
49
+ chain.split('/').each do |key|
53
50
  current_value = current_value[key.to_sym]
54
51
  next if current_value
55
- raise TaxCloud::Errors::UnexpectedSoapResponse.new(raw, key, chain)
52
+ fail TaxCloud::Errors::UnexpectedSoapResponse.new(raw, key, chain)
56
53
  end
57
54
  current_value
58
55
  end
59
56
 
60
57
  private
61
58
 
62
- class_attribute :dsl
59
+ class_attribute :dsl
63
60
 
64
- class << self
65
- def set_dsl(key, value)
66
- self.dsl ||= {}
67
- self.dsl[key] = value
68
- self.dsl
69
- end
61
+ class << self
62
+ def set_dsl(key, value)
63
+ self.dsl ||= {}
64
+ self.dsl[key] = value
65
+ self.dsl
70
66
  end
67
+ end
71
68
 
72
- def parse!
73
- if self.dsl[:response_type]
74
- case match(self.dsl[:response_type])
75
- when "OK", "Informational" then
76
- return true
77
- end
78
- elsif self.dsl[:error_number]
79
- return true if match(self.dsl[:error_number]) == "0"
80
- end
81
- if self.dsl[:error_message]
82
- raise TaxCloud::Errors::ApiError.new(match(self.dsl[:error_message]), raw)
69
+ def parse!
70
+ if self.dsl[:response_type]
71
+ case match(self.dsl[:response_type])
72
+ when 'OK', 'Informational' then
73
+ return true
83
74
  end
75
+ elsif self.dsl[:error_number]
76
+ return true if match(self.dsl[:error_number]) == '0'
84
77
  end
85
-
78
+ if self.dsl[:error_message]
79
+ fail TaxCloud::Errors::ApiError.new(match(self.dsl[:error_message]), raw)
80
+ end
81
+ end
86
82
  end
87
83
  end
88
- end
84
+ end
@@ -1,11 +1,10 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
-
4
3
  # Response to a TaxCloud Captured API call.
5
- #
4
+ #
6
5
  # See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=Captured.
7
6
  class Captured < Generic
8
7
  response_key :captured
9
8
  end
10
9
  end
11
- end
10
+ end
@@ -1,11 +1,9 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
-
4
3
  # A single item in the response to a TaxCloud Lookup API call.
5
- #
4
+ #
6
5
  # See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=Lookup.
7
6
  class CartItem
8
-
9
7
  # The index of the cart item.
10
8
  attr_accessor :cart_item_index
11
9
 
@@ -18,7 +16,6 @@ module TaxCloud #:nodoc:
18
16
  self.cart_item_index = savon_response[:cart_item_index].to_i
19
17
  self.tax_amount = savon_response[:tax_amount].to_f
20
18
  end
21
-
22
19
  end
23
20
  end
24
- end
21
+ end
@@ -1,14 +1,11 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
-
4
3
  # A generic response to a TaxCloud API call.
5
4
  class Generic < Base
6
-
7
5
  # Response key.
8
6
  class_attribute :key
9
7
 
10
8
  class << self
11
-
12
9
  # Set the response key.
13
10
  # === Parameters
14
11
  # [key] Response key.
@@ -25,11 +22,10 @@ module TaxCloud #:nodoc:
25
22
  #
26
23
  # Usually returns "OK" or raises an error.
27
24
  def parse(savon_response)
28
- response = self.new(savon_response)
25
+ response = new(savon_response)
29
26
  response.raw["#{key}_response".to_sym]["#{key}_result".to_sym][:response_type]
30
27
  end
31
28
  end
32
-
33
29
  end
34
30
  end
35
- end
31
+ end
@@ -1,41 +1,38 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
-
4
3
  # Response to a TaxCloud Lookup API call.
5
4
  #
6
5
  # See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=Lookup.
7
6
  class Lookup < Base
8
-
9
7
  # Cart ID.
10
8
  attr_accessor :cart_id
11
9
 
12
10
  # Cart items.
13
11
  attr_accessor :cart_items
14
12
 
15
- response_type "lookup_response/lookup_result/response_type"
16
- error_message "lookup_response/lookup_result/messages/response_message/message"
13
+ response_type 'lookup_response/lookup_result/response_type'
14
+ error_message 'lookup_response/lookup_result/messages/response_message/message'
17
15
 
18
16
  # === Parameters
19
17
  # [savon_response] SOAP response.
20
18
  def initialize(savon_response)
21
19
  super savon_response
22
- self.cart_id = match("lookup_response/lookup_result/cart_id")
20
+ self.cart_id = match('lookup_response/lookup_result/cart_id')
23
21
  # there can be on response or an array of responses
24
- cart_item_responses = match("lookup_response/lookup_result/cart_items_response/cart_item_response")
22
+ cart_item_responses = match('lookup_response/lookup_result/cart_items_response/cart_item_response')
25
23
  if cart_item_responses.is_a?(Array)
26
24
  self.cart_items = cart_item_responses.map do |cart_item_response|
27
25
  TaxCloud::Responses::CartItem.new(cart_item_response)
28
26
  end
29
27
  else
30
- self.cart_items = [ TaxCloud::Responses::CartItem.new(cart_item_responses) ]
28
+ self.cart_items = [TaxCloud::Responses::CartItem.new(cart_item_responses)]
31
29
  end
32
30
  end
33
31
 
34
32
  # Total tax amount in this cart.
35
33
  def tax_amount
36
- cart_items.inject(0) { |acc, item| acc + item.tax_amount }
34
+ cart_items.reduce(0) { |a, e| a + e.tax_amount }
37
35
  end
38
-
39
36
  end
40
37
  end
41
- end
38
+ end
@@ -1,10 +1,10 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
3
  # Response to a TaxCloud Ping API call.
4
- #
4
+ #
5
5
  # See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=Ping.
6
6
  class Ping < Generic
7
7
  response_key :ping
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -1,10 +1,10 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
3
  # Response to a TaxCloud Returned API call.
4
- #
4
+ #
5
5
  # See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=Returned.
6
6
  class Returned < Generic
7
7
  response_key :returned
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -1,33 +1,30 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
-
4
3
  # Response to a TaxCloud getTICGroups API call.
5
4
  #
6
5
  # https://api.taxcloud.net/1.0/TaxCloud.asmx?op=GetTICGroups
7
6
  class TaxCodeGroups < Base
8
-
9
- response_type "get_tic_groups_response/get_tic_groups_result/response_type"
10
- error_message "get_tic_groups_response/get_tic_groups_result/messages/response_message/message"
7
+ response_type 'get_tic_groups_response/get_tic_groups_result/response_type'
8
+ error_message 'get_tic_groups_response/get_tic_groups_result/messages/response_message/message'
11
9
 
12
10
  class << self
13
11
  # Parse a TaxCloud response.
14
12
  #
15
- # === Parameters
13
+ # === Parameters
16
14
  # [savon_response] SOAP response.
17
15
  #
18
16
  # Returns an array of Tax Code Groups.
19
17
  def parse(savon_response)
20
- response = self.new(savon_response)
21
- tax_code_groups = response.match("get_tic_groups_response/get_tic_groups_result/tic_groups/tic_group")
18
+ response = new(savon_response)
19
+ tax_code_groups = response.match('get_tic_groups_response/get_tic_groups_result/tic_groups/tic_group')
22
20
  tax_code_groups.map do |tax_code_group|
23
- TaxCloud::TaxCodeGroup.new({
24
- :group_id => tax_code_group[:group_id].to_i,
25
- :description => tax_code_group[:description].strip
26
- })
21
+ TaxCloud::TaxCodeGroup.new(
22
+ group_id: tax_code_group[:group_id].to_i,
23
+ description: tax_code_group[:description].strip
24
+ )
27
25
  end
28
26
  end
29
27
  end
30
-
31
28
  end
32
29
  end
33
- end
30
+ end
@@ -1,13 +1,11 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
-
4
3
  # Response to a TaxCloud getTICs API call.
5
4
  #
6
5
  # See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=GetTICs.
7
6
  class TaxCodes < Base
8
-
9
- response_type "get_ti_cs_response/get_ti_cs_result/response_type"
10
- error_message "get_ti_cs_response/get_ti_cs_result/messages/response_message/message"
7
+ response_type 'get_ti_cs_response/get_ti_cs_result/response_type'
8
+ error_message 'get_ti_cs_response/get_ti_cs_result/messages/response_message/message'
11
9
 
12
10
  class << self
13
11
  # Parse a TaxCloud response.
@@ -17,17 +15,16 @@ module TaxCloud #:nodoc:
17
15
  #
18
16
  # Returns an array of tax codes.
19
17
  def parse(savon_response)
20
- response = self.new(savon_response)
21
- tax_codes = response.match("get_ti_cs_response/get_ti_cs_result/ti_cs/tic")
18
+ response = new(savon_response)
19
+ tax_codes = response.match('get_ti_cs_response/get_ti_cs_result/ti_cs/tic')
22
20
  tax_codes.map do |tax_code|
23
- TaxCloud::TaxCode.new({
24
- :ticid => tax_code[:ticid].to_i,
25
- :description => tax_code[:description].strip
26
- })
21
+ TaxCloud::TaxCode.new(
22
+ ticid: tax_code[:ticid].to_i,
23
+ description: tax_code[:description].strip
24
+ )
27
25
  end
28
26
  end
29
27
  end
30
-
31
28
  end
32
29
  end
33
- end
30
+ end
@@ -1,33 +1,30 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
-
4
3
  # Response to a TaxCloud getTICsByGroup API call.
5
- #
4
+ #
6
5
  # See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=GetTICsByGroup.
7
6
  class TaxCodesByGroup < Base
8
-
9
- response_type "get_ti_cs_by_group_response/get_ti_cs_by_group_result/response_type"
10
- error_message "get_ti_cs_by_group_response/get_ti_cs_by_group_result/messages/response_message/message"
7
+ response_type 'get_ti_cs_by_group_response/get_ti_cs_by_group_result/response_type'
8
+ error_message 'get_ti_cs_by_group_response/get_ti_cs_by_group_result/messages/response_message/message'
11
9
 
12
10
  class << self
13
11
  # Parse a TaxCloud response.
14
12
  #
15
- # === Parameters
13
+ # === Parameters
16
14
  # [savon_response] SOAP response.
17
15
  #
18
16
  # Returns an array of tax codes.
19
17
  def parse(savon_response)
20
- response = self.new(savon_response)
21
- tax_codes = response.match("get_ti_cs_by_group_response/get_ti_cs_by_group_result/ti_cs/tic")
18
+ response = new(savon_response)
19
+ tax_codes = response.match('get_ti_cs_by_group_response/get_ti_cs_by_group_result/ti_cs/tic')
22
20
  tax_codes.map do |tax_code|
23
- TaxCloud::TaxCode.new({
24
- :ticid => tax_code[:ticid].to_i,
25
- :description => tax_code[:description]
26
- })
21
+ TaxCloud::TaxCode.new(
22
+ ticid: tax_code[:ticid].to_i,
23
+ description: tax_code[:description]
24
+ )
27
25
  end
28
26
  end
29
27
  end
30
-
31
28
  end
32
29
  end
33
- end
30
+ end
@@ -1,14 +1,12 @@
1
1
  module TaxCloud #:nodoc:
2
2
  module Responses #:nodoc:
3
-
4
3
  # Response to a TaxCloud VerifyAddress API call.
5
- #
4
+ #
6
5
  # See https://api.taxcloud.net/1.0/TaxCloud.asmx?op=VerifyAddress.
7
6
  class VerifyAddress < Base
7
+ error_number 'verify_address_response/verify_address_result/err_number'
8
+ error_message 'verify_address_response/verify_address_result/err_description'
8
9
 
9
- error_number "verify_address_response/verify_address_result/err_number"
10
- error_message "verify_address_response/verify_address_result/err_description"
11
-
12
10
  class << self
13
11
  # Parse a TaxCloud response.
14
12
  #
@@ -17,13 +15,12 @@ module TaxCloud #:nodoc:
17
15
  #
18
16
  # Returns a verified TaxCloud::Address.
19
17
  def parse(savon_response)
20
- response = self.new(savon_response)
21
- result = response.match("verify_address_response/verify_address_result")
18
+ response = new(savon_response)
19
+ result = response.match('verify_address_response/verify_address_result')
22
20
  result.delete(:err_number)
23
21
  TaxCloud::Address.new result
24
22
  end
25
23
  end
26
-
27
24
  end
28
25
  end
29
- end
26
+ end