public
Rubygem
Description: Makes http fun! Also, makes consuming restful web services dead easy.
Homepage:
Clone URL: git://github.com/jnunemaker/httparty.git
Click here to lend your support to: httparty and make a donation at www.pledgie.com !
Added readme info on CLI interface.

Ensured that CLI defaults to ruby pp.
jnunemaker (author)
Sun Jan 04 22:58:08 -0800 2009
commit  dbb68d047de2e6e3218577063031e655d64a7adf
tree    32f765f5e11a9ebe858d262c20dc6d9252ea1bde
parent  78f0c846d89ab53c3730b059aa75ae1ea53abb2b
...
7
8
9
10
11
12
13
...
7
8
9
 
10
11
12
0
@@ -7,7 +7,6 @@ examples/rubyurl.rb
0
 examples/twitter.rb
0
 examples/whoismyrep.rb
0
 History
0
-httparty.gemspec
0
 lib/core_extensions.rb
0
 lib/httparty/exceptions.rb
0
 lib/httparty/request.rb
0
...
15
16
17
 
 
 
 
 
 
 
 
 
 
 
18
19
20
...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
0
@@ -15,6 +15,17 @@ Makes http fun again!
0
 
0
 See http://github.com/jnunemaker/httparty/tree/master/examples
0
 
0
+== COMMAND LINE INTERFACE
0
+
0
+httparty also includes the executable <tt>httparty</tt> which can be
0
+used to query web services and examine the resulting output. By default
0
+it will output the response as a pretty-printed Ruby object (useful for
0
+grokking the structure of output). This can also be overridden to output
0
+formatted XML or JSON. Execute <tt>httparty --help</tt> for all the
0
+options. Below is an example of how easy it is.
0
+
0
+  httparty "http://twitter.com/statuses/public_timeline.json" -f json
0
+
0
 == REQUIREMENTS:
0
 
0
 * JSON ~> 1.1
...
80
81
82
83
84
85
86
 
 
87
88
89
90
91
92
93
 
 
 
 
 
 
94
95
 
 
 
 
 
 
 
 
 
96
97
 
98
...
80
81
82
 
 
 
 
83
84
85
 
 
 
 
 
 
86
87
88
89
90
91
92
 
93
94
95
96
97
98
99
100
101
102
 
103
104
0
@@ -80,18 +80,24 @@ module REXML
0
   end
0
 end
0
 
0
-response = HTTParty.send(opts[:action], ARGV.first, opts.merge(:format => :plain))
0
-
0
-if opts[:pretty_print]
0
-  pp response
0
+if opts[:pretty_print] || opts[:format].nil?
0
+  pp HTTParty.send(opts[:action], ARGV.first, opts)
0
 else
0
-  case opts[:format]
0
-  when :json
0
-    puts JSON.pretty_generate(JSON.parse(response))
0
-  when :xml
0
-    REXML::Document.new(response).write(STDOUT, 2)
0
-    puts
0
+  print_format = opts[:format]
0
+  opts.merge!(:format => :plain) if opts[:format]
0
+  response = HTTParty.send(opts[:action], ARGV.first, opts)
0
+
0
+  if print_format.nil?
0
+    pp response
0
   else
0
-    puts response
0
+    case print_format
0
+    when :json
0
+      puts JSON.pretty_generate(JSON.parse(response))
0
+    when :xml
0
+      REXML::Document.new(response).write(STDOUT, 2)
0
+      puts
0
+    else
0
+      puts response
0
+    end
0
   end
0
-end
0
+end
0
\ No newline at end of file

Comments