Class: Fedex::Request::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers, HTTParty
Defined in:
lib/fedex/request/base.rb

Constant Summary collapse

TEST_URL =

Fedex Text URL

"https://wsbeta.fedex.com:443/xml/"
PRODUCTION_URL =

Fedex Production URL

"https://ws.fedex.com:443/xml/"
SERVICE_TYPES =

List of available Service Types

%w(EUROPE_FIRST_INTERNATIONAL_PRIORITY FEDEX_1_DAY_FREIGHT FEDEX_2_DAY FEDEX_2_DAY_AM FEDEX_2_DAY_FREIGHT FEDEX_3_DAY_FREIGHT FEDEX_EXPRESS_SAVER FEDEX_FIRST_FREIGHT FEDEX_FREIGHT_ECONOMY FEDEX_FREIGHT_PRIORITY FEDEX_GROUND FIRST_OVERNIGHT GROUND_HOME_DELIVERY INTERNATIONAL_ECONOMY INTERNATIONAL_ECONOMY_FREIGHT INTERNATIONAL_FIRST INTERNATIONAL_PRIORITY INTERNATIONAL_PRIORITY_FREIGHT PRIORITY_OVERNIGHT SMART_POST STANDARD_OVERNIGHT)
PACKAGING_TYPES =

List of available Packaging Type

%w(FEDEX_10KG_BOX FEDEX_25KG_BOX FEDEX_BOX FEDEX_ENVELOPE FEDEX_PAK FEDEX_TUBE YOUR_PACKAGING)
DROP_OFF_TYPES =

List of available DropOffTypes

%w(BUSINESS_SERVICE_CENTER DROP_BOX REGULAR_PICKUP REQUEST_COURIER STATION)
CLEARANCE_BROKERAGE_TYPE =

Clearance Brokerage Type

%w(BROKER_INCLUSIVE BROKER_INCLUSIVE_NON_RESIDENT_IMPORTER BROKER_SELECT BROKER_SELECT_NON_RESIDENT_IMPORTER BROKER_UNASSIGNED)
RECIPIENT_CUSTOM_ID_TYPE =

Recipient Custom ID Type

%w(COMPANY INDIVIDUAL PASSPORT)
PAYMENT_TYPE =

List of available Payment Types

%w(RECIPIENT SENDER THIRD_PARTY)
CARRIER_CODES =

List of available Carrier Codes

%w(FDXC FDXE FDXG FDCC FXFR FXSP)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials, options = {}) ⇒ Base

In order to use Fedex rates API you must first apply for a developer(and later production keys), Visit / Fedex Developer Center for more information about how to obtain your keys. return a Fedex::Request::Base object

Parameters:

  • key (String)
    • Fedex web service key

  • password (String)
    • Fedex password

  • account_number (String)
    • Fedex account_number

  • meter (String)
    • Fedex meter number

  • mode (String)
    • development/production


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fedex/request/base.rb', line 50

def initialize(credentials, options={})
  requires!(options, :shipper, :recipient, :packages)
  @credentials = credentials
  @shipper, @recipient, @packages, @service_type, @customs_clearance_detail, @debug = options[:shipper], options[:recipient], options[:packages], options[:service_type], options[:customs_clearance_detail], options[:debug]
  @origin = options[:origin]
  @debug = ENV['DEBUG'] == 'true'
  @shipping_options =  options[:shipping_options] ||={}
  @payment_options = options[:payment_options] ||={}
  requires!(@payment_options, :type, :account_number, :name, :company, :phone_number, :country_code) if @payment_options.length > 0
  if options.has_key?(:mps)
    @mps = options[:mps]
    requires!(@mps, :package_count, :total_weight, :sequence_number)
    requires!(@mps, :master_tracking_id) if @mps.has_key?(:sequence_number) && @mps[:sequence_number].to_i >= 2
  else
    @mps = {}
  end
  # Expects hash with addr and port
  if options[:http_proxy]
    self.class.http_proxy options[:http_proxy][:host], options[:http_proxy][:port]
  end
end

Instance Attribute Details

#debugObject

If true the rate method will return the complete response from the Fedex Web Service



13
14
15
# File 'lib/fedex/request/base.rb', line 13

def debug
  @debug
end

Instance Method Details

#process_requestObject

Sends post request to Fedex web service and parse the response. Implemented by each subclass

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/fedex/request/base.rb', line 74

def process_request
  raise NotImplementedError, "Override process_request in subclass"
end