Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created April 12, 2011 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jugyo/915244 to your computer and use it in GitHub Desktop.
Save jugyo/915244 to your computer and use it in GitHub Desktop.
earthquake.gem imgur command
Earthquake.init do
config[:imgur] ||= {api_key: '5cb04404b1ff26a88cbfe42de5aba23f'}
command :imgur do
require 'tempfile'
image_path = Tempfile.open('imgur').path
puts "capture an image from the screen!"
system 'screencapture', '-s', image_path # NOTE: Mac only :(
unless File.size(image_path) == 0
input ":imgur #{image_path}"
else
puts 'canceled'
end
end
command :imgur do |m|
require 'imgur2'
client = Imgur2.new config[:imgur][:api_key]
image_path = File.expand_path(m[1].gsub('\\', ''))
puts "uploading... #{image_path}".c(:info)
result = File.open(image_path, 'rb') { |f|
client.upload f
}
unless result["error"]
url = result["upload"]["links"]["original"]
puts "url: #{url}".c(:info)
message = ask "message: "
input "#{message} #{url}"
else
puts "[Error] #{result["error"]["message"]}".c(:notice)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment