Class: Omniship::FedEx

Inherits:
Carrier show all
Defined in:
lib/omniship/carriers/fedex.rb

Overview

:key is your developer API key :password is your API password :account is your FedEx account number :login is your meter number

Constant Summary collapse

TEST_URL =
'https://gatewaybeta.fedex.com:443/xml'
LIVE_URL =
'https://gateway.fedex.com:443/xml'
CarrierCodes =
{
  "fedex_ground"  => "FDXG",
  "fedex_express" => "FDXE"
}
ServiceTypes =
{
  "PRIORITY_OVERNIGHT"                       => "FedEx Priority Overnight",
  "PRIORITY_OVERNIGHT_SATURDAY_DELIVERY"     => "FedEx Priority Overnight Saturday Delivery",
  "FEDEX_2_DAY"                              => "FedEx 2 Day",
  "FEDEX_2_DAY_SATURDAY_DELIVERY"            => "FedEx 2 Day Saturday Delivery",
  "STANDARD_OVERNIGHT"                       => "FedEx Standard Overnight",
  "FIRST_OVERNIGHT"                          => "FedEx First Overnight",
  "FIRST_OVERNIGHT_SATURDAY_DELIVERY"        => "FedEx First Overnight Saturday Delivery",
  "FEDEX_EXPRESS_SAVER"                      => "FedEx Express Saver",
  "FEDEX_1_DAY_FREIGHT"                      => "FedEx 1 Day Freight",
  "FEDEX_1_DAY_FREIGHT_SATURDAY_DELIVERY"    => "FedEx 1 Day Freight Saturday Delivery",
  "FEDEX_2_DAY_FREIGHT"                      => "FedEx 2 Day Freight",
  "FEDEX_2_DAY_FREIGHT_SATURDAY_DELIVERY"    => "FedEx 2 Day Freight Saturday Delivery",
  "FEDEX_3_DAY_FREIGHT"                      => "FedEx 3 Day Freight",
  "FEDEX_3_DAY_FREIGHT_SATURDAY_DELIVERY"    => "FedEx 3 Day Freight Saturday Delivery",
  "INTERNATIONAL_PRIORITY"                   => "FedEx International Priority",
  "INTERNATIONAL_PRIORITY_SATURDAY_DELIVERY" => "FedEx International Priority Saturday Delivery",
  "INTERNATIONAL_ECONOMY"                    => "FedEx International Economy",
  "INTERNATIONAL_FIRST"                      => "FedEx International First",
  "INTERNATIONAL_PRIORITY_FREIGHT"           => "FedEx International Priority Freight",
  "INTERNATIONAL_ECONOMY_FREIGHT"            => "FedEx International Economy Freight",
  "GROUND_HOME_DELIVERY"                     => "FedEx Ground Home Delivery",
  "FEDEX_GROUND"                             => "FedEx Ground",
  "INTERNATIONAL_GROUND"                     => "FedEx International Ground"
}
PackageTypes =
{
  "fedex_envelope"  => "FEDEX_ENVELOPE",
  "fedex_pak"       => "FEDEX_PAK",
  "fedex_box"       => "FEDEX_BOX",
  "fedex_tube"      => "FEDEX_TUBE",
  "fedex_10_kg_box" => "FEDEX_10KG_BOX",
  "fedex_25_kg_box" => "FEDEX_25KG_BOX",
  "your_packaging"  => "YOUR_PACKAGING"
}
DropoffTypes =
{
  'regular_pickup'          => 'REGULAR_PICKUP',
  'request_courier'         => 'REQUEST_COURIER',
  'dropbox'                 => 'DROP_BOX',
  'business_service_center' => 'BUSINESS_SERVICE_CENTER',
  'station'                 => 'STATION'
}
PaymentTypes =
{
  'sender'      => 'SENDER',
  'recipient'   => 'RECIPIENT',
  'third_party' => 'THIRDPARTY',
  'collect'     => 'COLLECT'
}
PackageIdentifierTypes =
{
  'tracking_number'           => 'TRACKING_NUMBER_OR_DOORTAG',
  'door_tag'                  => 'TRACKING_NUMBER_OR_DOORTAG',
  'rma'                       => 'RMA',
  'ground_shipment_id'        => 'GROUND_SHIPMENT_ID',
  'ground_invoice_number'     => 'GROUND_INVOICE_NUMBER',
  'ground_customer_reference' => 'GROUND_CUSTOMER_REFERENCE',
  'ground_po'                 => 'GROUND_PO',
  'express_reference'         => 'EXPRESS_REFERENCE',
  'express_mps_master'        => 'EXPRESS_MPS_MASTER'
}
@@name =
"FedEx"

Instance Attribute Summary

Attributes inherited from Carrier

#last_request, #test_mode

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Carrier

#initialize, #maximum_weight, #valid_credentials?

Constructor Details

This class inherits a constructor from Omniship::Carrier

Class Method Details

.service_name_for_code(service_code) ⇒ Object



85
86
87
88
89
90
# File 'lib/omniship/carriers/fedex.rb', line 85

def self.service_name_for_code(service_code)
  ServiceTypes[service_code] || begin
    name = service_code.downcase.split('_').collect{|word| word.capitalize }.join(' ')
    "FedEx #{name.sub(/Fedex /, '')}"
  end
end

Instance Method Details

#create_shipment(origin, destination, packages, options = {}) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/omniship/carriers/fedex.rb', line 105

def create_shipment(origin, destination, packages, options={})
  options        = @options.merge(options)
  options[:test] = options[:test].nil? ? true : options[:test]
  packages       = Array(packages)
  ship_request   = build_ship_request(origin, destination, packages, options)
  response       = commit(save_request(ship_request.gsub("\n", "")), options[:test])
  parse_ship_response(response, options)
end

#delete_shipment(tracking_number, shipment_type, options = {}) ⇒ Object



114
115
116
117
118
119
# File 'lib/omniship/carriers/fedex.rb', line 114

def delete_shipment(tracking_number, shipment_type, options={})
  options                 = @options.merge(options)
  delete_shipment_request = build_delete_request(tracking_number, shipment_type, options)
  response                = commit(save_request(delete_shipment_request.gsub("\n", "")), options[:test])
  parse_delete_response(response, options)
end

#find_rates(origin, destination, packages, options = {}) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/omniship/carriers/fedex.rb', line 96

def find_rates(origin, destination, packages, options = {})
  options        = @options.merge(options)
  options[:test] = options[:test].nil? ? true : options[:test]
  packages       = Array(packages)
  rate_request   = build_rate_request(origin, destination, packages, options)
  response       = commit(save_request(rate_request.gsub("\n", "")), options[:test])
  parse_rate_response(origin, destination, packages, response, options)
end

#find_tracking_info(tracking_number, options = {}) ⇒ Object



121
122
123
124
125
126
# File 'lib/omniship/carriers/fedex.rb', line 121

def find_tracking_info(tracking_number, options={})
  options          = @options.update(options)
  tracking_request = build_tracking_request(tracking_number, options)
  response         = commit(save_request(tracking_request), (options[:test] || false)).gsub(/<(\/)?.*?\:(.*?)>/, '<\1\2>')
  parse_tracking_response(response, options)
end

#requirementsObject



92
93
94
# File 'lib/omniship/carriers/fedex.rb', line 92

def requirements
  [:key, :account, :meter, :password]
end