From 0474a613e19c6106cbe1e7277bc2ae8c5d3b80f4 Mon Sep 17 00:00:00 2001 From: Rony Varghese Date: Thu, 17 Jan 2013 10:31:17 +0530 Subject: [PATCH] Adding MOVE request handling --- lib/httparty.rb | 9 +++++++++ lib/httparty/request.rb | 3 ++- spec/httparty/request_spec.rb | 5 +++++ spec/httparty_spec.rb | 6 ++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/httparty.rb b/lib/httparty.rb index 570992e..0affb25 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -429,6 +429,11 @@ module HTTParty perform_request Net::HTTP::Delete, path, options, &block end + # Perform a MOVE request to a path + def move(path, options={}, &block) + perform_request Net::HTTP::Move, path, options, &block + end + # Perform a HEAD request to a path def head(path, options={}, &block) perform_request Net::HTTP::Head, path, options, &block @@ -499,6 +504,10 @@ module HTTParty Basement.delete(*args, &block) end + def self.move(*args, &block) + Basement.move(*args, &block) + end + def self.head(*args, &block) Basement.head(*args, &block) end diff --git a/lib/httparty/request.rb b/lib/httparty/request.rb index 82ef37d..5f2774e 100644 --- a/lib/httparty/request.rb +++ b/lib/httparty/request.rb @@ -7,7 +7,8 @@ module HTTParty Net::HTTP::Put, Net::HTTP::Delete, Net::HTTP::Head, - Net::HTTP::Options + Net::HTTP::Options, + Net::HTTP::Move ] SupportedURISchemes = [URI::HTTP, URI::HTTPS, URI::Generic] diff --git a/spec/httparty/request_spec.rb b/spec/httparty/request_spec.rb index f06a71f..d81975d 100644 --- a/spec/httparty/request_spec.rb +++ b/spec/httparty/request_spec.rb @@ -358,6 +358,11 @@ describe HTTParty::Request do @request.perform.should == {"hash" => {"foo" => "bar"}} end + it "should be handled by MOVE transparently" do + @request.http_method = Net::HTTP::Move + @request.perform.should == {"hash" => {"foo" => "bar"}} + end + it "should be handled by PATCH transparently" do @request.http_method = Net::HTTP::Patch @request.perform.should == {"hash" => {"foo" => "bar"}} diff --git a/spec/httparty_spec.rb b/spec/httparty_spec.rb index 130fb10..592322f 100644 --- a/spec/httparty_spec.rb +++ b/spec/httparty_spec.rb @@ -491,6 +491,12 @@ describe HTTParty do end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'} end + it "should fail with redirected MOVE" do + lambda do + @klass.move('/foo', :no_follow => true) + end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'} + end + it "should fail with redirected PUT" do lambda do @klass.put('/foo', :no_follow => true)