Class: Fedex::Request::Address

Inherits:
Base
  • Object
show all
Defined in:
lib/fedex/request/address.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

Constructor Details

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

Returns a new instance of Address.



8
9
10
11
12
13
14
# File 'lib/fedex/request/address.rb', line 8

def initialize(credentials, options={})
  requires!(options, :address)
  @credentials = credentials
  @address     = options[:address]

  @address[:address] ||= @address[:street]
end

Instance Method Details

#process_requestObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fedex/request/address.rb', line 16

def process_request
  api_response = self.class.post(api_url, :body => build_xml)
  puts api_response if @debug == true
  response = parse_response(api_response)
  if success?(response)
    options = response[:address_validation_reply][:address_results][:proposed_address_details]
    options = options.first if options.is_a? Array
    Fedex::Address.new(options)
  else
    error_message = if response[:address_validation_reply]
      [response[:address_validation_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
end