I am hooking up with the USPS rate calculator so I can calculate
shipping costs online. Unfortunately, USPS uses neither XML-RPC or
SOAP. I send the data via a GET request (a long URL) and I get data
back via xml. Questions:
1) Is there a library or something within the rails platform that
allows me to send a get request?
2) Is there a library that allows me to parse the resulting XML data?
I am hooking up with the USPS rate calculator so I can calculate
shipping costs online. Unfortunately, USPS uses neither XML-RPC or
SOAP. I send the data via a GET request (a long URL) and I get data
back via xml. Questions:
1) Is there a library or something within the rails platform that
allows me to send a get request?
2) Is there a library that allows me to parse the resulting XML data?
A POST works just fine with the USPS webtools api. It's just not
evident from the documentation. Just post the data like you would for
a regular form post using application/x-www-form-urlencoded as the
content type.
If this is the case, do I use the "web services" functionality in
rails? I can't seem to find any documentation either on the USPS
website or the internet for that matter. usps doesn't even say if
they're using XML-RPC or SOAP (I think it's neither).
Use something like net/https to do the POST. The only strange thing
is that while the content type is application/x-www-form-urlencoded,
you don't want to actually urlencode any of the data.
I figured out a way to write a script to get the info I needed from
USPS web tools. I used rexml and net/http plugins. I thought I would
contribute code to this group because there doesn't seem to be much
support on the usps site for ruby. I searched online and couldn't find
any scripts either. Anyway, here you go:
(PS, please don't make fun of this code, I am new to ruby. However,
this code seems to work for me).
#! /usr/bin/ruby
# ************************************************************
# The purpose of this script is to find out how much it costs
# to send a package through USPS through a pre-defined
# criteria
# ************************************************************
Also, is there someplace else I can post this code? There are a few
sites that seem to be sites to store "code snippets". I forgot their
names though. What are the more popular ones?