Class: SimpleShipping::Demo::Ups

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_shipping/demo/ups.rb

Overview

Helper object to send demo requests to UPS in order to test credentials and the library.

Examples:

demo = SimpleShipping::Demo::Ups.new(credentials)
response = demo.shipment_request

Instance Attribute Summary collapse

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#recipient, #recipient_address, #recipient_contact, #shipper, #shipper_address, #shipper_contact

Constructor Details

#initialize(options = {}) ⇒ Ups

Returns a new instance of Ups.



10
11
12
13
14
15
# File 'lib/simple_shipping/demo/ups.rb', line 10

def initialize(options = {})
  @options = options.reverse_merge(
      :log          => false,
      :service_type => :second_day_air
  )
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



8
9
10
# File 'lib/simple_shipping/demo/ups.rb', line 8

def credentials
  @credentials
end

Instance Method Details

#packageSimpleShipping::Package

Build the package object.



20
21
22
23
24
25
# File 'lib/simple_shipping/demo/ups.rb', line 20

def package
  @package ||= SimpleShipping::Package.new(
      :weight         => 0.5,
      :packaging_type => :envelope
  )
end

#ship_clientSimpleShipping::Ups::ShipClient

Initialize the UPS client for shipment requests.



30
31
32
33
34
35
# File 'lib/simple_shipping/demo/ups.rb', line 30

def ship_client
  @ship_client ||= SimpleShipping::Ups::ShipClient.new(
      :credentials => options.slice(:username, :password, :access_license_number),
      :log         => options[:log]
  )
end

#shipment_identification_numberString

Shipment Id. The number is picked randomly.

Returns:

  • (String)


51
52
53
# File 'lib/simple_shipping/demo/ups.rb', line 51

def shipment_identification_number
  @shipment_identification_number ||= '1234567890'
end

#shipment_requestShipClient::Ups::ShipmentResponse

Send a shipment request.

Returns:

  • (ShipClient::Ups::ShipmentResponse)


58
59
60
# File 'lib/simple_shipping/demo/ups.rb', line 58

def shipment_request
  ship_client.shipment_request(shipper, recipient, package, :service_type => options[:service_type])
end

#void_clientSimpleShipping::Ups::VoidClient

Initialize the UPS client for void requests.



40
41
42
43
44
45
46
# File 'lib/simple_shipping/demo/ups.rb', line 40

def void_client
  @void_client ||= SimpleShipping::Ups::VoidClient.new(
      :credentials => options.slice(:username, :password, :access_license_number),
      :log         => options[:log],
      :live        => options[:live]
  )
end

#void_requestShipClient::Ups::VoidResponse

Send a request to void a shipment.

Returns:

  • (ShipClient::Ups::VoidResponse)


65
66
67
# File 'lib/simple_shipping/demo/ups.rb', line 65

def void_request
  void_client.void_request(shipment_identification_number)
end