tax_cloud 0.2.2 → 0.3.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.
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
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dce34f03969027431c16d3504d5f02106ae8c086
4
+ data.tar.gz: c55d7e4fa58df6cc206994e42ad2f0bfff8ead2b
5
+ SHA512:
6
+ metadata.gz: 4c0b46885a58ebf4ba0d807d32e7b342d57b5057824d024cc60ab699e32ec5ff9ea2f815ad466362d91e468f962c1bb9b198052052adfed99b74829d4308efc7
7
+ data.tar.gz: 4b909e99313bfcb962d44d124cdaf1b8d2d4c27d1d067549ad00f823d474fbd1c6fe0ffc5912f3fc38aeb7cd6da9677cf89637844c7870b9bdd709642bfb1521
@@ -0,0 +1,29 @@
1
+ AllCops:
2
+ Excludes:
3
+ - vendor/**
4
+ - bin/**
5
+
6
+ LineLength:
7
+ Enabled: false
8
+
9
+ MethodLength:
10
+ Enabled: false
11
+
12
+ ClassLength:
13
+ Enabled: false
14
+
15
+ Documentation:
16
+ # don't require classes to be documented
17
+ Enabled: false
18
+
19
+ NumericLiterals:
20
+ # don't separate numeric literals with _
21
+ Enabled: false
22
+
23
+ RaiseArgs:
24
+ # don't need to provide an exception class and message, SoapError takes care of that
25
+ Enabled: false
26
+
27
+ Encoding:
28
+ # missing UTF-8 comment
29
+ Enabled: false
@@ -1,9 +1,6 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.2
4
2
  - 1.9.3
5
- - ruby-head
6
- - jruby
7
- - rbx
8
- - ree
9
-
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - jruby-19mode
6
+ - rbx-2.1.1
@@ -1,3 +1,9 @@
1
+ === 0.3.0 (1/9/2014)
2
+
3
+ * #19: Support Savon 2 - @drewtempelmeyer.
4
+ * Implemented Rubocop, Ruby style linter - @dblock.
5
+ * Ruby 1.8.7 and 1.9.2 are no longer supported - @dblock.
6
+
1
7
  === 0.2.2 (4/29/2013)
2
8
 
3
9
  * Relaxed thirdparty gem dependency versions - @mperham.
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in tax_cloud.gemspec
4
3
  gemspec
4
+
5
+ platform :rbx do
6
+ gem 'rubysl', '~> 2.0'
7
+ gem 'racc'
8
+ gem 'iconv'
9
+ end
@@ -135,6 +135,6 @@ TaxCloud manages a list of states in which you can calculate sales tax. The defa
135
135
 
136
136
  === License
137
137
 
138
- Copyright Drew Tempelmeyer and contributors, 2011-2013.
138
+ Copyright Drew Tempelmeyer and contributors, 2011-2014.
139
139
 
140
- This gem is licened under the MIT license.
140
+ This gem is licensed under the MIT license.
data/Rakefile CHANGED
@@ -29,4 +29,7 @@ load 'lib/tasks/tax_code_groups.rake'
29
29
 
30
30
  load 'vcr/tasks/vcr.rake'
31
31
 
32
- task :default => :test
32
+ require 'rubocop/rake_task'
33
+ Rubocop::RakeTask.new(:rubocop)
34
+
35
+ task default: [:rubocop, :test]
@@ -1,11 +1,9 @@
1
1
  class Hash #:nodoc: all
2
-
3
2
  # Downcase the keys. Use this because <tt>TaxCloud::Address.verify</tt> requires downcased keys
4
3
  def downcase_keys
5
- inject({}) do |h, (k, v)|
4
+ reduce({}) do |h, (k, v)|
6
5
  h[k.downcase] = v
7
6
  h
8
7
  end
9
8
  end
10
-
11
- end
9
+ end
@@ -1,7 +1,6 @@
1
1
  require 'savon'
2
2
  require 'i18n'
3
3
  require 'hash'
4
- require 'savon_soap_xml'
5
4
  require 'active_support/core_ext'
6
5
 
7
6
  require 'tax_cloud/version'
@@ -20,12 +19,11 @@ require 'tax_cloud/tax_code_group_constants'
20
19
  require 'tax_cloud/configuration'
21
20
  require 'tax_cloud/client'
22
21
 
23
- I18n.load_path << File.join(File.dirname(__FILE__), "config", "locales", "en.yml")
22
+ I18n.load_path << File.join(File.dirname(__FILE__), 'config', 'locales', 'en.yml')
24
23
 
25
24
  # TaxCloud is a web service to calculate and track sales tax for your ecommerce platform. Integration is easy to use.
26
25
  # For information on configuring and using the TaxCloud API, look at the <tt>README</tt> file.
27
26
  module TaxCloud
28
-
29
27
  # WSDL location for TaxCloud API.
30
28
  WSDL_URL = 'https://api.taxcloud.net/1.0/?wsdl'
31
29
 
@@ -33,13 +31,12 @@ module TaxCloud
33
31
  API_VERSION = '1.0'
34
32
 
35
33
  class << self
36
-
37
34
  # TaxCloud gem configuration.
38
35
  attr_accessor :configuration
39
36
 
40
37
  # Returns true if the gem has been configured.
41
38
  def configured?
42
- !! self.configuration
39
+ !!configuration
43
40
  end
44
41
 
45
42
  # Configure the gem.
@@ -51,21 +48,20 @@ module TaxCloud
51
48
  # Reset the current configuration.
52
49
  def reset!
53
50
  self.configuration = nil
51
+ @client = nil
54
52
  end
55
53
 
56
54
  # The configured SOAP client to the TaxCloud service.
57
55
  def client
58
56
  check_configuration!
59
- @@client ||= TaxCloud::Client.new
57
+ @client ||= TaxCloud::Client.new
60
58
  end
61
59
 
62
60
  private
63
61
 
64
- def check_configuration!
65
- raise TaxCloud::Errors::MissingConfig.new unless self.configuration
66
- self.configuration.check!
67
- end
68
-
62
+ def check_configuration!
63
+ fail TaxCloud::Errors::MissingConfig.new unless self.configuration
64
+ self.configuration.check!
65
+ end
69
66
  end
70
-
71
67
  end
@@ -1,7 +1,6 @@
1
1
  module TaxCloud #:nodoc:
2
2
  # An <tt>Address</tt> defines an address in the United States.
3
3
  class Address < Record
4
-
5
4
  # First line of address.
6
5
  attr_accessor :address1
7
6
  # Second line of adress.
@@ -20,9 +19,9 @@ module TaxCloud #:nodoc:
20
19
  # Returns a verified TaxCloud::Address.
21
20
  def verify
22
21
  params = to_hash.downcase_keys
23
- params = params.merge({
22
+ params = params.merge(
24
23
  'uspsUserID' => TaxCloud.configuration.usps_username
25
- }) if TaxCloud.configuration.usps_username
24
+ ) if TaxCloud.configuration.usps_username
26
25
  response = TaxCloud.client.request(:verify_address, params)
27
26
  TaxCloud::Responses::VerifyAddress.parse(response)
28
27
  end
@@ -31,7 +30,7 @@ module TaxCloud #:nodoc:
31
30
  # Returns a 9-digit Zip Code, when available.
32
31
  def zip
33
32
  return nil unless zip5 && zip5.length > 0
34
- [ zip5, zip4 ].select { |z| z && z.length > 0 }.join("-")
33
+ [zip5, zip4].select { |z| z && z.length > 0 }.join('-')
35
34
  end
36
35
 
37
36
  # Convert the object to a usable hash for SOAP requests
@@ -45,6 +44,5 @@ module TaxCloud #:nodoc:
45
44
  'Zip4' => zip4
46
45
  }
47
46
  end
48
-
49
47
  end
50
48
  end
@@ -1,7 +1,6 @@
1
1
  module TaxCloud #:nodoc:
2
2
  # A <tt>CartItem</tt> defines a single line item for the purchase. Used to calculate the tax amount.
3
3
  class CartItem < Record
4
-
5
4
  # The unique index number for the line item. Must be unique for the scope of the cart.
6
5
  attr_accessor :index
7
6
  # The stock keeping unit (SKU) number.
@@ -23,6 +22,5 @@ module TaxCloud #:nodoc:
23
22
  'Qty' => quantity
24
23
  }
25
24
  end
26
-
27
25
  end
28
26
  end
@@ -1,24 +1,27 @@
1
1
  module TaxCloud #:nodoc:
2
- # A <tt>Client</tt> communicates with the TaCloud service.
2
+ # A <tt>Client</tt> communicates with the TaxCloud service.
3
3
  class Client < Savon::Client
4
-
5
4
  # Create a new client.
6
5
  def initialize
7
- super TaxCloud::WSDL_URL
6
+ super wsdl: TaxCloud::WSDL_URL
8
7
  end
9
8
 
10
- # Make a safe SOAP call.
9
+ # Make a safe SOAP call.
11
10
  # Will raise a TaxCloud::Errors::SoapError on error.
12
11
  #
13
12
  # === Parameters
14
13
  # [method] SOAP method.
15
14
  # [body] Body content.
16
- def request(method, body = {})
15
+ def call(method, message = {})
17
16
  safe do
18
- super method, :body => body.merge(auth_params)
17
+ super method, message: message.merge(auth_params)
19
18
  end
20
19
  end
21
20
 
21
+ def request(method, message = {})
22
+ call method, message
23
+ end
24
+
22
25
  # Ping the TaxCloud service.
23
26
  #
24
27
  # Returns "OK" or raises an error if the TaxCloud service is unreachable.
@@ -28,21 +31,19 @@ module TaxCloud #:nodoc:
28
31
 
29
32
  private
30
33
 
31
- # Authorization hash to use with all SOAP requests
32
- def auth_params
33
- {
34
- 'apiLoginID' => TaxCloud.configuration.api_login_id,
35
- 'apiKey' => TaxCloud.configuration.api_key
36
- }
37
- end
38
-
39
- def safe &block
40
- begin
41
- yield
42
- rescue Savon::SOAP::Fault => e
43
- raise TaxCloud::Errors::SoapError.new(e)
44
- end
45
- end
34
+ # Authorization hash to use with all SOAP requests
35
+ def auth_params
36
+ return {} unless TaxCloud.configuration
37
+ {
38
+ 'apiLoginID' => TaxCloud.configuration.api_login_id,
39
+ 'apiKey' => TaxCloud.configuration.api_key
40
+ }
41
+ end
46
42
 
43
+ def safe(&block)
44
+ yield
45
+ rescue Savon::SOAPFault => e
46
+ raise TaxCloud::Errors::SoapError.new(e)
47
+ end
47
48
  end
48
49
  end
@@ -1,7 +1,6 @@
1
1
  module TaxCloud #:nodoc:
2
2
  # TaxCloud gem configuration.
3
3
  class Configuration
4
-
5
4
  # TaxCloud login ID.
6
5
  attr_accessor :api_login_id
7
6
  # TaxCloud API key.
@@ -13,8 +12,8 @@ module TaxCloud #:nodoc:
13
12
  #
14
13
  # Will raise a TaxCloud::Errors::MissingConfigOption if any of the API login ID or the API key are missing.
15
14
  def check!
16
- raise TaxCloud::Errors::MissingConfigOption.new('api_login_id') unless self.api_login_id && self.api_login_id.strip.length > 0
17
- raise TaxCloud::Errors::MissingConfigOption.new('api_key') unless self.api_key && self.api_key.strip.length > 0
15
+ fail TaxCloud::Errors::MissingConfigOption.new('api_login_id') unless api_login_id && api_login_id.strip.length > 0
16
+ fail TaxCloud::Errors::MissingConfigOption.new('api_key') unless api_key && api_key.strip.length > 0
18
17
  end
19
18
  end
20
19
  end
@@ -1,18 +1,18 @@
1
1
  # encoding: utf-8
2
2
  module TaxCloud #:nodoc:
3
3
  module Errors #:nodoc:
4
- # This error is raised when the TaxCloud service
4
+ # This error is raised when the TaxCloud service
5
5
  # returns an error from an API.
6
6
  class ApiError < TaxCloudError
7
7
  # === Parameters
8
8
  # [message] Error message.
9
9
  # [raw] Raw data from the SOAP response.
10
10
  def initialize(message, raw)
11
- super(compose_message("api_error", {
12
- :message => message,
13
- :raw => raw
14
- }))
11
+ super(compose_message('api_error',
12
+ message: message,
13
+ raw: raw
14
+ ))
15
15
  end
16
16
  end
17
17
  end
18
- end
18
+ end
@@ -6,8 +6,8 @@ module TaxCloud #:nodoc:
6
6
  class MissingConfig < TaxCloudError
7
7
  # Create a new error.
8
8
  def initialize
9
- super(compose_message("missing_config"))
9
+ super(compose_message('missing_config'))
10
10
  end
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module TaxCloud #:nodoc:
3
3
  module Errors #:nodoc:
4
- # This error is raised when a configuration
4
+ # This error is raised when a configuration
5
5
  # option is missing.
6
6
  class MissingConfigOption < TaxCloudError
7
7
  # === Parameters
@@ -9,11 +9,11 @@ module TaxCloud #:nodoc:
9
9
  def initialize(name)
10
10
  super(
11
11
  compose_message(
12
- "missing_config_option",
13
- { :name => name }
12
+ 'missing_config_option',
13
+ name: name
14
14
  )
15
15
  )
16
- end
16
+ end
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -3,7 +3,6 @@ module TaxCloud #:nodoc:
3
3
  module Errors #:nodoc:
4
4
  # This error is raised when a SOAP call fails.
5
5
  class SoapError < TaxCloudError
6
-
7
6
  # Original SOAP failt.
8
7
  attr_reader :fault
9
8
 
@@ -15,19 +14,18 @@ module TaxCloud #:nodoc:
15
14
  e.to_hash.tap do |fault|
16
15
  fault_code = fault[:fault][:faultcode]
17
16
  fault_string = parse_fault(fault[:fault][:faultstring])
18
- super(compose_message("soap_error", {
19
- :message => fault_string,
20
- :code => fault_code
21
- }))
17
+ super(compose_message('soap_error',
18
+ message: fault_string,
19
+ code: fault_code
20
+ ))
22
21
  end
23
22
  end
24
23
 
25
24
  private
26
25
 
27
- def parse_fault(fault_string)
28
- fault_string.lines.first.strip
29
- end
30
-
26
+ def parse_fault(fault_string)
27
+ fault_string.lines.first.strip
28
+ end
31
29
  end
32
30
  end
33
- end
31
+ end
@@ -1,14 +1,12 @@
1
1
  # encoding: utf-8
2
2
  module TaxCloud #:nodoc:
3
3
  module Errors #:nodoc:
4
-
5
4
  # Default parent TaxCloud error for all custom errors. This handles the base
6
5
  # key for the translations and provides the convenience method for
7
6
  # translating the messages.
8
7
  #
9
8
  # Generously borrowed from Mongoid[https://github.com/mongoid/mongoid/blob/master/lib/mongoid/errors/mongoid_error.rb].
10
9
  class TaxCloudError < StandardError
11
-
12
10
  # Problem occurred.
13
11
  attr_reader :problem
14
12
 
@@ -27,60 +25,59 @@ module TaxCloud #:nodoc:
27
25
  @summary = create_summary(key, attributes)
28
26
  @resolution = create_resolution(key, attributes)
29
27
 
30
- "\nProblem:\n #{@problem}"+
31
- "\nSummary:\n #{@summary}"+
28
+ "\nProblem:\n #{@problem}" +
29
+ "\nSummary:\n #{@summary}" +
32
30
  "\nResolution:\n #{@resolution}"
33
31
  end
34
32
 
35
33
  private
36
34
 
37
- BASE_KEY = "taxcloud.errors.messages" #:nodoc:
38
-
39
- # Given the key of the specific error and the options hash, translate the
40
- # message.
41
- #
42
- # === Parameters
43
- # [key] The key of the error in the locales.
44
- # [options] The objects to pass to create the message.
45
- #
46
- # Returns a localized error message string.
47
- def translate(key, options)
48
- ::I18n.translate("#{BASE_KEY}.#{key}", { :locale => :en }.merge(options)).strip
49
- end
35
+ BASE_KEY = 'taxcloud.errors.messages' #:nodoc:
50
36
 
51
- # Create the problem.
52
- #
53
- # === Parameters
54
- # [key] The error key.
55
- # [attributes] The attributes to interpolate.
56
- #
57
- # Returns the problem.
58
- def create_problem(key, attributes)
59
- translate("#{key}.message", attributes)
60
- end
37
+ # Given the key of the specific error and the options hash, translate the
38
+ # message.
39
+ #
40
+ # === Parameters
41
+ # [key] The key of the error in the locales.
42
+ # [options] The objects to pass to create the message.
43
+ #
44
+ # Returns a localized error message string.
45
+ def translate(key, options)
46
+ ::I18n.translate("#{BASE_KEY}.#{key}", { locale: :en }.merge(options)).strip
47
+ end
61
48
 
62
- # Create the summary.
63
- #
64
- # === Parameters
65
- # [key] The error key.
66
- # [attributes] The attributes to interpolate.
67
- #
68
- # Returns the summary.
69
- def create_summary(key, attributes)
70
- translate("#{key}.summary", attributes)
71
- end
49
+ # Create the problem.
50
+ #
51
+ # === Parameters
52
+ # [key] The error key.
53
+ # [attributes] The attributes to interpolate.
54
+ #
55
+ # Returns the problem.
56
+ def create_problem(key, attributes)
57
+ translate("#{key}.message", attributes)
58
+ end
72
59
 
73
- # Create the resolution.
74
- #
75
- # === Parameters
76
- # [key] The error key.
77
- # [attributes] The attributes to interpolate.
78
- #
79
- # Returns the resolution.
80
- def create_resolution(key, attributes)
81
- translate("#{key}.resolution", attributes)
82
- end
60
+ # Create the summary.
61
+ #
62
+ # === Parameters
63
+ # [key] The error key.
64
+ # [attributes] The attributes to interpolate.
65
+ #
66
+ # Returns the summary.
67
+ def create_summary(key, attributes)
68
+ translate("#{key}.summary", attributes)
69
+ end
83
70
 
71
+ # Create the resolution.
72
+ #
73
+ # === Parameters
74
+ # [key] The error key.
75
+ # [attributes] The attributes to interpolate.
76
+ #
77
+ # Returns the resolution.
78
+ def create_resolution(key, attributes)
79
+ translate("#{key}.resolution", attributes)
80
+ end
84
81
  end
85
82
  end
86
- end
83
+ end