lib/gyazo.rb in gyazo-0.0.5 vs lib/gyazo.rb in gyazo-0.1.0
- old
+ new
@@ -3,11 +3,11 @@
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
require 'net/http'
class Gyazo
- VERSION = '0.0.5'
+ VERSION = '0.1.0'
def initialize(app = '/Applications/Gyazo.app')
@user = IO.popen("whoami", "r+").gets.chomp
@program = app
@idfile = "/Users/#{@user}/Library/Gyazo/id"
@@ -18,11 +18,11 @@
elsif File.exist?(@old_idfile) then
@id = File.read(@old_idfile).chomp
end
end
- def upload(imagefile)
+ def upload(imagefile,time=nil)
tmpfile = "/tmp/image_upload#{$$}.png"
if imagefile && File.exist?(imagefile) then
system "sips -s format png \"#{imagefile}\" --out \"#{tmpfile}\" > /dev/null"
end
imagedata = File.read(tmpfile)
@@ -41,9 +41,21 @@
content-disposition: form-data; name="imagedata"; filename="gyazo.com"\r
\r
#{imagedata}\r
--#{boundary}--\r
EOF
+
+ if time && time.class == Time then
+ @timestr = time.gmtime.strftime("%Y-%m-%d %H:%M:%S")
+ s = <<EOF
+--#{boundary}\r
+content-disposition: form-data; name="date"\r
+\r
+#{@timestr}\r
+EOF
+ data = s + data
+ end
+
header ={
'Content-Length' => data.length.to_s,
'Content-type' => "multipart/form-data; boundary=#{boundary}",
'User-Agent' => @ua
}