1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Added readme info on CLI interface.

Ensured that CLI defaults to ruby pp.
This commit is contained in:
John Nunemaker 2009-01-05 01:58:08 -05:00
parent 78f0c846d8
commit dbb68d047d
3 changed files with 29 additions and 13 deletions

View file

@ -7,7 +7,6 @@ examples/rubyurl.rb
examples/twitter.rb
examples/whoismyrep.rb
History
httparty.gemspec
lib/core_extensions.rb
lib/httparty/exceptions.rb
lib/httparty/request.rb

11
README
View file

@ -15,6 +15,17 @@ Makes http fun again!
See http://github.com/jnunemaker/httparty/tree/master/examples
== COMMAND LINE INTERFACE
httparty also includes the executable <tt>httparty</tt> which can be
used to query web services and examine the resulting output. By default
it will output the response as a pretty-printed Ruby object (useful for
grokking the structure of output). This can also be overridden to output
formatted XML or JSON. Execute <tt>httparty --help</tt> for all the
options. Below is an example of how easy it is.
httparty "http://twitter.com/statuses/public_timeline.json" -f json
== REQUIREMENTS:
* JSON ~> 1.1

View file

@ -80,18 +80,24 @@ module REXML
end
end
response = HTTParty.send(opts[:action], ARGV.first, opts.merge(:format => :plain))
if opts[:pretty_print]
pp response
if opts[:pretty_print] || opts[:format].nil?
pp HTTParty.send(opts[:action], ARGV.first, opts)
else
case opts[:format]
when :json
puts JSON.pretty_generate(JSON.parse(response))
when :xml
REXML::Document.new(response).write(STDOUT, 2)
puts
print_format = opts[:format]
opts.merge!(:format => :plain) if opts[:format]
response = HTTParty.send(opts[:action], ARGV.first, opts)
if print_format.nil?
pp response
else
puts response
case print_format
when :json
puts JSON.pretty_generate(JSON.parse(response))
when :xml
REXML::Document.new(response).write(STDOUT, 2)
puts
else
puts response
end
end
end
end