Skip to content

Instantly share code, notes, and snippets.

@ebith
Created September 6, 2012 16:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ebith/3657917 to your computer and use it in GitHub Desktop.
Save ebith/3657917 to your computer and use it in GitHub Desktop.
Gyazoのアップロード先をTumblrにするやつAPI v2版
#!/usr/bin/env ruby
require 'oauth'
consumer = OAuth::Consumer.new(
'consumer_key',
'consumer_secret',
{
site: 'http://api.tumblr.com',
request_token_url: "http://www.tumblr.com/oauth/request_token",
authorize_url: "http://www.tumblr.com/oauth/authorize",
access_token_url: "http://www.tumblr.com/oauth/access_token"
}
)
request_token = consumer.get_request_token
system('open ' + request_token.authorize_url)
p 'enter oauth_verifier'
oauth_verifier = gets.chomp!
access_token = request_token.get_access_token(:oauth_verifier => oauth_verifier)
p 'oauth_token : ' + access_token.token
p 'oauth_token_secret : ' + access_token.secret
#!/usr/bin/env ruby
require 'rubygems'
require 'net/http'
require 'tumblife'
HOME = 'hoge.tumblr.com'
Tumblife.configure do |config|
config.consumer_key = ''
config.consumer_secret = ''
config.oauth_token = ''
config.oauth_token_secret = ''
end
client = Tumblife.client
tmpfile = "/tmp/image_upload#{$$}.png"
imagefile = ARGV[1]
if imagefile && File.exist?(imagefile) then
system "sips -s format png \"#{imagefile}\" --out \"#{tmpfile}\""
else
system "screencapture -i \"#{tmpfile}\""
if File.exist?(tmpfile) then
system "sips -d profile --deleteColorManagementProperties \"#{tmpfile}\""
end
end
if !File.exist?(tmpfile) then
exit
end
res = client.photo(HOME, :data => Faraday::UploadIO.new(tmpfile, 'image/png'))
File.delete(tmpfile)
system "echo -n http://#{HOME}/post/#{res.id} | pbcopy"
system "open http://#{HOME}/post/#{res.id}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment