lib/bio/command.rb in bio-1.4.3.0001 vs lib/bio/command.rb in bio-1.5.0
- old
+ new
@@ -4,11 +4,10 @@
# Copyright:: Copyright (C) 2003-2010
# Naohisa Goto <ng@bioruby.org>,
# Toshiaki Katayama <k@bioruby.org>
# License:: The Ruby License
#
-# $Id:$
#
require 'open3'
require 'uri'
require 'open-uri'
@@ -854,11 +853,11 @@
CGI.escape(str)
end
end.join('&')
end
when String
- data = URI.escape(params.strip)
+ raise TypeError, 'Bio::Command.make_cgi_params no longer accepts a single String as a form'
end
return data
end
# Builds parameter string for from a key string and a value (or values)
@@ -878,9 +877,70 @@
end
else
result << [key, value].map {|x| CGI.escape(x.to_s) }.join('=')
end
return result
+ end
+
+ # Same as:
+ # http = Net::HTTP.new(...); http.post(path, data, header)
+ # and
+ # it uses proxy if an environment variable (same as OpenURI.open_uri)
+ # is set.
+ # In addition, +header+ can be set.
+ # (Default Content-Type is application/octet-stream.
+ # Content-Length is automatically set by default.)
+ # +uri+ must be a URI object, +params+ must be a hash, and
+ # +header+ must be a hash.
+ #
+ # ---
+ # *Arguments*:
+ # * (required) _http_: Net::HTTP object or compatible object
+ # * (required) _path_: String
+ # * (required) _data_: String containing data
+ # * (optional) _header_: Hash containing header strings
+ # *Returns*:: (same as Net::HTTP::post)
+ def http_post(http, path, data, header = {})
+ hash = {
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Length' => data.length.to_s
+ }
+ hash.update(header)
+
+ http.post(path, data, hash)
+ end
+
+ # Same as:
+ # Net::HTTP.post(uri, params)
+ # and
+ # it uses proxy if an environment variable (same as OpenURI.open_uri)
+ # is set.
+ # In addition, +header+ can be set.
+ # (Default Content-Type is application/octet-stream.
+ # Content-Length is automatically set by default.)
+ # +uri+ must be a URI object, +data+ must be a String, and
+ # +header+ must be a hash.
+ #
+ # ---
+ # *Arguments*:
+ # * (required) _uri_: URI object or String
+ # * (optional) _data_: String containing data
+ # * (optional) _header_: Hash containing header strings
+ # *Returns*:: (same as Net::HTTP::post)
+ def post(uri, data, header = {})
+ unless uri.is_a?(URI)
+ uri = URI.parse(uri)
+ end
+
+ hash = {
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Length' => data.length.to_s
+ }
+ hash.update(header)
+
+ start_http(uri.host, uri.port) do |http|
+ http.post(uri.path, data, hash)
+ end
end
end # module Command
end # module Bio