Skip to content

Commit

Permalink
More support for PUT
Browse files Browse the repository at this point in the history
  • Loading branch information
alcides authored and defunkt committed Mar 20, 2011
1 parent 4f4b4f5 commit 5a4eec1
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 5a4eec1

Please sign in to comment.