[BioRuby-cvs] bioruby/lib/bio command.rb,1.14,1.15
Katayama Toshiaki
k at dev.open-bio.org
Wed Mar 28 16:54:13 UTC 2007
Update of /home/repository/bioruby/bioruby/lib/bio
In directory dev.open-bio.org:/tmp/cvs-serv7774
Modified Files:
command.rb
Log Message:
* post_form method is extended to accept params as
array of string,
array of hash,
array of array,
or
string
in addition to hash.
* params option can be ommited if not needed (defaults to nil)
Index: command.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/command.rb,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** command.rb 28 Mar 2007 12:31:03 -0000 1.14
--- command.rb 28 Mar 2007 16:54:11 -0000 1.15
***************
*** 272,289 ****
# +header+ must be a hash.
#
! def post_form(uri, params, header = {})
unless uri.is_a?(URI)
uri = URI.parse(uri)
end
! data = params.map do |key, val|
! "#{URI.escape(key.to_s)}=#{URI.escape(val.to_s)}"
! end.join('&')
! h = {
'Content-Type' => 'application/x-www-form-urlencoded',
'Content-Length' => data.length.to_s
}
! h.update(header)
start_http(uri.host, uri.port) do |http|
! http.post(uri.path, data, h)
end
end
--- 272,310 ----
# +header+ must be a hash.
#
! def post_form(uri, params = nil, header = {})
unless uri.is_a?(URI)
uri = URI.parse(uri)
end
!
! data = ""
!
! case params
! when Hash
! data = params.map do |key, val|
! "#{URI.escape(key.to_s)}=#{URI.escape(val.to_s)}"
! end.join('&')
! when Array
! case params.first
! when Hash, Array
! data = params.map do |key, val|
! "#{URI.escape(key.to_s)}=#{URI.escape(val.to_s)}"
! end.join('&')
! when String
! data = params.map do |str|
! URI.escape(str.strip)
! end.join('&')
! end
! when String
! data = URI.escape(params.strip)
! end
!
! hash = {
'Content-Type' => 'application/x-www-form-urlencoded',
'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
More information about the bioruby-cvs
mailing list