Class: Temando::Api::GetQuotesByRequest

Inherits:
Base
  • Object
show all
Defined in:
lib/temando/api/get_quotes_by_request.rb

Overview

Abstracts generating the request for the SOAP API’s getQuotesByRequest method, and parsing the response.

Constant Summary

Constants inherited from Base

Base::TEMANDO_NAMESPACE

Instance Method Summary collapse

Methods inherited from Base

#soap_boilerplate

Constructor Details

#initialize(items, delivery) ⇒ GetQuotesByRequest

Returns a new instance of GetQuotesByRequest.



7
8
9
10
11
12
# File 'lib/temando/api/get_quotes_by_request.rb', line 7

def initialize(items, delivery)
  @items = items
  @delivery = delivery

  @items.each { |item| validate_item(item) }
end

Instance Method Details

#parse_response(response_xml) ⇒ Object



34
35
36
37
38
39
# File 'lib/temando/api/get_quotes_by_request.rb', line 34

def parse_response(response_xml)
  xml = Nokogiri::XML(response_xml)
  quotes = xml.xpath('//quote').collect do |result|
    Temando::Api::Entities::Quote.parse_xml(result.to_xml)
  end
end

#request_xmlObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/temando/api/get_quotes_by_request.rb', line 14

def request_xml
  soap_boilerplate do |xml|
    xml.getQuotesByRequest('xmlns:tem' => TEMANDO_NAMESPACE) do
      xml.parent.namespace = xml.parent.namespace_definitions.find { |x| x.prefix == 'tem' }

      xml.anythings do
        xml.parent.namespace = nil
        @items.each do |anything|
          Temando::Api::Entities::Anything.new(anything).build_xml(xml)
        end
      end

      Temando::Api::Entities::Anywhere.new(@delivery).build_xml(xml)

      # TODO: anytime
      # TODO: general
    end
  end
end