Permalink
Browse files

How are you?

  • Loading branch information...
ujihisa committed Aug 16, 2009
1 parent a0ab6c1 commit d27f12e08378716c044fa9ef53556dab900296cd
Showing with 34 additions and 0 deletions.
  1. 0 README → README.md
  2. +34 −0 net-https-wrapper.rb
View
File renamed without changes.
View
@@ -0,0 +1,34 @@
+require 'net/https'
+
+class Net::HTTP
+ def self.post(uri, data, header)
+ __post_or_put__(:post, uri, data, header)
+ end
+
+ def self.put(uri, data, header)
+ __post_or_put__(:put, uri, data, header)
+ end
+
+ def self.__post_or_put__(method, uri, data, header)
+ uri = URI.parse(uri)
+ i = new(uri.host, uri.port)
+ unless uri.port == 80
+ i.use_ssl = true
+ i.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
+ i.__send__(method, uri.path, data, header)
+ end
+end
+
+# sample code
+# a = Net::HTTP.post(
+# 'https://www.google.com/accounts/ClientLogin',
+# {
+# 'Email' => email,
+# 'Passwd' => pass,
+# 'service' => 'blogger',
+# 'accountType' => 'HOSTED_OR_GOOGLE',
+# 'source' => 'ujihisa-bloggervim-1'
+# }.map {|i, j| "#{i}=#{j}" }.join('&'),
+# {'Content-Type' => 'application/x-www-form-urlencoded'})
+# a.body.lines.to_a.maph {|i| i.split('=') }['Auth'].chomp

0 comments on commit d27f12e

Please sign in to comment.