-
-
Save sss/934603 to your computer and use it in GitHub Desktop.
earthquake.gem imgur command
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
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 | |
en |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment