Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More support for PUT

  • Loading branch information...
commit 5a4eec159eb523c50944a66753194cf349e0de93 1 parent 4f4b4f5
@alcides alcides authored defunkt committed
Showing with 19 additions and 2 deletions.
  1. +19 −2 app/app.rb
View
21 app/app.rb
@@ -155,7 +155,11 @@ def initialize(*args)
begin
debug { puts "#{method} #{url}" }
- curl.send("http_#{method.downcase}", *post_data)
+ if method == 'PUT'
+ curl.http_put(stringify_data(post_data))
+ else
+ curl.send("http_#{method.downcase}", *post_data)
+ end
debug do
puts sent_headers.join("\n")
@@ -223,7 +227,7 @@ def add_headers_from_arrays(curl, keys, values)
# post params from non-empty keys and values
def make_fields(method, keys, values)
- return [] unless method == 'POST'
+ return [] unless %w( POST PUT ).include? method
fields = []
keys, values = Array(keys), Array(values)
@@ -257,5 +261,18 @@ def find_hurl_or_view(id)
def rate_limited?
false
end
+
+ # turn post_data into a string for PUT requests
+ def stringify_data(data)
+ if data.is_a? String
+ data
+ elsif data.is_a? Array
+ data.map { |x| stringify_data(x) }.join("&")
+ elsif data.is_a? Curl::PostField
+ data.to_s
+ else
+ raise "Cannot stringify #{data.inspect}"
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.