httparty 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/History +35 -1
- data/Manifest +1 -4
- data/README.rdoc +54 -0
- data/Rakefile +76 -48
- data/VERSION +1 -0
- data/bin/httparty +33 -22
- data/examples/basic.rb +1 -1
- data/examples/custom_parsers.rb +67 -0
- data/features/steps/env.rb +1 -0
- data/features/steps/httparty_response_steps.rb +2 -2
- data/features/steps/httparty_steps.rb +6 -2
- data/features/steps/mongrel_helper.rb +2 -1
- data/features/steps/remote_service_steps.rb +5 -0
- data/features/supports_timeout_option.feature +12 -0
- data/httparty.gemspec +100 -13
- data/lib/httparty/cookie_hash.rb +16 -3
- data/lib/httparty/core_extensions.rb +9 -3
- data/lib/httparty/exceptions.rb +5 -2
- data/lib/httparty/module_inheritable_attributes.rb +3 -3
- data/lib/httparty/parser.rb +140 -0
- data/lib/httparty/request.rb +92 -50
- data/lib/httparty/response.rb +1 -1
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +110 -52
- data/spec/httparty/cookie_hash_spec.rb +43 -10
- data/spec/httparty/parser_spec.rb +154 -0
- data/spec/httparty/request_spec.rb +149 -10
- data/spec/httparty/response_spec.rb +1 -1
- data/spec/httparty_spec.rb +210 -39
- data/spec/spec.opts +1 -2
- data/spec/spec_helper.rb +7 -4
- data/website/index.html +35 -36
- metadata +81 -36
- data/README +0 -36
- data/setup.rb +0 -1585
- data/spec/hash_spec.rb +0 -49
- data/spec/string_spec.rb +0 -27
data/History
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
|
-
== 0.
|
|
1
|
+
== 0.5.0 2009-12-07
|
|
2
|
+
* bug fixes
|
|
3
|
+
* inheritable attributes no longer mutable by subclasses (yyyc514)
|
|
4
|
+
* namespace BasicObject within HTTParty to avoid class name collisions (eric)
|
|
5
|
+
|
|
6
|
+
* major enhancements
|
|
7
|
+
* Custom Parsers via class or proc
|
|
8
|
+
* Deprecation warning on HTTParty::AllowedFormats
|
|
9
|
+
moved to HTTParty::Parser::SupportedFormats
|
|
10
|
+
|
|
11
|
+
* minor enhancements
|
|
12
|
+
* Curl inspired output when using the binary in verbose mode (alexvollmer)
|
|
13
|
+
* raise UnsupportedURIScheme when scheme is not HTTP or HTTPS (djspinmonkey)
|
|
14
|
+
* Allow SSL for ports other than 443 when scheme is HTTPS (stefankroes)
|
|
15
|
+
* Accept PEM certificates via HTTParty#pem (chrislo)
|
|
16
|
+
* Support HEAD and OPTION verbs (grempe)
|
|
17
|
+
* Verify SSL certificates when providing a PEM file (collectiveidea/danielmorrison)
|
|
18
|
+
|
|
19
|
+
== 0.4.5 2009-09-12
|
|
20
|
+
* bug fixes
|
|
21
|
+
* Fixed class-level headers overwritten by cookie management code. Closes #19
|
|
22
|
+
* Fixed "superclass mismatch for class BlankSlate" error. Closes #20
|
|
23
|
+
* Fixed reading files as post data from the command line (vesan)
|
|
24
|
+
* minor enhancements
|
|
25
|
+
* Timeout option added; will raise a Timeout::Error after the timeout has elapsed (attack). Closes #17
|
|
26
|
+
HTTParty.get "http://github.com", :timeout => 1
|
|
27
|
+
* Building gem with Jeweler
|
|
28
|
+
|
|
29
|
+
== 0.4.4 2009-07-19
|
|
30
|
+
* 2 minor update
|
|
31
|
+
* :query no longer sets form data. Use body and set content type to application/x-www-form-urlencoded if you need it. :query was wrong for that.
|
|
32
|
+
* Fixed a bug in the cookies class method that caused cookies to be forgotten after the first request.
|
|
33
|
+
* Also, some general cleanup of tests and such.
|
|
34
|
+
|
|
35
|
+
== 0.4.3 2009-04-23
|
|
2
36
|
* 1 minor update
|
|
3
37
|
* added message to the response object
|
|
4
38
|
|
data/Manifest
CHANGED
|
@@ -30,21 +30,18 @@ lib/httparty.rb
|
|
|
30
30
|
Manifest
|
|
31
31
|
MIT-LICENSE
|
|
32
32
|
Rakefile
|
|
33
|
-
README
|
|
34
|
-
setup.rb
|
|
33
|
+
README.rdoc
|
|
35
34
|
spec/fixtures/delicious.xml
|
|
36
35
|
spec/fixtures/empty.xml
|
|
37
36
|
spec/fixtures/google.html
|
|
38
37
|
spec/fixtures/twitter.json
|
|
39
38
|
spec/fixtures/twitter.xml
|
|
40
39
|
spec/fixtures/undefined_method_add_node_for_nil.xml
|
|
41
|
-
spec/hash_spec.rb
|
|
42
40
|
spec/httparty/cookie_hash_spec.rb
|
|
43
41
|
spec/httparty/request_spec.rb
|
|
44
42
|
spec/httparty/response_spec.rb
|
|
45
43
|
spec/httparty_spec.rb
|
|
46
44
|
spec/spec.opts
|
|
47
45
|
spec/spec_helper.rb
|
|
48
|
-
spec/string_spec.rb
|
|
49
46
|
website/css/common.css
|
|
50
47
|
website/index.html
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
= httparty
|
|
2
|
+
|
|
3
|
+
Makes http fun again!
|
|
4
|
+
|
|
5
|
+
== Note on Releases
|
|
6
|
+
|
|
7
|
+
Releases are tagged on github and also released as gems on github and rubyforge. Master is pushed to whenever I add a patch or a new feature. To build from master, you can clone the code, generate the updated gemspec, build the gem and install.
|
|
8
|
+
|
|
9
|
+
* rake gemspec
|
|
10
|
+
* gem build httparty.gemspec
|
|
11
|
+
* gem install the gem that was built
|
|
12
|
+
|
|
13
|
+
== Note on Patches/Pull Requests
|
|
14
|
+
|
|
15
|
+
* Fork the project.
|
|
16
|
+
* Make your feature addition or bug fix.
|
|
17
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
|
18
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
|
|
19
|
+
* Send me a pull request. Bonus points for topic branches.
|
|
20
|
+
|
|
21
|
+
== Features:
|
|
22
|
+
|
|
23
|
+
* Easy get, post requests
|
|
24
|
+
* Basic http authentication
|
|
25
|
+
* Default request query string parameters (ie: for api keys that are needed on each request)
|
|
26
|
+
* Automatic parsing of JSON and XML into ruby hashes based on response content-type
|
|
27
|
+
|
|
28
|
+
== Examples
|
|
29
|
+
|
|
30
|
+
See http://github.com/jnunemaker/httparty/tree/master/examples
|
|
31
|
+
|
|
32
|
+
== Command Line Interface
|
|
33
|
+
|
|
34
|
+
httparty also includes the executable <tt>httparty</tt> which can be
|
|
35
|
+
used to query web services and examine the resulting output. By default
|
|
36
|
+
it will output the response as a pretty-printed Ruby object (useful for
|
|
37
|
+
grokking the structure of output). This can also be overridden to output
|
|
38
|
+
formatted XML or JSON. Execute <tt>httparty --help</tt> for all the
|
|
39
|
+
options. Below is an example of how easy it is.
|
|
40
|
+
|
|
41
|
+
httparty "http://twitter.com/statuses/public_timeline.json"
|
|
42
|
+
|
|
43
|
+
== Requirements
|
|
44
|
+
|
|
45
|
+
* Crack http://github.com/jnunemaker/crack/ - For XML and JSON parsing.
|
|
46
|
+
* You like to party!
|
|
47
|
+
|
|
48
|
+
== Install
|
|
49
|
+
|
|
50
|
+
* sudo gem install httparty
|
|
51
|
+
|
|
52
|
+
== Docs
|
|
53
|
+
|
|
54
|
+
http://rdoc.info/projects/jnunemaker/httparty
|
data/Rakefile
CHANGED
|
@@ -1,48 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
require '
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "httparty"
|
|
8
|
+
gem.summary = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
|
9
|
+
gem.description = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
|
10
|
+
gem.email = "nunemaker@gmail.com"
|
|
11
|
+
gem.homepage = "http://httparty.rubyforge.org"
|
|
12
|
+
gem.authors = ["John Nunemaker", "Sandro Turriate"]
|
|
13
|
+
gem.add_dependency 'crack', '>= 0.1.1'
|
|
14
|
+
gem.add_development_dependency "activesupport", "~>2.3"
|
|
15
|
+
gem.add_development_dependency "cucumber", "~>0.4"
|
|
16
|
+
gem.add_development_dependency "fakeweb", "~>1.2"
|
|
17
|
+
gem.add_development_dependency "mongrel", "~>1.1"
|
|
18
|
+
gem.add_development_dependency "rspec", "1.2.9"
|
|
19
|
+
gem.post_install_message = "When you HTTParty, you must party hard!"
|
|
20
|
+
gem.rubyforge_project = 'httparty'
|
|
21
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
22
|
+
end
|
|
23
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
|
24
|
+
rubyforge.doc_task = "rdoc"
|
|
25
|
+
end
|
|
26
|
+
Jeweler::GemcutterTasks.new
|
|
27
|
+
rescue LoadError
|
|
28
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
require 'spec/rake/spectask'
|
|
32
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
|
33
|
+
spec.libs << 'lib' << 'spec'
|
|
34
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
35
|
+
spec.spec_opts = ['--options', 'spec/spec.opts']
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
39
|
+
spec.libs << 'lib' << 'spec'
|
|
40
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
41
|
+
spec.rcov = true
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
task :spec => :check_dependencies
|
|
45
|
+
|
|
46
|
+
begin
|
|
47
|
+
require 'cucumber/rake/task'
|
|
48
|
+
Cucumber::Rake::Task.new(:features)
|
|
49
|
+
|
|
50
|
+
task :features => :check_dependencies
|
|
51
|
+
rescue LoadError
|
|
52
|
+
task :features do
|
|
53
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
task :default => [:spec, :features]
|
|
58
|
+
|
|
59
|
+
require 'rake/rdoctask'
|
|
60
|
+
Rake::RDocTask.new do |rdoc|
|
|
61
|
+
if File.exist?('VERSION')
|
|
62
|
+
version = File.read('VERSION')
|
|
63
|
+
else
|
|
64
|
+
version = ""
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
68
|
+
rdoc.title = "httparty #{version}"
|
|
69
|
+
rdoc.rdoc_files.include('README*')
|
|
70
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
desc 'Upload website files to rubyforge'
|
|
74
|
+
task :website do
|
|
75
|
+
sh %{rsync -av website/ jnunemaker@rubyforge.org:/var/www/gforge-projects/httparty}
|
|
76
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.5.0
|
data/bin/httparty
CHANGED
|
@@ -12,74 +12,85 @@ opts = {
|
|
|
12
12
|
:verbose => false
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
def die(msg)
|
|
16
|
-
STDERR.puts(msg)
|
|
17
|
-
exit 1
|
|
18
|
-
end
|
|
19
|
-
|
|
20
15
|
OptionParser.new do |o|
|
|
21
16
|
o.banner = "USAGE: #{$0} [options] [url]"
|
|
22
|
-
|
|
17
|
+
|
|
23
18
|
o.on("-f",
|
|
24
19
|
"--format [FORMAT]",
|
|
25
20
|
"Output format to use instead of pretty-print ruby: " +
|
|
26
21
|
"plain, json or xml") do |f|
|
|
27
22
|
opts[:output_format] = f.downcase.to_sym
|
|
28
23
|
end
|
|
29
|
-
|
|
24
|
+
|
|
30
25
|
o.on("-a",
|
|
31
26
|
"--action [ACTION]",
|
|
32
|
-
"HTTP action: get (default), post, put or
|
|
27
|
+
"HTTP action: get (default), post, put, delete, head, or options") do |a|
|
|
33
28
|
opts[:action] = a.downcase.to_sym
|
|
34
29
|
end
|
|
35
|
-
|
|
30
|
+
|
|
36
31
|
o.on("-d",
|
|
37
32
|
"--data [BODY]",
|
|
38
33
|
"Data to put in request body (prefix with '@' for file)") do |d|
|
|
39
34
|
if d =~ /^@/
|
|
40
|
-
opts[:data] = open(d).read
|
|
35
|
+
opts[:data] = open(d[1..-1]).read
|
|
41
36
|
else
|
|
42
37
|
opts[:data] = d
|
|
43
38
|
end
|
|
44
39
|
end
|
|
45
|
-
|
|
40
|
+
|
|
46
41
|
o.on("-H", "--header [NAME=VALUE]", "Additional HTTP headers in NAME=VALUE form") do |h|
|
|
47
|
-
|
|
42
|
+
abort "Invalid header specification, should be Name:Value" unless h =~ /.+:.+/
|
|
48
43
|
name, value = h.split(':')
|
|
49
44
|
opts[:headers][name.strip] = value.strip
|
|
50
45
|
end
|
|
51
|
-
|
|
46
|
+
|
|
52
47
|
o.on("-v", "--verbose", "If set, print verbose output") do |v|
|
|
53
48
|
opts[:verbose] = true
|
|
54
49
|
end
|
|
55
|
-
|
|
50
|
+
|
|
56
51
|
o.on("-u", "--user [CREDS]", "Use basic authentication. Value should be user:password") do |u|
|
|
57
|
-
|
|
52
|
+
abort "Invalid credentials format. Must be user:password" unless u =~ /.+:.+/
|
|
58
53
|
user, password = u.split(':')
|
|
59
54
|
opts[:basic_auth] = { :username => user, :password => password }
|
|
60
55
|
end
|
|
61
|
-
|
|
56
|
+
|
|
62
57
|
o.on("-h", "--help", "Show help documentation") do |h|
|
|
63
58
|
puts o
|
|
64
59
|
exit
|
|
65
60
|
end
|
|
66
61
|
end.parse!
|
|
67
62
|
|
|
68
|
-
puts "Querying #{ARGV.first} with options: #{opts.inspect}" if opts[:verbose]
|
|
69
63
|
|
|
70
64
|
if ARGV.empty?
|
|
71
65
|
STDERR.puts "You need to provide a URL"
|
|
72
66
|
STDERR.puts "USAGE: #{$0} [options] [url]"
|
|
73
67
|
end
|
|
74
68
|
|
|
69
|
+
def dump_headers(response)
|
|
70
|
+
resp_type = Net::HTTPResponse::CODE_TO_OBJ[response.code.to_s]
|
|
71
|
+
puts "#{response.code} #{resp_type.to_s.sub(/^Net::HTTP/, '')}"
|
|
72
|
+
response.headers.each do |n,v|
|
|
73
|
+
puts "#{n}: #{v}"
|
|
74
|
+
end
|
|
75
|
+
puts
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
if opts[:verbose]
|
|
79
|
+
puts "#{opts[:action].to_s.upcase} #{ARGV.first}"
|
|
80
|
+
opts[:headers].each do |n,v|
|
|
81
|
+
puts "#{n}: #{v}"
|
|
82
|
+
end
|
|
83
|
+
puts
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
response = HTTParty.send(opts[:action], ARGV.first, opts)
|
|
75
87
|
if opts[:output_format].nil?
|
|
76
|
-
response
|
|
77
|
-
puts "Status: #{response.code}"
|
|
88
|
+
dump_headers(response) if opts[:verbose]
|
|
78
89
|
pp response
|
|
79
90
|
else
|
|
80
91
|
print_format = opts[:output_format]
|
|
81
|
-
response
|
|
82
|
-
|
|
92
|
+
dump_headers(response) if opts[:verbose]
|
|
93
|
+
|
|
83
94
|
case opts[:output_format]
|
|
84
95
|
when :json
|
|
85
96
|
begin
|
|
@@ -95,4 +106,4 @@ else
|
|
|
95
106
|
else
|
|
96
107
|
puts response
|
|
97
108
|
end
|
|
98
|
-
end
|
|
109
|
+
end
|
data/examples/basic.rb
CHANGED
|
@@ -2,7 +2,7 @@ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
2
2
|
require File.join(dir, 'httparty')
|
|
3
3
|
require 'pp'
|
|
4
4
|
|
|
5
|
-
# You can also use post, put, delete in the same fashion
|
|
5
|
+
# You can also use post, put, delete, head, options in the same fashion
|
|
6
6
|
response = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
|
|
7
7
|
puts response.body, response.code, response.message, response.headers.inspect
|
|
8
8
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
class ParseAtom
|
|
2
|
+
include HTTParty
|
|
3
|
+
|
|
4
|
+
# Support Atom along with the default parsers: xml, json, yaml, etc.
|
|
5
|
+
class Parser::Atom < HTTParty::Parser
|
|
6
|
+
SupportedFormats.merge!({"application/atom+xml" => :atom})
|
|
7
|
+
|
|
8
|
+
protected
|
|
9
|
+
|
|
10
|
+
# perform atom parsing on body
|
|
11
|
+
def atom
|
|
12
|
+
body.to_atom
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
parser Parser::Atom
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class OnlyParseAtom
|
|
21
|
+
include HTTParty
|
|
22
|
+
|
|
23
|
+
# Only support Atom
|
|
24
|
+
class Parser::OnlyAtom < HTTParty::Parser
|
|
25
|
+
SupportedFormats = {"application/atom+xml" => :atom}
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
|
|
29
|
+
# perform atom parsing on body
|
|
30
|
+
def atom
|
|
31
|
+
body.to_atom
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
parser Parser::OnlyAtom
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class SkipParsing
|
|
40
|
+
include HTTParty
|
|
41
|
+
|
|
42
|
+
# Parse the response body however you like
|
|
43
|
+
class Parser::Simple < HTTParty::Parser
|
|
44
|
+
def parse
|
|
45
|
+
body
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
parser Parser::Simple
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class AdHocParsing
|
|
54
|
+
include HTTParty
|
|
55
|
+
parser(
|
|
56
|
+
Proc.new do |body, format|
|
|
57
|
+
case format
|
|
58
|
+
when :json
|
|
59
|
+
body.to_json
|
|
60
|
+
when :xml
|
|
61
|
+
body.to_xml
|
|
62
|
+
else
|
|
63
|
+
body
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
)
|
|
67
|
+
end
|
data/features/steps/env.rb
CHANGED
|
@@ -20,7 +20,7 @@ Then /it should return a response with a (\d+) response code/ do |code|
|
|
|
20
20
|
@response_from_httparty.code.should eql(code.to_i)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
Then /it should raise an
|
|
23
|
+
Then /it should raise (?:an|a) ([\w:]+) exception/ do |exception|
|
|
24
24
|
@exception_from_httparty.should_not be_nil
|
|
25
|
-
@exception_from_httparty.class.should eql(
|
|
25
|
+
@exception_from_httparty.class.name.should eql(exception)
|
|
26
26
|
end
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
When /^I set my HTTParty timeout option to (\d+)$/ do |timeout|
|
|
2
|
+
@request_options[:timeout] = timeout.to_i
|
|
3
|
+
end
|
|
4
|
+
|
|
1
5
|
When /I call HTTParty#get with '(.*)'$/ do |url|
|
|
2
6
|
begin
|
|
3
|
-
@response_from_httparty = HTTParty.get("http://#{@host_and_port}#{url}")
|
|
4
|
-
rescue HTTParty::RedirectionTooDeep => e
|
|
7
|
+
@response_from_httparty = HTTParty.get("http://#{@host_and_port}#{url}", @request_options)
|
|
8
|
+
rescue HTTParty::RedirectionTooDeep, Timeout::Error => e
|
|
5
9
|
@exception_from_httparty = e
|
|
6
10
|
end
|
|
7
11
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
def basic_mongrel_handler
|
|
2
2
|
Class.new(Mongrel::HttpHandler) do
|
|
3
|
-
attr_writer :content_type, :response_body, :response_code
|
|
3
|
+
attr_writer :content_type, :response_body, :response_code, :preprocessor
|
|
4
4
|
|
|
5
5
|
def initialize
|
|
6
6
|
@content_type = "text/html"
|
|
@@ -10,6 +10,7 @@ def basic_mongrel_handler
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def process(request, response)
|
|
13
|
+
instance_eval &@preprocessor if @preprocessor
|
|
13
14
|
reply_with(response, @response_code, @response_body)
|
|
14
15
|
end
|
|
15
16
|
|
|
@@ -12,6 +12,11 @@ Given /that service is accessed at the path '(.*)'/ do |path|
|
|
|
12
12
|
@server.register(path, @handler)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
Given /^that service takes (\d+) seconds to generate a response$/ do |time|
|
|
16
|
+
preprocessor = lambda { sleep time.to_i }
|
|
17
|
+
@handler.preprocessor = preprocessor
|
|
18
|
+
end
|
|
19
|
+
|
|
15
20
|
Given /the response from the service has a Content-Type of '(.*)'/ do |content_type|
|
|
16
21
|
@handler.content_type = content_type
|
|
17
22
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Feature: Supports the timeout option
|
|
2
|
+
In order to handle inappropriately slow response times
|
|
3
|
+
As a developer
|
|
4
|
+
I want my request to raise an exception after my specified timeout as elapsed
|
|
5
|
+
|
|
6
|
+
Scenario: A long running response
|
|
7
|
+
Given a remote service that returns '<h1>Some HTML</h1>'
|
|
8
|
+
And that service is accessed at the path '/service.html'
|
|
9
|
+
And that service takes 2 seconds to generate a response
|
|
10
|
+
When I set my HTTParty timeout option to 1
|
|
11
|
+
And I call HTTParty#get with '/service.html'
|
|
12
|
+
Then it should raise a Timeout::Error exception
|
data/httparty.gemspec
CHANGED
|
@@ -1,40 +1,127 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
1
4
|
# -*- encoding: utf-8 -*-
|
|
2
5
|
|
|
3
6
|
Gem::Specification.new do |s|
|
|
4
7
|
s.name = %q{httparty}
|
|
5
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.5.0"
|
|
6
9
|
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">=
|
|
8
|
-
s.authors = ["John Nunemaker"]
|
|
9
|
-
s.date = %q{2009-
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["John Nunemaker", "Sandro Turriate"]
|
|
12
|
+
s.date = %q{2009-12-07}
|
|
10
13
|
s.default_executable = %q{httparty}
|
|
11
14
|
s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
|
12
15
|
s.email = %q{nunemaker@gmail.com}
|
|
13
16
|
s.executables = ["httparty"]
|
|
14
|
-
s.extra_rdoc_files = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
s.extra_rdoc_files = [
|
|
18
|
+
"README.rdoc"
|
|
19
|
+
]
|
|
20
|
+
s.files = [
|
|
21
|
+
".gitignore",
|
|
22
|
+
"History",
|
|
23
|
+
"MIT-LICENSE",
|
|
24
|
+
"Manifest",
|
|
25
|
+
"README.rdoc",
|
|
26
|
+
"Rakefile",
|
|
27
|
+
"VERSION",
|
|
28
|
+
"bin/httparty",
|
|
29
|
+
"cucumber.yml",
|
|
30
|
+
"examples/aaws.rb",
|
|
31
|
+
"examples/basic.rb",
|
|
32
|
+
"examples/custom_parsers.rb",
|
|
33
|
+
"examples/delicious.rb",
|
|
34
|
+
"examples/google.rb",
|
|
35
|
+
"examples/rubyurl.rb",
|
|
36
|
+
"examples/twitter.rb",
|
|
37
|
+
"examples/whoismyrep.rb",
|
|
38
|
+
"features/basic_authentication.feature",
|
|
39
|
+
"features/command_line.feature",
|
|
40
|
+
"features/deals_with_http_error_codes.feature",
|
|
41
|
+
"features/handles_multiple_formats.feature",
|
|
42
|
+
"features/steps/env.rb",
|
|
43
|
+
"features/steps/httparty_response_steps.rb",
|
|
44
|
+
"features/steps/httparty_steps.rb",
|
|
45
|
+
"features/steps/mongrel_helper.rb",
|
|
46
|
+
"features/steps/remote_service_steps.rb",
|
|
47
|
+
"features/supports_redirection.feature",
|
|
48
|
+
"features/supports_timeout_option.feature",
|
|
49
|
+
"httparty.gemspec",
|
|
50
|
+
"lib/httparty.rb",
|
|
51
|
+
"lib/httparty/cookie_hash.rb",
|
|
52
|
+
"lib/httparty/core_extensions.rb",
|
|
53
|
+
"lib/httparty/exceptions.rb",
|
|
54
|
+
"lib/httparty/module_inheritable_attributes.rb",
|
|
55
|
+
"lib/httparty/parser.rb",
|
|
56
|
+
"lib/httparty/request.rb",
|
|
57
|
+
"lib/httparty/response.rb",
|
|
58
|
+
"lib/httparty/version.rb",
|
|
59
|
+
"spec/fixtures/delicious.xml",
|
|
60
|
+
"spec/fixtures/empty.xml",
|
|
61
|
+
"spec/fixtures/google.html",
|
|
62
|
+
"spec/fixtures/twitter.json",
|
|
63
|
+
"spec/fixtures/twitter.xml",
|
|
64
|
+
"spec/fixtures/undefined_method_add_node_for_nil.xml",
|
|
65
|
+
"spec/httparty/cookie_hash_spec.rb",
|
|
66
|
+
"spec/httparty/parser_spec.rb",
|
|
67
|
+
"spec/httparty/request_spec.rb",
|
|
68
|
+
"spec/httparty/response_spec.rb",
|
|
69
|
+
"spec/httparty_spec.rb",
|
|
70
|
+
"spec/spec.opts",
|
|
71
|
+
"spec/spec_helper.rb",
|
|
72
|
+
"website/css/common.css",
|
|
73
|
+
"website/index.html"
|
|
74
|
+
]
|
|
17
75
|
s.homepage = %q{http://httparty.rubyforge.org}
|
|
18
76
|
s.post_install_message = %q{When you HTTParty, you must party hard!}
|
|
19
|
-
s.rdoc_options = ["--
|
|
77
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
20
78
|
s.require_paths = ["lib"]
|
|
21
79
|
s.rubyforge_project = %q{httparty}
|
|
22
|
-
s.rubygems_version = %q{1.3.
|
|
80
|
+
s.rubygems_version = %q{1.3.5}
|
|
23
81
|
s.summary = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
|
82
|
+
s.test_files = [
|
|
83
|
+
"spec/httparty/cookie_hash_spec.rb",
|
|
84
|
+
"spec/httparty/parser_spec.rb",
|
|
85
|
+
"spec/httparty/request_spec.rb",
|
|
86
|
+
"spec/httparty/response_spec.rb",
|
|
87
|
+
"spec/httparty_spec.rb",
|
|
88
|
+
"spec/spec_helper.rb",
|
|
89
|
+
"examples/aaws.rb",
|
|
90
|
+
"examples/basic.rb",
|
|
91
|
+
"examples/custom_parsers.rb",
|
|
92
|
+
"examples/delicious.rb",
|
|
93
|
+
"examples/google.rb",
|
|
94
|
+
"examples/rubyurl.rb",
|
|
95
|
+
"examples/twitter.rb",
|
|
96
|
+
"examples/whoismyrep.rb"
|
|
97
|
+
]
|
|
24
98
|
|
|
25
99
|
if s.respond_to? :specification_version then
|
|
26
100
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
27
|
-
s.specification_version =
|
|
101
|
+
s.specification_version = 3
|
|
28
102
|
|
|
29
103
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
30
104
|
s.add_runtime_dependency(%q<crack>, [">= 0.1.1"])
|
|
31
|
-
s.add_development_dependency(%q<
|
|
105
|
+
s.add_development_dependency(%q<activesupport>, ["~> 2.3"])
|
|
106
|
+
s.add_development_dependency(%q<cucumber>, ["~> 0.4"])
|
|
107
|
+
s.add_development_dependency(%q<fakeweb>, ["~> 1.2"])
|
|
108
|
+
s.add_development_dependency(%q<mongrel>, ["~> 1.1"])
|
|
109
|
+
s.add_development_dependency(%q<rspec>, ["= 1.2.9"])
|
|
32
110
|
else
|
|
33
111
|
s.add_dependency(%q<crack>, [">= 0.1.1"])
|
|
34
|
-
s.add_dependency(%q<
|
|
112
|
+
s.add_dependency(%q<activesupport>, ["~> 2.3"])
|
|
113
|
+
s.add_dependency(%q<cucumber>, ["~> 0.4"])
|
|
114
|
+
s.add_dependency(%q<fakeweb>, ["~> 1.2"])
|
|
115
|
+
s.add_dependency(%q<mongrel>, ["~> 1.1"])
|
|
116
|
+
s.add_dependency(%q<rspec>, ["= 1.2.9"])
|
|
35
117
|
end
|
|
36
118
|
else
|
|
37
119
|
s.add_dependency(%q<crack>, [">= 0.1.1"])
|
|
38
|
-
s.add_dependency(%q<
|
|
120
|
+
s.add_dependency(%q<activesupport>, ["~> 2.3"])
|
|
121
|
+
s.add_dependency(%q<cucumber>, ["~> 0.4"])
|
|
122
|
+
s.add_dependency(%q<fakeweb>, ["~> 1.2"])
|
|
123
|
+
s.add_dependency(%q<mongrel>, ["~> 1.1"])
|
|
124
|
+
s.add_dependency(%q<rspec>, ["= 1.2.9"])
|
|
39
125
|
end
|
|
40
126
|
end
|
|
127
|
+
|