Class: TaxCloud::Responses::Lookup

Inherits:
Base
  • Object
show all
Defined in:
lib/tax_cloud/responses/lookup.rb

Overview

Response to a TaxCloud Lookup API call.

See api.taxcloud.net/1.0/TaxCloud.asmx?op=Lookup.

Instance Attribute Summary collapse

Attributes inherited from Base

#raw

Instance Method Summary collapse

Methods inherited from Base

error_message, error_number, #match, parse, response_type, set_dsl

Constructor Details

#initialize(savon_response) ⇒ Lookup

Parameters

savon_response

SOAP response.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tax_cloud/responses/lookup.rb', line 18

def initialize(savon_response)
  super savon_response
  self.cart_id = match('lookup_response/lookup_result/cart_id')
  # there can be on response or an array of responses
  cart_item_responses = match('lookup_response/lookup_result/cart_items_response/cart_item_response')
  if cart_item_responses.is_a?(Array)
    self.cart_items = cart_item_responses.map do |cart_item_response|
      TaxCloud::Responses::CartItem.new(cart_item_response)
    end
  else
    self.cart_items = [TaxCloud::Responses::CartItem.new(cart_item_responses)]
  end
end

Instance Attribute Details

#cart_idObject

Cart ID.



8
9
10
# File 'lib/tax_cloud/responses/lookup.rb', line 8

def cart_id
  @cart_id
end

#cart_itemsObject

Cart items.



11
12
13
# File 'lib/tax_cloud/responses/lookup.rb', line 11

def cart_items
  @cart_items
end

Instance Method Details

#tax_amountObject

Total tax amount in this cart.



33
34
35
# File 'lib/tax_cloud/responses/lookup.rb', line 33

def tax_amount
  cart_items.reduce(0) { |a, e| a + e.tax_amount }
end