Module: Strikeiron

Defined in:
lib/strikeiron2/tax_value.rb,
lib/strikeiron2.rb,
lib/strikeiron2/client.rb,
lib/strikeiron2/address.rb,
lib/strikeiron2/version.rb,
lib/strikeiron2/tax_result.rb,
lib/strikeiron2/jurisdiction.rb,
lib/strikeiron2/configuration.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Address, AddressException, Client, Configuration, ConfigurationException, InternalError, Jurisdiction, TaxCategoryException, TaxResult, TaxValue

Constant Summary collapse

VERSION =
"0.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



13
14
15
# File 'lib/strikeiron2.rb', line 13

def configuration
  @configuration
end

Class Method Details

.clientObject



20
21
22
23
24
25
# File 'lib/strikeiron2.rb', line 20

def client
  @@client ||= nil
  return @@client if !@@client.nil?
  raise Strikeiron::ConfigurationException, 'You must set up your configuration before making requests' if configuration.nil?
  @@client = Client.new configuration
end

.configure {|configuration| ... } ⇒ Object

Yields:



15
16
17
18
# File 'lib/strikeiron2.rb', line 15

def configure
  self.configuration ||= Configuration.new
  yield configuration
end

.remaining_hitsObject



62
63
64
65
# File 'lib/strikeiron2.rb', line 62

def remaining_hits
  response = self.client.request :get_remaining_hits
  response.body[:si_subscription_info][:remaining_hits].to_i
end

.sales_tax(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/strikeiron2.rb', line 27

def sales_tax(options={})
  options = options.inject({}) { |hsh,(k,v)| hsh[k.to_sym] = v; hsh }
  required_options = [:from, :to, :tax_values]
  
  # Raise an error if a required option is not defined
  raise ArgumentError, "You must pass all required options: #{required_options}" if (required_options - options.keys).length > 0
  
  data = {
    'ShipFrom' => options[:from].to_soap,
    'ShipTo' => options[:to].to_soap,
    'TaxValueRequests' => { 'TaxValueRequest' => options[:tax_values].collect(&:to_soap) }
  }
  
  response = self.client.request :get_sales_tax_value, data
  response_code = response.body[:get_sales_tax_value_response][:get_sales_tax_value_result][:service_status][:status_nbr].to_i
  
  case response_code
  when 401 then raise Strikeiron::AddressException, 'Invalid From address.'
  when 402 then raise Strikeiron::AddressException, 'Invalid To address.'
  when 403 then raise Strikeiron::TaxCategoryException, 'Invalid Taxability category.'
  when 500 then raise Strikeiron::InternalError, 'Internal Strikeiron server error.'
  end
  
  TaxResult.from_soap(response.body[:get_sales_tax_value_response][:get_sales_tax_value_result][:service_result])
end

.tax_categoriesObject



53
54
55
56
57
58
59
60
# File 'lib/strikeiron2.rb', line 53

def tax_categories
  response = self.client.request :get_sales_tax_categories
  
  # Return an empty array if the response was not successful
  return [] if response.body[:get_sales_tax_categories_response][:get_sales_tax_categories_result][:service_status][:status_nbr].to_i != 200
  
  response.body[:get_sales_tax_categories_response][:get_sales_tax_categories_result][:service_result][:sales_tax_category]
end