Created
November 6, 2008 16:25
-
-
Save snaka/22628 to your computer and use it in GitHub Desktop.
Gyazo client for windows (Ruby script version)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rem gyazowinR.bat | |
rem Gyazo client for Windows (Ruby script version) | |
rem by snaka (http://d.hatena.ne.jp/snaka72/) | |
ruby -x %~f0 %~s1 | |
rem pause | |
exit | |
#! ruby | |
require 'net/http' | |
require 'yaml' | |
# スクリプトが格納されている場所にidファイルを作る | |
script_dir = File.expand_path(File.dirname(__FILE__)) | |
idfile = "#{script_dir}\\gyazowin.bat.id" | |
id = '' | |
if File.exist?(idfile) then | |
id = File.read(idfile).chomp | |
else | |
id = Time.new.strftime("%Y%m%d%H%M%S") | |
File.open(idfile, "w").print( id + "\n") | |
end | |
imagefile = ARGV[0] | |
imagedata = open(imagefile, 'rb') {|f| f.read } | |
boundary = '----BOUNDARYBOUNDARY----' | |
data = <<EOF | |
--#{boundary}\r | |
content-disposition: form-data; name="id"\r | |
\r | |
#{id}\r | |
--#{boundary}\r | |
content-disposition: form-data; name="imagedata"\r | |
\r | |
#{imagedata}\r | |
\r | |
--#{boundary}--\r | |
EOF | |
header ={ | |
'Content-Length' => data.length.to_s, | |
'Content-type' => "multipart/form-data; boundary=#{boundary}" | |
} | |
# load proxy settings (optional) | |
proxy_setting = "#{script_dir}\\proxy.yaml" | |
proxy = {} | |
if (FileTest.exist?(proxy_setting)) | |
proxy = YAML.load_file(proxy_setting) | |
puts "proxy settings: #{proxy['address']}, #{proxy['port']}" | |
end | |
HOST = 'gyazo.com' | |
CGI = '/upload.cgi' | |
Net::HTTP::Proxy(proxy['address'], proxy['port']).start(HOST){|http| | |
res = http.post(CGI, data, header) | |
url = res.response.to_ary[1] | |
system("start #{url}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment