jnunemaker-httparty 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History +4 -0
- data/Manifest +1 -0
- data/README +11 -0
- data/bin/httparty +103 -0
- data/httparty.gemspec +6 -4
- data/lib/httparty/version.rb +2 -2
- metadata +8 -6
data/History
CHANGED
data/Manifest
CHANGED
data/README
CHANGED
@@ -15,6 +15,17 @@ Makes http fun again!
|
|
15
15
|
|
16
16
|
See http://github.com/jnunemaker/httparty/tree/master/examples
|
17
17
|
|
18
|
+
== COMMAND LINE INTERFACE
|
19
|
+
|
20
|
+
httparty also includes the executable <tt>httparty</tt> which can be
|
21
|
+
used to query web services and examine the resulting output. By default
|
22
|
+
it will output the response as a pretty-printed Ruby object (useful for
|
23
|
+
grokking the structure of output). This can also be overridden to output
|
24
|
+
formatted XML or JSON. Execute <tt>httparty --help</tt> for all the
|
25
|
+
options. Below is an example of how easy it is.
|
26
|
+
|
27
|
+
httparty "http://twitter.com/statuses/public_timeline.json" -f json
|
28
|
+
|
18
29
|
== REQUIREMENTS:
|
19
30
|
|
20
31
|
* JSON ~> 1.1
|
data/bin/httparty
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
require "pp"
|
5
|
+
require "rexml/document"
|
6
|
+
|
7
|
+
$:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
|
8
|
+
require "httparty"
|
9
|
+
|
10
|
+
opts = {
|
11
|
+
:action => :get,
|
12
|
+
:headers => {},
|
13
|
+
:keep_body => true,
|
14
|
+
:verbose => false,
|
15
|
+
:pretty_print => false
|
16
|
+
}
|
17
|
+
|
18
|
+
OptionParser.new do |o|
|
19
|
+
o.banner = "USAGE: #{$0} [options] [url]"
|
20
|
+
o.on("-f",
|
21
|
+
"--format [FORMAT]",
|
22
|
+
"Body format: plain, json or xml") do |f|
|
23
|
+
opts[:format] = f.downcase.to_sym
|
24
|
+
end
|
25
|
+
o.on("-r", "--ruby", "Dump output in Ruby pretty-print format") do |r|
|
26
|
+
opts[:pretty_print] = true
|
27
|
+
end
|
28
|
+
o.on("-a",
|
29
|
+
"--action [ACTION]",
|
30
|
+
"HTTP action: get (default), post, put or delete") do |a|
|
31
|
+
opts[:action] = a.downcase.to_sym
|
32
|
+
end
|
33
|
+
o.on("-d",
|
34
|
+
"--data [BODY]",
|
35
|
+
"Data to put in request body (prefix with '@' for file)") do |d|
|
36
|
+
if d =~ /^@/
|
37
|
+
opts[:data] = open(d).read
|
38
|
+
else
|
39
|
+
opts[:data] = d
|
40
|
+
end
|
41
|
+
end
|
42
|
+
o.on("-H", "--header [NAME=VALUE]", "Additional HTTP headers in NAME=VALUE form") do |h|
|
43
|
+
name, value = h.split('=')
|
44
|
+
opts[:headers][name] = value
|
45
|
+
end
|
46
|
+
o.on("-v", "--verbose", "If set, print verbose output") do |v|
|
47
|
+
opts[:verbose] = true
|
48
|
+
end
|
49
|
+
o.on("-h", "--help", "Show help documentation") do |h|
|
50
|
+
puts o
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
end.parse!
|
54
|
+
|
55
|
+
puts "Querying #{ARGV.first} with options: #{opts.inspect}" if opts[:verbose]
|
56
|
+
|
57
|
+
if ARGV.empty?
|
58
|
+
STDERR.puts "You need to provide a URL"
|
59
|
+
STDERR.puts "USAGE: #{$0} [options] [url]"
|
60
|
+
end
|
61
|
+
|
62
|
+
# 1.8.6 has mistyping of transitive in if statement
|
63
|
+
module REXML
|
64
|
+
class Document < Element
|
65
|
+
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
|
66
|
+
if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
|
67
|
+
output = Output.new( output, xml_decl.encoding )
|
68
|
+
end
|
69
|
+
formatter = if indent > -1
|
70
|
+
if transitive
|
71
|
+
REXML::Formatters::Transitive.new( indent, ie_hack )
|
72
|
+
else
|
73
|
+
REXML::Formatters::Pretty.new( indent, ie_hack )
|
74
|
+
end
|
75
|
+
else
|
76
|
+
REXML::Formatters::Default.new( ie_hack )
|
77
|
+
end
|
78
|
+
formatter.write( self, output )
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
if opts[:pretty_print] || opts[:format].nil?
|
84
|
+
pp HTTParty.send(opts[:action], ARGV.first, opts)
|
85
|
+
else
|
86
|
+
print_format = opts[:format]
|
87
|
+
opts.merge!(:format => :plain) if opts[:format]
|
88
|
+
response = HTTParty.send(opts[:action], ARGV.first, opts)
|
89
|
+
|
90
|
+
if print_format.nil?
|
91
|
+
pp response
|
92
|
+
else
|
93
|
+
case print_format
|
94
|
+
when :json
|
95
|
+
puts JSON.pretty_generate(JSON.parse(response))
|
96
|
+
when :xml
|
97
|
+
REXML::Document.new(response).write(STDOUT, 2)
|
98
|
+
puts
|
99
|
+
else
|
100
|
+
puts response
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/httparty.gemspec
CHANGED
@@ -2,15 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{httparty}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Nunemaker"]
|
9
|
-
s.date = %q{
|
9
|
+
s.date = %q{2009-01-05}
|
10
|
+
s.default_executable = %q{httparty}
|
10
11
|
s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
11
12
|
s.email = %q{nunemaker@gmail.com}
|
12
|
-
s.
|
13
|
-
s.
|
13
|
+
s.executables = ["httparty"]
|
14
|
+
s.extra_rdoc_files = ["bin/httparty", "lib/core_extensions.rb", "lib/httparty/exceptions.rb", "lib/httparty/request.rb", "lib/httparty/version.rb", "lib/httparty.rb", "lib/module_level_inheritable_attributes.rb", "README"]
|
15
|
+
s.files = ["bin/httparty", "examples/aaws.rb", "examples/basic.rb", "examples/delicious.rb", "examples/google.rb", "examples/rubyurl.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "History", "lib/core_extensions.rb", "lib/httparty/exceptions.rb", "lib/httparty/request.rb", "lib/httparty/version.rb", "lib/httparty.rb", "lib/module_level_inheritable_attributes.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README", "setup.rb", "spec/as_buggery_spec.rb", "spec/fixtures/delicious.xml", "spec/fixtures/google.html", "spec/fixtures/twitter.json", "spec/fixtures/twitter.xml", "spec/httparty/request_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "website/css/common.css", "website/index.html", "httparty.gemspec"]
|
14
16
|
s.has_rdoc = true
|
15
17
|
s.homepage = %q{http://httparty.rubyforge.org}
|
16
18
|
s.post_install_message = %q{When you HTTParty, you must party hard!}
|
data/lib/httparty/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module HTTParty
|
2
|
-
Version = '0.2.
|
3
|
-
end
|
2
|
+
Version = '0.2.5'
|
3
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jnunemaker-httparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,8 +9,8 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2009-01-05 00:00:00 -08:00
|
13
|
+
default_executable: httparty
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -32,11 +32,12 @@ dependencies:
|
|
32
32
|
version:
|
33
33
|
description: Makes http fun! Also, makes consuming restful web services dead easy.
|
34
34
|
email: nunemaker@gmail.com
|
35
|
-
executables:
|
36
|
-
|
35
|
+
executables:
|
36
|
+
- httparty
|
37
37
|
extensions: []
|
38
38
|
|
39
39
|
extra_rdoc_files:
|
40
|
+
- bin/httparty
|
40
41
|
- lib/core_extensions.rb
|
41
42
|
- lib/httparty/exceptions.rb
|
42
43
|
- lib/httparty/request.rb
|
@@ -45,6 +46,7 @@ extra_rdoc_files:
|
|
45
46
|
- lib/module_level_inheritable_attributes.rb
|
46
47
|
- README
|
47
48
|
files:
|
49
|
+
- bin/httparty
|
48
50
|
- examples/aaws.rb
|
49
51
|
- examples/basic.rb
|
50
52
|
- examples/delicious.rb
|
@@ -53,7 +55,6 @@ files:
|
|
53
55
|
- examples/twitter.rb
|
54
56
|
- examples/whoismyrep.rb
|
55
57
|
- History
|
56
|
-
- httparty.gemspec
|
57
58
|
- lib/core_extensions.rb
|
58
59
|
- lib/httparty/exceptions.rb
|
59
60
|
- lib/httparty/request.rb
|
@@ -76,6 +77,7 @@ files:
|
|
76
77
|
- spec/spec_helper.rb
|
77
78
|
- website/css/common.css
|
78
79
|
- website/index.html
|
80
|
+
- httparty.gemspec
|
79
81
|
has_rdoc: true
|
80
82
|
homepage: http://httparty.rubyforge.org
|
81
83
|
post_install_message: When you HTTParty, you must party hard!
|