Skip to content

Instantly share code, notes, and snippets.

@offby1
Created June 10, 2012 20:41
Show Gist options
  • Save offby1/2907248 to your computer and use it in GitHub Desktop.
Save offby1/2907248 to your computer and use it in GitHub Desktop.
require 'net/http'
class ImageShack
@@uri = URI.parse('http://imageshack.us/upload_api.php')
def upload
boundary = '---------------------------7d63bf2ef300f2'
post_data = []
post_data << boundary << "\r\n"
post_data << 'key=mykey\r\n'
post_data << "Content-Type: image/png\r\n"
post_data << File.read('/Users/erichanchrow/Dropbox/tmp/all-black.png')
post_data << "\r\n--#{boundary}--\r\n"
request = Net::HTTP::Post.new(@@uri.request_uri)
request.body = post_data.join
http = Net::HTTP.new(@@uri.host,@@uri.port)
response, data = http.request(request)
p response
p response.body
p data
end
end
ImageShack.new.upload
# #<Net::HTTPOK 200 OK readbody=true>
# "<links>\n<error id=\"auth_error\">You must provide a valid auth token or dev key. see http://code.google.com/p/imageshackapi/</error>\n</links>\n"
# nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment