Class: PigMediaServer::Gyazo
- Inherits:
-
Object
- Object
- PigMediaServer::Gyazo
- Defined in:
- lib/pig-media-server/web.rb
Class Method Summary collapse
Class Method Details
.post(url, point) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pig-media-server/web.rb', line 55 def self.post url, point imagedata = url.sub(/data:image\/png;base64,/, '').unpack('m').first boundary = '----BOUNDARYBOUNDARY----' id = rand(256**16).to_s(16) data = <<EOF --#{boundary}\r content-disposition: form-data; name="id"\r \r #{id}\r --#{boundary}\r content-disposition: form-data; name="imagedata"; filename="gyazo.com"\r \r #{imagedata}\r --#{boundary}--\r EOF header ={ 'Content-Length' => data.length.to_s, 'Content-type' => "multipart/form-data; boundary=#{boundary}", 'User-Agent' => 'ssig33.com/1.0' } proxy_host, proxy_port = nil, nil uri = URI.parse point Net::HTTP::Proxy(proxy_host, proxy_port).start(uri.host,80) {|http| res = http.post(uri.path, data, header).body puts res return res } end |
.tweet(url, comment, key, secret, token, token_secret, c) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pig-media-server/web.rb', line 34 def self.tweet url, comment, key, secret, token, token_secret, c Dir.mktmpdir do |dir| name = dir + "/#{rand(256**16).to_s(16)}.png" jpg = name.sub(/png$/, 'jpg') img = url.sub(/data:image\/png;base64,/, '').unpack('m').first open(name, 'w'){|f| f.puts img} system "gm", "convert", name, jpg jpg = name unless File.exists? jpg client = Twitter::REST::Client.new do |config| config.consumer_key = key config.consumer_secret = secret config.access_token = token config.access_token_secret = token_secret end client.update_with_media(comment.to_s, open(jpg))# rescue nil FileUtils.rm name rescue nil FileUtils.rm jpg rescue nil end end |