Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jnunemaker/httparty
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Sep 15, 2009
2 parents 2b6ca2f + 7443e42 commit 3509007
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 140 deletions.
13 changes: 10 additions & 3 deletions History
@@ -1,5 +1,12 @@
== 0.4.5 2009-08-22
* default headers are now correctly passed (sporkd)
== 0.4.5 2009-09-12
* bug fixes
* Fixed class-level headers overwritten by cookie management code. Closes #19
* Fixed "superclass mismatch for class BlankSlate" error. Closes #20
* Fixed reading files as post data from the command line (vesan)
* minor enhancements
* Timeout option added; will raise a Timeout::Error after the timeout has elapsed (attack). Closes #17
HTTParty.get "http://github.com", :timeout => 1
* Building gem with Jeweler

== 0.4.4 2009-07-19
* 2 minor update
Expand Down Expand Up @@ -131,4 +138,4 @@
== 0.1.0 2008-07-27

* 1 major enhancement:
* Initial release
* Initial release
137 changes: 69 additions & 68 deletions Rakefile
@@ -1,69 +1,70 @@
require 'rubygems'
require 'rake'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "httparty"
gem.summary = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
gem.description = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
gem.email = "nunemaker@gmail.com"
gem.homepage = "http://httparty.rubyforge.org"
gem.authors = ["John Nunemaker"]
gem.add_dependency 'crack', '>= 0.1.1'
gem.add_development_dependency "rspec"
gem.post_install_message = "When you HTTParty, you must party hard!"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::RubyforgeTasks.new do |rubyforge|
rubyforge.doc_task = "rdoc"
end
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end

require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
end

Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end

task :spec => :check_dependencies

begin
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features)

task :features => :check_dependencies
rescue LoadError
task :features do
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
end
end

task :default => [:spec, :features]

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
if File.exist?('VERSION')
version = File.read('VERSION')
else
version = ""
end

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "httparty #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

desc 'Upload website files to rubyforge'
task :website do
sh %{rsync -av website/ jnunemaker@rubyforge.org:/var/www/gforge-projects/httparty}
require 'rubygems'
require 'rake'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "httparty"
gem.summary = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
gem.description = %Q{Makes http fun! Also, makes consuming restful web services dead easy.}
gem.email = "nunemaker@gmail.com"
gem.homepage = "http://httparty.rubyforge.org"
gem.authors = ["John Nunemaker"]
gem.add_dependency 'crack', '>= 0.1.1'
gem.add_development_dependency "rspec", "1.2.8"
gem.post_install_message = "When you HTTParty, you must party hard!"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::RubyforgeTasks.new do |rubyforge|
rubyforge.doc_task = "rdoc"
end
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end

require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
spec.spec_opts = ['--options', 'spec/spec.opts']
end

Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end

task :spec => :check_dependencies

begin
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features)

task :features => :check_dependencies
rescue LoadError
task :features do
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
end
end

task :default => [:spec, :features]

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
if File.exist?('VERSION')
version = File.read('VERSION')
else
version = ""
end

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "httparty #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

desc 'Upload website files to rubyforge'
task :website do
sh %{rsync -av website/ jnunemaker@rubyforge.org:/var/www/gforge-projects/httparty}
end
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.4.4
0.4.5
2 changes: 1 addition & 1 deletion bin/httparty
Expand Up @@ -37,7 +37,7 @@ OptionParser.new do |o|
"--data [BODY]",
"Data to put in request body (prefix with '@' for file)") do |d|
if d =~ /^@/
opts[:data] = open(d).read
opts[:data] = open(d[1..-1]).read
else
opts[:data] = d
end
Expand Down
1 change: 1 addition & 0 deletions features/steps/env.rb
Expand Up @@ -8,6 +8,7 @@
@host_and_port = "0.0.0.0:#{port}"
@server = Mongrel::HttpServer.new("0.0.0.0", port)
@server.run
@request_options = {}
end

After do
Expand Down
4 changes: 2 additions & 2 deletions features/steps/httparty_response_steps.rb
Expand Up @@ -20,7 +20,7 @@
@response_from_httparty.code.should eql(code.to_i)
end

Then /it should raise an HTTParty::RedirectionTooDeep exception/ do
Then /it should raise (?:an|a) ([\w:]+) exception/ do |exception|
@exception_from_httparty.should_not be_nil
@exception_from_httparty.class.should eql(HTTParty::RedirectionTooDeep)
@exception_from_httparty.class.name.should eql(exception)
end
8 changes: 6 additions & 2 deletions features/steps/httparty_steps.rb
@@ -1,7 +1,11 @@
When /^I set my HTTParty timeout option to (\d+)$/ do |timeout|
@request_options[:timeout] = timeout.to_i
end

When /I call HTTParty#get with '(.*)'$/ do |url|
begin
@response_from_httparty = HTTParty.get("http://#{@host_and_port}#{url}")
rescue HTTParty::RedirectionTooDeep => e
@response_from_httparty = HTTParty.get("http://#{@host_and_port}#{url}", @request_options)
rescue HTTParty::RedirectionTooDeep, Timeout::Error => e
@exception_from_httparty = e
end
end
Expand Down
3 changes: 2 additions & 1 deletion features/steps/mongrel_helper.rb
@@ -1,6 +1,6 @@
def basic_mongrel_handler
Class.new(Mongrel::HttpHandler) do
attr_writer :content_type, :response_body, :response_code
attr_writer :content_type, :response_body, :response_code, :preprocessor

def initialize
@content_type = "text/html"
Expand All @@ -10,6 +10,7 @@ def initialize
end

def process(request, response)
instance_eval &@preprocessor if @preprocessor
reply_with(response, @response_code, @response_body)
end

Expand Down
5 changes: 5 additions & 0 deletions features/steps/remote_service_steps.rb
Expand Up @@ -12,6 +12,11 @@
@server.register(path, @handler)
end

Given /^that service takes (\d+) seconds to generate a response$/ do |time|
preprocessor = lambda { sleep time.to_i }
@handler.preprocessor = preprocessor
end

Given /the response from the service has a Content-Type of '(.*)'/ do |content_type|
@handler.content_type = content_type
end
Expand Down
12 changes: 12 additions & 0 deletions features/supports_timeout_option.feature
@@ -0,0 +1,12 @@
Feature: Supports the timeout option
In order to handle inappropriately slow response times
As a developer
I want my request to raise an exception after my specified timeout as elapsed

Scenario: A long running response
Given a remote service that returns '<h1>Some HTML</h1>'
And that service is accessed at the path '/service.html'
And that service takes 2 seconds to generate a response
When I set my HTTParty timeout option to 1
And I call HTTParty#get with '/service.html'
Then it should raise a Timeout::Error exception
89 changes: 79 additions & 10 deletions httparty.gemspec
@@ -1,40 +1,109 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{httparty}
s.version = "0.4.4"
s.version = "0.4.5"

s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["John Nunemaker"]
s.date = %q{2009-07-19}
s.date = %q{2009-09-12}
s.default_executable = %q{httparty}
s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
s.email = %q{nunemaker@gmail.com}
s.executables = ["httparty"]
s.extra_rdoc_files = ["bin/httparty", "lib/httparty/cookie_hash.rb", "lib/httparty/core_extensions.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/request.rb", "lib/httparty/response.rb", "lib/httparty/version.rb", "lib/httparty.rb", "README.rdoc"]
s.files = ["bin/httparty", "cucumber.yml", "examples/aaws.rb", "examples/basic.rb", "examples/delicious.rb", "examples/google.rb", "examples/rubyurl.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "features/basic_authentication.feature", "features/command_line.feature", "features/deals_with_http_error_codes.feature", "features/handles_multiple_formats.feature", "features/steps/env.rb", "features/steps/httparty_response_steps.rb", "features/steps/httparty_steps.rb", "features/steps/mongrel_helper.rb", "features/steps/remote_service_steps.rb", "features/supports_redirection.feature", "History", "httparty.gemspec", "lib/httparty/cookie_hash.rb", "lib/httparty/core_extensions.rb", "lib/httparty/exceptions.rb", "lib/httparty/module_inheritable_attributes.rb", "lib/httparty/request.rb", "lib/httparty/response.rb", "lib/httparty/version.rb", "lib/httparty.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README.rdoc", "spec/fixtures/delicious.xml", "spec/fixtures/empty.xml", "spec/fixtures/google.html", "spec/fixtures/twitter.json", "spec/fixtures/twitter.xml", "spec/fixtures/undefined_method_add_node_for_nil.xml", "spec/httparty/cookie_hash_spec.rb", "spec/httparty/request_spec.rb", "spec/httparty/response_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "website/css/common.css", "website/index.html"]
s.extra_rdoc_files = [
"README.rdoc"
]
s.files = [
".gitignore",
"History",
"MIT-LICENSE",
"Manifest",
"README.rdoc",
"Rakefile",
"VERSION",
"bin/httparty",
"cucumber.yml",
"examples/aaws.rb",
"examples/basic.rb",
"examples/delicious.rb",
"examples/google.rb",
"examples/rubyurl.rb",
"examples/twitter.rb",
"examples/whoismyrep.rb",
"features/basic_authentication.feature",
"features/command_line.feature",
"features/deals_with_http_error_codes.feature",
"features/handles_multiple_formats.feature",
"features/steps/env.rb",
"features/steps/httparty_response_steps.rb",
"features/steps/httparty_steps.rb",
"features/steps/mongrel_helper.rb",
"features/steps/remote_service_steps.rb",
"features/supports_redirection.feature",
"features/supports_timeout_option.feature",
"httparty.gemspec",
"lib/httparty.rb",
"lib/httparty/cookie_hash.rb",
"lib/httparty/core_extensions.rb",
"lib/httparty/exceptions.rb",
"lib/httparty/module_inheritable_attributes.rb",
"lib/httparty/request.rb",
"lib/httparty/response.rb",
"lib/httparty/version.rb",
"spec/fixtures/delicious.xml",
"spec/fixtures/empty.xml",
"spec/fixtures/google.html",
"spec/fixtures/twitter.json",
"spec/fixtures/twitter.xml",
"spec/fixtures/undefined_method_add_node_for_nil.xml",
"spec/httparty/cookie_hash_spec.rb",
"spec/httparty/request_spec.rb",
"spec/httparty/response_spec.rb",
"spec/httparty_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb",
"website/css/common.css",
"website/index.html"
]
s.has_rdoc = true
s.homepage = %q{http://httparty.rubyforge.org}
s.post_install_message = %q{When you HTTParty, you must party hard!}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Httparty", "--main", "README.rdoc"]
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{httparty}
s.rubygems_version = %q{1.3.1}
s.summary = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
s.test_files = [
"spec/httparty/cookie_hash_spec.rb",
"spec/httparty/request_spec.rb",
"spec/httparty/response_spec.rb",
"spec/httparty_spec.rb",
"spec/spec_helper.rb",
"examples/aaws.rb",
"examples/basic.rb",
"examples/delicious.rb",
"examples/google.rb",
"examples/rubyurl.rb",
"examples/twitter.rb",
"examples/whoismyrep.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<crack>, [">= 0.1.1"])
s.add_development_dependency(%q<echoe>, [">= 0"])
s.add_development_dependency(%q<rspec>, ["= 1.2.8"])
else
s.add_dependency(%q<crack>, [">= 0.1.1"])
s.add_dependency(%q<echoe>, [">= 0"])
s.add_dependency(%q<rspec>, ["= 1.2.8"])
end
else
s.add_dependency(%q<crack>, [">= 0.1.1"])
s.add_dependency(%q<echoe>, [">= 0"])
s.add_dependency(%q<rspec>, ["= 1.2.8"])
end
end
8 changes: 3 additions & 5 deletions lib/httparty.rb
Expand Up @@ -172,11 +172,9 @@ def perform_request(http_method, path, options) #:nodoc:
end

def process_cookies(options) #:nodoc:
return unless options[:cookies] || default_cookies
options[:headers] ||= {}
options[:headers]["cookie"] = cookies.merge(options[:cookies] || {}).to_cookie_string

options.delete(:cookies)
return unless options[:cookies] || default_cookies.any?
options[:headers] ||= headers.dup
options[:headers]["cookie"] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
end
end

Expand Down

0 comments on commit 3509007

Please sign in to comment.