strikeiron2 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7685d04a103055ad322859be6238c7341d56d64e
4
+ data.tar.gz: 027fef100b7b0547c243ffca404d2d4e80a5744d
5
+ SHA512:
6
+ metadata.gz: a2bfeeb62393f4b5aca6013bf09d595c6c0864192af8a36ef01beca831ca7b3c3fe45beff26ac5193a95d03fc4e894bfe2e55122bd4b2004bc7d3b93a7c37ac2
7
+ data.tar.gz: 19e4d0cfc52de1bf5f825f267d876a53a886360e5cf0a269f06d6e0c246e2202d95ee411b4daaaefd930fe70fb59b1cbe7721e24416c0375276ad60a9d6f2e40
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in strikeiron2.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Chris Sturgill
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Strikeiron2
2
+
3
+ Gem for interacting with StrikeIron's API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'strikeiron2'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install strikeiron2
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,67 @@
1
+ require 'savon'
2
+ require "strikeiron2/version"
3
+ require "strikeiron2/exceptions"
4
+ require "strikeiron2/configuration"
5
+ require "strikeiron2/client"
6
+ require 'strikeiron2/address'
7
+ require 'strikeiron2/jurisdiction'
8
+ require 'strikeiron2/tax_result'
9
+ require 'strikeiron2/tax_value'
10
+
11
+ module Strikeiron
12
+ class << self
13
+ attr_accessor :configuration
14
+
15
+ def configure
16
+ self.configuration ||= Configuration.new
17
+ yield configuration
18
+ end
19
+
20
+ def client
21
+ @@client ||= nil
22
+ return @@client if !@@client.nil?
23
+ raise Strikeiron::ConfigurationException, 'You must set up your configuration before making requests' if configuration.nil?
24
+ @@client = Client.new configuration
25
+ end
26
+
27
+ def sales_tax(options={})
28
+ options = options.inject({}) { |hsh,(k,v)| hsh[k.to_sym] = v; hsh }
29
+ required_options = [:from, :to, :tax_values]
30
+
31
+ # Raise an error if a required option is not defined
32
+ raise ArgumentError, "You must pass all required options: #{required_options}" if (required_options - options.keys).length > 0
33
+
34
+ data = {
35
+ 'ShipFrom' => options[:from].to_soap,
36
+ 'ShipTo' => options[:to].to_soap,
37
+ 'TaxValueRequests' => { 'TaxValueRequest' => options[:tax_values].collect(&:to_soap) }
38
+ }
39
+
40
+ response = self.client.request :get_sales_tax_value, data
41
+ response_code = response.body[:get_sales_tax_value_response][:get_sales_tax_value_result][:service_status][:status_nbr].to_i
42
+
43
+ case response_code
44
+ when 401 then raise Strikeiron::AddressException, 'Invalid From address.'
45
+ when 402 then raise Strikeiron::AddressException, 'Invalid To address.'
46
+ when 403 then raise Strikeiron::TaxCategoryException, 'Invalid Taxability category.'
47
+ when 500 then raise Strikeiron::InternalError, 'Internal Strikeiron server error.'
48
+ end
49
+
50
+ TaxResult.from_soap(response.body[:get_sales_tax_value_response][:get_sales_tax_value_result][:service_result])
51
+ end
52
+
53
+ def tax_categories
54
+ response = self.client.request :get_sales_tax_categories
55
+
56
+ # Return an empty array if the response was not successful
57
+ return [] if response.body[:get_sales_tax_categories_response][:get_sales_tax_categories_result][:service_status][:status_nbr].to_i != 200
58
+
59
+ response.body[:get_sales_tax_categories_response][:get_sales_tax_categories_result][:service_result][:sales_tax_category]
60
+ end
61
+
62
+ def remaining_hits
63
+ response = self.client.request :get_remaining_hits
64
+ response.body[:si_subscription_info][:remaining_hits].to_i
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,36 @@
1
+ module Strikeiron
2
+ class Address
3
+ attr_accessor :street_address, :city, :state, :zip_code
4
+
5
+ # Creates an Address with the supplied attributes.
6
+ def initialize(default_values = {})
7
+ safe_keys = %w(street_address city state zip_code)
8
+
9
+ default_values.each do |key, value|
10
+ next unless safe_keys.include? key.to_s # Only permit the keys defined in safe_keys
11
+ self.send "#{key}=", value
12
+ end
13
+ end
14
+
15
+ # Convert the object to a Hash for SOAP
16
+ def to_soap
17
+ {
18
+ 'StreetAddress' => street_address,
19
+ 'City' => city,
20
+ 'State' => state,
21
+ 'ZIPCode' => zip_code
22
+ }
23
+ end
24
+
25
+ # Convert the object from a SOAP response to an Address object
26
+ def self.from_soap(hash = {})
27
+ default_values = {
28
+ :street_address => hash['StreetAddress'],
29
+ :city => hash['City'],
30
+ :state => hash['State'],
31
+ :zip_code => hash['ZIPCode']
32
+ }
33
+ new(default_values)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ module Strikeiron
2
+ class Client
3
+ # The location of the Strikeiron Online Sales Tax WSDL
4
+ WSDL = 'https://wsparam.strikeiron.com/SpeedTaxSalesTax3?WSDL'
5
+
6
+ def initialize(configuration)
7
+ @configuration = configuration
8
+ @savon_client = Savon::Client.new(:wsdl => WSDL, :ssl_version => @configuration.ssl_version, :ssl_verify_mode => @configuration.ssl_verify_mode)
9
+ end
10
+
11
+ def request(action, msg={})
12
+ msg = { 'UserID' => @configuration.user_id, 'Password' => @configuration.password }.merge(msg)
13
+ @savon_client.call action, :message => msg
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Strikeiron
2
+ class Configuration
3
+ attr_accessor :user_id, :password, :ssl_version, :ssl_verify_mode
4
+
5
+ def initialize
6
+ # set default options (can be overwritten in configure block)
7
+ self.ssl_version = :TLSv1
8
+ self.ssl_verify_mode = :none
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ class Strikeiron::ConfigurationException < StandardError; end
2
+ class Strikeiron::AddressException < StandardError; end
3
+ class Strikeiron::TaxCategoryException < StandardError; end
4
+ class Strikeiron::InternalError < StandardError; end
@@ -0,0 +1,33 @@
1
+ module Strikeiron #:nodoc:
2
+ # Jurisdiction represents a breakdown of the tax calculations for the taxable region(s).
3
+ #
4
+ # === Attributes
5
+ # * <tt>fips</tt> - The code assigned by the Federal Government or state agencies to uniquely identify a location.
6
+ # * <tt>name</tt> - Name associated to the corresponding FIPS code.
7
+ # * <tt>tax_amount</tt> - Sales tax rate for the corresponding FIPS code.
8
+ class Jurisdiction
9
+ attr_accessor :fips, :name, :tax_amount
10
+
11
+ # Creates a Jurisdiction with the supplied attributes.
12
+ def initialize(default_values = {})
13
+ safe_keys = %w(fips name tax_amount)
14
+
15
+ default_values.each do |key, value|
16
+ next unless safe_keys.include? key.to_s # Only permit the keys defined in safe_keys
17
+ self.send "#{key}=", value
18
+ end
19
+ end
20
+
21
+ # Convert the SOAP response object to a Jurisdiction
22
+ def self.from_soap(hash = {})
23
+ default_values = {
24
+ :fips => hash['FIPS'],
25
+ :name => hash['Name'],
26
+ :tax_amount => hash['SalesTaxAmount']
27
+ }
28
+
29
+ new(default_values)
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,34 @@
1
+ module Strikeiron
2
+ class TaxResult
3
+ attr_accessor :from, :to, :tax_values, :total_tax
4
+
5
+ def initialize(default_values = {})
6
+ default_values.each { |key, value| self.send "#{key}=", value }
7
+ end
8
+
9
+ def self.from_soap(response)
10
+ tax_values = []
11
+ response_records = response[:results][:tax_value_record]
12
+ response_records = [ response_records ] if response_records.is_a?(Hash)
13
+
14
+ response_records.each do |record|
15
+ jurisdictions = record[:jurisdictions][:sales_tax_value_jurisdiction]
16
+ jurisdictions = [ jurisdictions ] if jurisdictions.is_a?(Hash)
17
+
18
+ tax_values << TaxValue.new(
19
+ :category => record[:category],
20
+ :category_id => record[:category_id],
21
+ :tax_amount => record[:sales_tax_amount].to_f,
22
+ :jurisdictions => jurisdictions.collect { |j| Jurisdiction.new(:fips => j[:fips], :name => j[:name], :tax_amount => j[:sales_tax_amount].to_f) }
23
+ )
24
+ end
25
+
26
+ new(
27
+ :from => Address.new(response[:resolved_from_address]),
28
+ :to => Address.new(response[:resolved_to_address]),
29
+ :tax_values => tax_values,
30
+ :total_tax => tax_values.inject(0) { |sum, tax_value| sum + tax_value.tax_amount }
31
+ )
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,45 @@
1
+ module Strikeiron #:nodoc:
2
+ # Total sales tax rate based on the dollar amount and category from TaxValueRequest.
3
+ # TaxValueRecord should only be rendered from a SOAP response.
4
+ #
5
+ # === Attributes
6
+ # * <tt>category</tt> - The corresponding category name. A category name and/or ID must be supplied.
7
+ # * <tt>category_id</tt> - The corresponding category ID. A category name and/or ID must be supplied.
8
+ # * <tt>amount</tt> - The amount to calculate the tax for.
9
+ # * <tt>tax_amount</tt> - The combined sales tax rate based on the address and tax category provided
10
+ #
11
+ # === Notes
12
+ # See Strikeiron.tax_categories for information on obtaining category information.
13
+ class TaxValue
14
+ attr_accessor :category, :category_id, :amount, :tax_amount, :jurisdictions
15
+
16
+ # Creates a TaxValueRecord with the supplied attributes.
17
+ def initialize(default_values = {})
18
+ safe_keys = %w(category category_id amount tax_amount jurisdictions)
19
+
20
+ default_values.each do |key, value|
21
+ next unless safe_keys.include? key.to_s # Only permit the keys defined in safe_keys
22
+ self.send "#{key}=", value
23
+ end
24
+ end
25
+
26
+ # Convert the object to be valid for the SOAP request
27
+ def to_soap
28
+ {
29
+ 'SalesTaxCategoryOrCategoryID' => category || category_id,
30
+ 'Amount' => amount
31
+ }
32
+ end
33
+
34
+ # Convert the SOAP response object to a TaxValueRecord
35
+ def self.from_soap(hash = {})
36
+ default_values = {
37
+ :category => hash['Category'],
38
+ :category_id => hash['CategoryID'],
39
+ :tax_amount => hash['SalesTaxAmount']
40
+ }
41
+
42
+ new(default_values)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Strikeiron
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'strikeiron2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "strikeiron2"
8
+ spec.version = Strikeiron::VERSION
9
+ spec.authors = ["Chris Sturgill"]
10
+ spec.email = ["chris@thesturgills.com"]
11
+ spec.description = %q{Write a gem description}
12
+ spec.summary = %q{Write a gem summary}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'savon', '2.8.0'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strikeiron2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Sturgill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: savon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Write a gem description
56
+ email:
57
+ - chris@thesturgills.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/strikeiron2.rb
68
+ - lib/strikeiron2/address.rb
69
+ - lib/strikeiron2/client.rb
70
+ - lib/strikeiron2/configuration.rb
71
+ - lib/strikeiron2/exceptions.rb
72
+ - lib/strikeiron2/jurisdiction.rb
73
+ - lib/strikeiron2/tax_result.rb
74
+ - lib/strikeiron2/tax_value.rb
75
+ - lib/strikeiron2/version.rb
76
+ - strikeiron2.gemspec
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.14
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Write a gem summary
101
+ test_files: []