Class: Temando::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/temando/request.rb

Overview

Temando::Request represents a request for a quotation from the Temando API.

It is used to construct the parameters for a quotation, send them off to the API and return the available quotes.

Example:

request = Temando::Request.new

# Add the items to be shipped
request.items << Temando::Item::GeneralGoods.new(...)
request.items << Temando::Item::GeneralGoods.new(...)

# Add the details for the actual shipment method and its locations
anywhere = Temando::Delivery::DoorToDoor.new
anywhere.origin      = Temando::Location.new(...)
anywhere.destination = Temando::Location.new(...)

# Ask the server for the quotes
quotes = request.quotes_for(anywhere)

quotes.first # => #<Temando::Quote>

Temando authentication details should be set before calling these methods :

Temando::Api::Base.config.username = '[email protected]'
Temando::Api::Base.config.password = 'sekrit'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequest

Returns a new instance of Request.



33
34
35
# File 'lib/temando/request.rb', line 33

def initialize
  @items = []
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



31
32
33
# File 'lib/temando/request.rb', line 31

def items
  @items
end

Instance Method Details

#clientObject



45
46
47
# File 'lib/temando/request.rb', line 45

def client
  @client ||= Temando::Api::SoapClient.new
end

#quotes_for(delivery) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/temando/request.rb', line 37

def quotes_for(delivery)
  # Construct the request, dispatch it off to the server and return
  # the result.
  formatter = Temando::Api::GetQuotesByRequest.new(@items, delivery)
  response  = client.dispatch(formatter.request_xml)
  formatter.parse_response(response)
end