Module: AwesomeUsps::ServiceStandard
- Included in:
- USPS
- Defined in:
- lib/awesome_usps/service_standard.rb
Instance Method Summary collapse
- #canned_express_mail_commitment_test ⇒ Object
- #canned_priority_mail_estimated_time_test ⇒ Object
- #canned_standard_mail_estimated_time_test ⇒ Object
- #express_mail_commitment(origin, destination, date = nil, api_request = 'ExpressMailCommitmentRequest') ⇒ Object
- #parse_express(xml) ⇒ Object
-
#parse_service(xml) ⇒ Object
Parses the XML into an array broken up by each event.
-
#priority_mail_estimated_time(origin, destination, api_request = "PriorityMailRequest") ⇒ Object
Takes your package tracking number and returns information for the USPS web API.
- #standard_mail_estimated_time(origin, destination, api_request = 'StandardBRequest') ⇒ Object
-
#xml_for_estimated_time_for_delivery(api_request, origin, destination, date = nil) ⇒ Object
XML from a straight string.
Instance Method Details
#canned_express_mail_commitment_test ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/awesome_usps/service_standard.rb', line 39 def canned_express_mail_commitment_test origin= Location.new( :zip5 =>'20770') destination=Location.new( :zip5 =>'11210') date = '05-Aug-2004' api_request = 'ExpressMailCommitmentRequest' request = xml_for_estimated_time_for_delivery(api_request, origin, destination, date) gateway_commit(:express, 'ExpressMailCommitment', request, :test) end |
#canned_priority_mail_estimated_time_test ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/awesome_usps/service_standard.rb', line 31 def canned_priority_mail_estimated_time_test origin = Location.new( :zip5 => '4') destination = Location.new( :zip5 => '4') api_request="PriorityMailRequest" request = xml_for_estimated_time_for_delivery(api_request, origin, destination) gateway_commit(:standard, 'StandardB', request, :test) end |
#canned_standard_mail_estimated_time_test ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/awesome_usps/service_standard.rb', line 23 def canned_standard_mail_estimated_time_test origin = Location.new( :zip5 => '4') destination = Location.new( :zip5 => '4') api_request="StandardBRequest" request = xml_for_estimated_time_for_delivery(api_request, origin, destination) gateway_commit(:priority_mail, 'PriorityMail', request, :test) end |
#express_mail_commitment(origin, destination, date = nil, api_request = 'ExpressMailCommitmentRequest') ⇒ Object
18 19 20 21 |
# File 'lib/awesome_usps/service_standard.rb', line 18 def express_mail_commitment(origin, destination, date=nil, api_request='ExpressMailCommitmentRequest') xml_for_estimated_time_for_delivery(api_request, origin, destination, date) gateway_commit(:express, 'ExpressMailCommitment', request, :live) end |
#parse_express(xml) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/awesome_usps/service_standard.rb', line 73 def parse_express(xml) parse = Hpricot.parse(xml)/:error if parse != [] RAILS_DEFAULT_LOGGER.info "#{xml}" return (Hpricot.parse(xml)/:description).inner_html else i= 0 location_list = [] (Hpricot.parse(xml)/:location).each do |location| i+=1 h = {} location.children.each {|elem| h[elem.name.to_sym] = elem.inner_text unless elem.inner_text.blank?} location_list << h end return location_list end end |
#parse_service(xml) ⇒ Object
Parses the XML into an array broken up by each event. Example of returned array
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/awesome_usps/service_standard.rb', line 62 def parse_service(xml) event_list = [] parse = Hpricot.parse(xml)/:error if parse != [] RAILS_DEFAULT_LOGGER.info "#{xml}" return (Hpricot.parse(xml)/:description).inner_html else return parse = (Hpricot.parse(xml)/:days).inner_html end end |
#priority_mail_estimated_time(origin, destination, api_request = "PriorityMailRequest") ⇒ Object
Takes your package tracking number and returns information for the USPS web API
4 5 6 7 8 9 |
# File 'lib/awesome_usps/service_standard.rb', line 4 def priority_mail_estimated_time(origin, destination, api_request="PriorityMailRequest") origin = orgin destination=destination request = xml_for_estimated_time_for_delivery(api_request, origin, destination) commit_service_standard_request(:priority_mail, 'PriorityMail', request , :live) end |
#standard_mail_estimated_time(origin, destination, api_request = 'StandardBRequest') ⇒ Object
11 12 13 14 15 16 |
# File 'lib/awesome_usps/service_standard.rb', line 11 def standard_mail_estimated_time(origin, destination, api_request='StandardBRequest') origin = orgin destination=destination request = xml_for_estimated_time_for_delivery(api_request, origin, destination) gateway_commit(:standard, 'StandardB', request, :live) end |
#xml_for_estimated_time_for_delivery(api_request, origin, destination, date = nil) ⇒ Object
XML from a straight string.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/awesome_usps/service_standard.rb', line 49 def xml_for_estimated_time_for_delivery(api_request, origin, destination, date=nil) xm = Builder::XmlMarkup.new xm.tag!(api_request, "USERID"=>"#{@username}") do xm.OriginZIP(origin.zip5) xm.DestinationZIP(destination.zip5) if api_request == 'ExpressMailCommitmentRequest' xm.Date(date) end end end |