Class: SimpleShipping::Demo::Fedex

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

Overview

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

Examples:

demo     = SimpleShipping::Demo::Fedex.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 = {}) ⇒ Fedex

Returns a new instance of Fedex.



10
11
12
# File 'lib/simple_shipping/demo/fedex.rb', line 10

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

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



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

def credentials
  @credentials
end

Instance Method Details

#fedex_clientSimpleShipping::Fedex::Client

Initialize the FedEx client.



32
33
34
35
36
37
38
# File 'lib/simple_shipping/demo/fedex.rb', line 32

def fedex_client
  @fedex_client ||= SimpleShipping::Fedex::Client.new(
      :credentials => options.slice(:key, :password, :account_number, :meter_number),
      :log         => options[:log],
      :live        => options[:live]
  )
end

#packageSimpleShipping::Package

Build the package object.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/simple_shipping/demo/fedex.rb', line 17

def package
  @package ||= SimpleShipping::Package.new(
      :weight          => 1,
      :length          => 2,
      :height          => 3,
      :dimension_units => :in,  # you can use :kg as well
      :weight_units    => :lb,  # you can use :cm as well
      :width           => 4,
      :packaging_type  => :your
  )
end

#shipment_requestSimpleShipping::Fedex::Response

Send the shipment request to FedEx.



43
44
45
# File 'lib/simple_shipping/demo/fedex.rb', line 43

def shipment_request
  fedex_client.shipment_request(shipper, recipient, package)
end