mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Fixed weird issue with content length when using net http post method. [#9 state:resolved]
This commit is contained in:
parent
f4c46223f4
commit
a517168278
7 changed files with 38 additions and 5 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
== 0.1.6 2008-11-26
|
||||||
|
* 1 major enhancement
|
||||||
|
* now passing :query to set_form_data if post request to avoid content length errors
|
||||||
|
|
||||||
== 0.1.5 2008-11-14
|
== 0.1.5 2008-11-14
|
||||||
* 2 major enhancements
|
* 2 major enhancements
|
||||||
* Refactored send request method out into its own object.
|
* Refactored send request method out into its own object.
|
||||||
|
|
|
@ -9,6 +9,7 @@ config/requirements.rb
|
||||||
examples/aaws.rb
|
examples/aaws.rb
|
||||||
examples/delicious.rb
|
examples/delicious.rb
|
||||||
examples/google.rb
|
examples/google.rb
|
||||||
|
examples/rubyurl.rb
|
||||||
examples/twitter.rb
|
examples/twitter.rb
|
||||||
examples/whoismyrep.rb
|
examples/whoismyrep.rb
|
||||||
httparty.gemspec
|
httparty.gemspec
|
||||||
|
|
14
examples/rubyurl.rb
Normal file
14
examples/rubyurl.rb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||||
|
require File.join(dir, 'httparty')
|
||||||
|
|
||||||
|
class Rubyurl
|
||||||
|
include HTTParty
|
||||||
|
base_uri 'rubyurl.com'
|
||||||
|
|
||||||
|
def self.shorten(website_url)
|
||||||
|
xml = post('/api/links.json', :query => {'link[website_url]' => website_url})
|
||||||
|
xml['link'] && xml['link']['permalink']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
puts Rubyurl.shorten( 'http://istwitterdown.com/' ).inspect
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{httparty}
|
s.name = %q{httparty}
|
||||||
s.version = "0.1.5"
|
s.version = "0.1.6"
|
||||||
|
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") 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.authors = ["John Nunemaker"]
|
||||||
s.date = %q{2008-11-14}
|
s.date = %q{2008-11-26}
|
||||||
s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
||||||
s.email = ["nunemaker@gmail.com"]
|
s.email = ["nunemaker@gmail.com"]
|
||||||
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt"]
|
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt"]
|
||||||
s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "examples/aaws.rb", "examples/delicious.rb", "examples/google.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "httparty.gemspec", "lib/httparty.rb", "lib/httparty/request.rb", "lib/httparty/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/httparty/request_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "website/css/common.css", "website/index.html"]
|
s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "examples/aaws.rb", "examples/delicious.rb", "examples/google.rb", "examples/rubyurl.rb", "examples/twitter.rb", "examples/whoismyrep.rb", "httparty.gemspec", "lib/httparty.rb", "lib/httparty/request.rb", "lib/httparty/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/httparty/request_spec.rb", "spec/httparty_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "website/css/common.css", "website/index.html"]
|
||||||
s.has_rdoc = true
|
s.has_rdoc = true
|
||||||
s.homepage = %q{http://httparty.rubyforge.org}
|
s.homepage = %q{http://httparty.rubyforge.org}
|
||||||
s.post_install_message = %q{When you HTTParty, you must party hard!}
|
s.post_install_message = %q{When you HTTParty, you must party hard!}
|
||||||
|
|
|
@ -37,7 +37,8 @@ module HTTParty
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_response(uri) #:nodoc:
|
def get_response(uri) #:nodoc:
|
||||||
request = http_method.new(uri.request_uri)
|
request = http_method.new(uri.request_uri)
|
||||||
|
request.set_form_data(options[:query]) if post? && options[:query]
|
||||||
request.body = options[:body].is_a?(Hash) ? options[:body].to_query : options[:body] unless options[:body].blank?
|
request.body = options[:body].is_a?(Hash) ? options[:body].to_query : options[:body] unless options[:body].blank?
|
||||||
request.initialize_http_header options[:headers]
|
request.initialize_http_header options[:headers]
|
||||||
request.basic_auth(options[:basic_auth][:username], options[:basic_auth][:password]) if options[:basic_auth]
|
request.basic_auth(options[:basic_auth][:username], options[:basic_auth][:password]) if options[:basic_auth]
|
||||||
|
@ -99,6 +100,11 @@ module HTTParty
|
||||||
raise ArgumentError, 'only get, post, put and delete methods are supported' unless SupportedHTTPMethods.include?(http_method)
|
raise ArgumentError, 'only get, post, put and delete methods are supported' unless SupportedHTTPMethods.include?(http_method)
|
||||||
raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].is_a?(Hash)
|
raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].is_a?(Hash)
|
||||||
raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].is_a?(Hash)
|
raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].is_a?(Hash)
|
||||||
|
raise ArgumentError, ':query must be hash if using HTTP Post' if post? && !options[:query].nil? && !options[:query].is_a?(Hash)
|
||||||
|
end
|
||||||
|
|
||||||
|
def post?
|
||||||
|
Net::HTTP::Post == http_method
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ module HTTParty
|
||||||
module VERSION #:nodoc:
|
module VERSION #:nodoc:
|
||||||
MAJOR = 0
|
MAJOR = 0
|
||||||
MINOR = 1
|
MINOR = 1
|
||||||
TINY = 5
|
TINY = 6
|
||||||
|
|
||||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -105,3 +105,11 @@ describe HTTParty::Request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe HTTParty::Request, "with POST http method" do
|
||||||
|
it "should raise argument error if query is not a hash" do
|
||||||
|
lambda {
|
||||||
|
HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :format => :xml, :query => 'astring').perform
|
||||||
|
}.should raise_error(ArgumentError)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue