Class: Fedex::Request::Address

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

Constant Summary

Constants inherited from Base

Base::CLEARANCE_BROKERAGE_TYPE, Base::DROP_OFF_TYPES, Base::PACKAGING_TYPES, 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
# File 'lib/fedex/request/address.rb', line 8

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

Instance Method Details

#process_requestObject



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

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]

    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"]
    end rescue $1
    raise RateError, error_message
  end
end