[BioRuby-cvs] bioruby/lib/bio command.rb,1.8,1.9

Naohisa Goto ngoto at dev.open-bio.org
Tue May 9 07:13:56 UTC 2006


Update of /home/repository/bioruby/bioruby/lib/bio
In directory dev.open-bio.org:/tmp/cvs-serv18420/lib/bio

Modified Files:
	command.rb 
Log Message:
* new method Bio::Command::NetTools.post_form is added. Note that it is
  bioruby internal use only and users should not use it.
* Bio::Command::NetTools.net_http_start is renamed to http_start.
  (net_http_start still remains as an alias.)


Index: command.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/command.rb,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** command.rb	27 Apr 2006 03:15:27 -0000	1.8
--- command.rb	9 May 2006 07:13:54 -0000	1.9
***************
*** 171,175 ****
    # is set.
    #
!   def net_http_start(address, port = 80, &block)
      uri = URI.parse("http://#{address}:#{port}")
      # Note: URI#find_proxy is an unofficial method defined in open-uri.rb.
--- 171,175 ----
    # is set.
    #
!   def http_start(address, port = 80, &block)
      uri = URI.parse("http://#{address}:#{port}")
      # Note: URI#find_proxy is an unofficial method defined in open-uri.rb.
***************
*** 183,188 ****
--- 183,216 ----
      http.start(address, port, &block)
    end
+   module_function :http_start
+ 
+   alias net_http_start http_start
    module_function :net_http_start
  
+   # Same as:
+   # Net::HTTP.post_form(uri, params)
+   # and 
+   # it uses proxy if an environment variable (same as OpenURI.open_uri)
+   # is set.
+   # In addition, +header+ can be set.
+   # (Note that Content-Type and Content-Length are automatically
+   # set by default.)
+   # +uri+ must be a URI object and +params+ must be a hash.
+   #
+   def post_form(uri, params, header = {})
+     data = params.map do |key, val|
+       "#{URI.escape(key)}=#{URI.escape(val)}" 
+     end.join('&')
+     h = {
+       'Content-Type'   => 'application/x-www-form-urlencoded',
+       'Content-Length' => data.length.to_s
+     }
+     h.update(header)
+     net_http_start(uri.host, uri.port) do |http|
+       http.post(uri.path, data, h)
+     end
+   end
+   module_function :post_form
+ 
  end #module NetTools
  




More information about the bioruby-cvs mailing list