Module: DialAZip
- Included in:
- Endpost
- Defined in:
- lib/dial_a_zip.rb
Constant Summary collapse
- DIAL_A_ZIP_BASE_URL =
'http://www.dial-a-zip.com/XML-Dial-A-ZIP/DAZService.asmx'- DIAL_A_ZIP_RESPONSE_MESSAGES =
{ '10' => 'More than one delivery address was detected', '11' => 'ZIP Code could not be found', '12' => 'The State code is invalid', '13' => 'The City is invalid', '21' => 'The address as submitted could not be found', '22' => 'More than one ZIP code was found', '25' => 'The Street address is invalid', '31' => 'Exact Match', '32' => 'More information, such as an apartment or suite number, may give a more specific address.', }
- DIAL_A_ZIP_ADDRESS_NOT_FOUND_MESSAGE =
'The address as submitted could not be found'
Instance Attribute Summary collapse
-
#dial_a_zip_password ⇒ Object
Returns the value of attribute dial_a_zip_password.
-
#dial_a_zip_user ⇒ Object
Returns the value of attribute dial_a_zip_user.
Instance Method Summary collapse
Instance Attribute Details
#dial_a_zip_password ⇒ Object
Returns the value of attribute dial_a_zip_password.
18 19 20 |
# File 'lib/dial_a_zip.rb', line 18 def dial_a_zip_password @dial_a_zip_password end |
#dial_a_zip_user ⇒ Object
Returns the value of attribute dial_a_zip_user.
18 19 20 |
# File 'lib/dial_a_zip.rb', line 18 def dial_a_zip_user @dial_a_zip_user end |
Instance Method Details
#verify_address(address) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dial_a_zip.rb', line 20 def verify_address(address) xml = %! <VERIFYADDRESS> <COMMAND>ZIP1</COMMAND> <SERIALNO>#{dial_a_zip_user}</SERIALNO> <USER>#{dial_a_zip_user}</USER> <PASSWORD>#{dial_a_zip_password}</PASSWORD> <ADDRESS0></ADDRESS0> <ADDRESS1>#{address[:full_name]}</ADDRESS1> <ADDRESS2>#{address[:address]}</ADDRESS2> <ADDRESS3>#{address[:city]}, #{address[:state]} #{address[:zipcode]}</ADDRESS3> </VERIFYADDRESS>! begin response = RestClient.post "#{DIAL_A_ZIP_BASE_URL}/MethodZIPValidate", :input => xml response_xml = Nokogiri::XML(response.body) return_code_node_xml = response_xml.css('Dial-A-ZIP_Response ReturnCode').first return_code = return_code_node_xml ? return_code_node_xml.text : nil addr_exists_node_xml = response_xml.css('Dial-A-ZIP_Response AddrExists').first addr_exists = addr_exists_node_xml ? addr_exists_node_xml.text : nil if ['31', '32'].include?(return_code) && addr_exists == 'TRUE' return { :full_name => response_xml.css('Dial-A-ZIP_Response AddrLine2').first.text, :address => response_xml.css('Dial-A-ZIP_Response AddrLine1').first.text, :city => response_xml.css('Dial-A-ZIP_Response City').first.text, :state => response_xml.css('Dial-A-ZIP_Response State').first.text, :zipcode => [response_xml.css('Dial-A-ZIP_Response ZIP5').first.text, response_xml.css('Dial-A-ZIP_Response Plus4').first.text].join('-'), } else fail return_code == '31' ? DIAL_A_ZIP_ADDRESS_NOT_FOUND_MESSAGE : DIAL_A_ZIP_RESPONSE_MESSAGES[return_code] end rescue => e fail e.to_s end end |