Class: Fedex::Request::Shipment

Inherits:
Base
  • Object
show all
Defined in:
lib/fedex/request/shipment.rb

Constant Summary

Constants inherited from Base

Base::CARRIER_CODES, Base::CLEARANCE_BROKERAGE_TYPE, Base::DROP_OFF_TYPES, Base::PACKAGING_TYPES, Base::PAYMENT_TYPE, Base::PRODUCTION_URL, Base::RECIPIENT_CUSTOM_ID_TYPE, Base::SERVICE_TYPES, Base::TEST_URL

Instance Attribute Summary collapse

Attributes inherited from Base

#debug

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Shipment.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fedex/request/shipment.rb', line 8

def initialize(credentials, options={})
  super
  requires!(options, :service_type)
  # Label specification is required even if we're not using it.
  @label_specification = {
    :label_format_type => 'COMMON2D',
    :image_type => 'PDF',
    :label_stock_type => 'PAPER_LETTER'
  }
  @label_specification.merge! options[:label_specification] if options[:label_specification]
  @customer_specified_detail = options[:customer_specified_detail] if options[:customer_specified_detail]
end

Instance Attribute Details

#response_detailsObject (readonly)

Returns the value of attribute response_details.



6
7
8
# File 'lib/fedex/request/shipment.rb', line 6

def response_details
  @response_details
end

Instance Method Details

#process_requestObject

Sends post request to Fedex web service and parse the response. A label file is created with the label at the specified location. The parsed Fedex response is available in #response_details e.g. response_details[:completed_package_details][:tracking_number]



25
26
27
28
29
30
31
32
33
34
# File 'lib/fedex/request/shipment.rb', line 25

def process_request
  api_response = self.class.post api_url, :body => build_xml
  puts api_response if @debug
  response = parse_response(api_response)
  if success?(response)
    success_response(api_response, response)
  else
    failure_response(api_response, response)
  end
end