-
-
Save jmcarthur/396266 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
require "net/http" | |
require "uri" | |
require "json" | |
require "base64" | |
class Imgur | |
API_KEY = "15a6efd29935f62ea87579a8325d945a" | |
def self.upload(file_name) | |
url = URI::parse 'http://imgur.com/' | |
img = Base64.encode64 File.read(file_name) | |
req = Net::HTTP::Post.new('/api/upload.json') | |
req.set_form_data :key => API_KEY , :image => img | |
response,body = Net::HTTP::start(url.host,url.port) do |http| | |
http.request(req) | |
end | |
puts JSON[body]['rsp']['image']['imgur_page'] | |
end | |
end | |
if ARGV.first == nil | |
puts "Usage: #{$0} [filename]" | |
exit 1 | |
end | |
Imgur.upload ARGV.first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment