Just starting to dabble with Ruby and XML, initial attempts at using
HTTParty have been amazing, so I'm starting to port some of my
clunkier scripts to Ruby... and now I've run into something that's got
me stumped...
Usually I have multiple WIFI access points defined in the
"wifi_towers" section, but I'm trying to simplify here.
Anyway, I'm trying to port this to Ruby, and what I have so far is:
--------------------------------------------------------------------------- ------------------------
#!/usr/bin/ruby
require 'rubygems'
require 'httparty'
class GeoLocate
include HTTParty
debug_output $stdout
format :json
base_uri 'http://www.google.com' headers "Pragma" => "no-cache", "Cache-controle" => "no-cache"
end
I suppose I could just run curl in the background to get the results,
but I'd really like to start using Ruby object instead of just
dropping to bash commands all the time, not to mention I love how easy
it is to parse the results once HTTParty sorts things out.
Anyway, forgive me if my newby status is making me miss something
glaringly obvious, I'm really hoping that someone out there has an
idea of what I'm missing though.
> Just starting to dabble with Ruby and XML, initial attempts at using
> HTTParty have been amazing, so I'm starting to port some of my
> clunkier scripts to Ruby... and now I've run into something that's got
> me stumped...
> Usually I have multiple WIFI access points defined in the
> "wifi_towers" section, but I'm trying to simplify here.
> Anyway, I'm trying to port this to Ruby, and what I have so far is:
> --------------------------------------------------------------------------- ------------------------
> #!/usr/bin/ruby
> require 'rubygems'
> require 'httparty'
> class GeoLocate
> include HTTParty
> debug_output $stdout
> format :json
> base_uri 'http://www.google.com' > headers "Pragma" => "no-cache", "Cache-controle" => "no-cache"
> end
> I suppose I could just run curl in the background to get the results,
> but I'd really like to start using Ruby object instead of just
> dropping to bash commands all the time, not to mention I love how easy
> it is to parse the results once HTTParty sorts things out.
> Anyway, forgive me if my newby status is making me miss something
> glaringly obvious, I'm really hoping that someone out there has an
> idea of what I'm missing though.
The body method returns the Net::HTTP body, that is, the raw body
before parsing takes place. You can call #parsed_response to get the
parsed body but you really shouldn't have to - just work with the
HTTParty::Response object. Try doing something like result.keys or
puts(result.to_yaml) or result.code or result.not_found? At this
point, unless there was a parse error, those methods should all work.
On Jun 22, 6:49 pm, Jeff Dyck <fsjj...@gmail.com> wrote:
> Any more ideas? I suppose I could start working on parsing it out manually, but definitely nicer if HTTParty does it for me (I'm lazy I guess)
> Jeff
> On 2011-06-22, at 5:24 PM, Sandro wrote:
> > Are you supposed to be posting JSON? If so, you'll want to do
> > something like result = GeoLocate.post('/loc/json',:body =>
> > JSON.dump(queryHash))
> The body method returns the Net::HTTP body, that is, the raw body > before parsing takes place. You can call #parsed_response to get the > parsed body but you really shouldn't have to - just work with the > HTTParty::Response object. Try doing something like result.keys or > puts(result.to_yaml) or result.code or result.not_found? At this > point, unless there was a parse error, those methods should all work.