Class: FedexShip::Request::Pickup

Inherits:
LogsFedex show all
Defined in:
lib/fedex_ship/request/pickup.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

Attributes inherited from Base

#debug

Instance Method Summary collapse

Methods inherited from LogsFedex

#delete_ship_serv_log, #pickup_serv_log, #rate_serv_log, #ship_serv_log, #track_serv_log

Constructor Details

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

Returns a new instance of Pickup.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fedex_ship/request/pickup.rb', line 7

def initialize(credentials, options = {})
  requires!(options, :packages, :ready_timestamp, :close_time, :carrier_code, :country_relationship)
  @debug = ENV['DEBUG'] == 'true'

  @credentials = credentials
  @packages = options[:packages]
  @ready_timestamp = options[:ready_timestamp]
  @close_time = options[:close_time]
  @carrier_code = options[:carrier_code]
  @remarks = options[:remarks] if options[:remarks]
  @pickup_location = options[:pickup_location]
  @commodity_description = options[:commodity_description] if options[:commodity_description]
  @country_relationship = options[:country_relationship]
end

Instance Method Details

#process_requestObject

Sends post request to Fedex web service and parse the response, a Pickup object is created if the response is successful



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fedex_ship/request/pickup.rb', line 23

def process_request
  @build_xml = build_xml
  pickup_serv_log('Final XML Request : ' + @build_xml.to_s)
  api_url_srv = api_url + "/pickup"
  pickup_serv_log('URL for API : ' + api_url_srv.to_s)
  api_response = self.class.post(api_url_srv, :body => build_xml)
  pickup_serv_log('API Response : ' + api_response.to_s)
  puts api_response if @debug
  response = parse_response(api_response)
  if success?(response)
    pickup_serv_log('Successfully Done : ' + response.to_s)
    success_response(api_response, response)
  else
    failure_response(api_response, response)
  end
end