class Fedex::Request::ServiceAvailability
Public Class Methods
new(credentials, options={})
click to toggle source
# File lib/fedex/request/service_availability.rb, line 6 def initialize(credentials, options={}) requires!(options, :origin, :destination, :ship_date, :carrier_code) @credentials = credentials @origin = options[:origin] @destination = options[:destination] @ship_date = options[:ship_date] @carrier_code = options[:carrier_code] end
Public Instance Methods
add_destination(xml)
click to toggle source
# File lib/fedex/request/service_availability.rb, line 48 def add_destination(xml) xml.Destination{ xml.PostalCode @destination[:postal_code] xml.CountryCode @destination[:country_code] } end
add_origin(xml)
click to toggle source
# File lib/fedex/request/service_availability.rb, line 41 def add_origin(xml) xml.Origin{ xml.PostalCode @origin[:postal_code] xml.CountryCode @origin[:country_code] } end
add_other_details(xml)
click to toggle source
# File lib/fedex/request/service_availability.rb, line 55 def add_other_details(xml) xml.ShipDate @ship_date xml.CarrierCode @carrier_code end
build_xml()
click to toggle source
# File lib/fedex/request/service_availability.rb, line 27 def build_xml builder = Nokogiri::XML::Builder.new do |xml| xml.ServiceAvailabilityRequest(:xmlns => "http://fedex.com/ws/packagemovementinformationservice/v#{service[:version]}"){ add_web_authentication_detail(xml) add_client_detail(xml) add_version(xml) add_origin(xml) add_destination(xml) add_other_details(xml) } end builder.doc.root.to_xml end
failure_response(api_response, response)
click to toggle source
Callback used after a failed shipment response.
# File lib/fedex/request/service_availability.rb, line 61 def failure_response(api_response, response) error_message = if response[:service_availability_reply] [response[:service_availability_reply][:notifications]].flatten.first[:message] else "#{api_response["Fault"]["detail"]["fault"]["reason"]}\n--#{api_response["Fault"]["detail"]["fault"]["details"]["ValidationFailureDetail"]["message"].join("\n--")}" end rescue $1 raise RateError, error_message end
process_request()
click to toggle source
# File lib/fedex/request/service_availability.rb, line 16 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
service()
click to toggle source
# File lib/fedex/request/service_availability.rb, line 75 def service { :id => 'pmis', :version => Fedex::SERVICE_AVAILABILITY_API_VERSION } end
success?(response)
click to toggle source
Successful request
# File lib/fedex/request/service_availability.rb, line 80 def success?(response) response[:service_availability_reply] && %w{SUCCESS WARNING NOTE}.include?(response[:service_availability_reply][:highest_severity]) end
success_response(api_response, response)
click to toggle source
Callback used after a successful shipment response.
# File lib/fedex/request/service_availability.rb, line 71 def success_response(api_response, response) @response_details = response[:service_availability_reply] end