Class: CargowiseTS::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cargowise-ts/client.rb

Overview

The starting point for accessing data from your logistics provider. See the README for usage tips.

You should create a new Client instance for each company API you plan to query.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
22
23
# File 'lib/cargowise-ts/client.rb', line 17

def initialize(opts = {})
  @order_uri = opts[:order_uri]
  @shipment_uri = opts[:shipment_uri]
  @code = opts[:company_code]
  @username = opts[:username]
  @password = opts[:password]
end

Instance Method Details

#base_uriObject

Find the base URI for the web interface at this client



49
50
51
52
# File 'lib/cargowise-ts/client.rb', line 49

def base_uri
  uri = @shipment_uri || @order_uri || ""
  uri.to_s[/(.+)\/WebService.+/,1]
end

#ordersObject

begin an order search. See the docs for CargowiseTS::OrderSearch for info on what you can do with the object returned from this method.



27
28
29
# File 'lib/cargowise-ts/client.rb', line 27

def orders
  OrderSearch.new(orders_client)
end

#orders_helloObject



37
38
39
40
# File 'lib/cargowise-ts/client.rb', line 37

def orders_hello
  response = orders_client.call(:hello)
  response.xpath("//tns:HelloResponse/tns:HelloResult/text()", {"tns" => CargowiseTS::DEFAULT_NS}).to_s
end

#shipmentsObject

begin a shipment search. See the docs for CargowiseTS::ShipmentSearch for info on what you can do with the object returned from this method.



33
34
35
# File 'lib/cargowise-ts/client.rb', line 33

def shipments
  ShipmentSearch.new(shipments_client)
end

#shipments_helloObject



42
43
44
45
# File 'lib/cargowise-ts/client.rb', line 42

def shipments_hello
  response = shipments_client.call(:hello)
  response.xpath("//tns:HelloResponse/tns:HelloResult/text()", {"tns" => CargowiseTS::DEFAULT_NS}).to_s
end