Patches: Browse | Submit New | Admin
When writing clients for REST web services, I want to use the simple interface of open-uri.rb to make HTTP requests that use POST, PUT, DELETE, etc. Currently only GET requests are supported. A simple change (2 new options) gives support for all HTTP methods without breaking the old interface. I have patches for both Ruby 1.8 and 1.9. Let me know if you have questions or need anything else from me.
Add A Comment:
Date: 2011-03-12 02:26 Sender: Joan Marquez I think this patch is really useful, why was never appplied?
Date: 2006-11-14 18:42 Sender: Ivan Todoroski Or even worse ;) # get all classes in Net::HTTP inherited from HTTPRequest method_classes = Net::HTTP.constants.map {|m| Net::HTTP.const_get(m) }.select {|c| c.is_a? Class and c.ancestors.include? Net::HTTPRequest } # map them to their shortened lower case names Methods = Hash[*method_classes.inject([]) {|a,m| a.push m.to_s.split("::").last.downcase.to_sym, m }]
Date: 2006-11-14 17:28 Sender: Ivan Todoroski This is a nice patch, very useful for me, thanks. Hope it's accepted in Ruby soon. As for you comment about Methods initialization, there are ways to shorten it, but I'm not sure if the cure is worse than the disease :) methods = %w(copy delete get head lock mkcol options post propfind proppatch put trace unlock) Methods = Hash[*methods.inject([]) {|a,m| a.push m.to_sym, eval("Net::HTTP::#{m.capitalize}")}]