Created
June 10, 2012 20:41
-
-
Save offby1/2907248 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
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