Class: Imgur::API
Imgur API interface
Constructor Summary
Creates a new Imgur API instance
27 28 29 |
# File 'lib/imgur.rb', line 27 def initialize api_key @api_key = api_key end |
Public Visibility
Public Instance Method Summary
#delete(image_hash) |
Deletes the image with the specified delete hash. Returns: Boolean |
---|---|
#gallery(params = {}) |
Returns a set of images in gallery format based on your specifications. Returns: Array<Hash> |
#image_stats(image_hash) |
Returns statistics for a specific image, like size, type, and bandwidth usage. Returns: Hash |
#upload_file(image_filename) |
Uploads an image from local disk. Returns: Hash |
#upload_from_url(image_url) |
Uploads a file from a remote URL. Returns: Hash |
Public Instance Method Details
delete
Deletes the image with the specified delete hash. Delete hashes are not the same as image hashes, they are two separate hashes.
94 95 96 97 98 99 |
# File 'lib/imgur.rb', line 94 def delete image_hash c = Curl::Easy.new("http://imgur.com/api/delete/#{image_hash}.json?key=#{@api_key}") c.http_get response = Crack::JSON.parse c.body_str response["rsp"]["stat"] == "ok" end |
gallery
Returns a set of images in gallery format based on your specifications
67 |
# File 'lib/imgur.rb', line 67 def gallery params = {} |
image_stats
Returns statistics for a specific image, like size, type, and bandwidth usage
81 82 83 84 85 86 87 |
# File 'lib/imgur.rb', line 81 def image_stats image_hash c = Curl::Easy.new("http://imgur.com/api/stats/#{image_hash}.json") c.http_get response = Crack::JSON.parse c.body_str raise ImgurError, response["error"]["error_msg"] if response.key?("error") response["stats"] end |
upload_file
Uploads an image from local disk
36 37 38 39 40 41 42 43 |
# File 'lib/imgur.rb', line 36 def upload_file image_filename c = Curl::Easy.new("http://imgur.com/api/upload.json") c.multipart_form_post = true c.http_post(Curl::PostField.content('key', @api_key), Curl::PostField.file('image', image_filename)) response = Crack::JSON.parse c.body_str raise ImgurError, response["rsp"]["error_msg"] if response["rsp"]["stat"] == "fail" response["rsp"]["image"] end |
upload_from_url
Uploads a file from a remote URL
50 51 52 53 54 55 56 |
# File 'lib/imgur.rb', line 50 def upload_from_url image_url c = Curl::Easy.new("http://imgur.com/api/upload.json") c.http_post(Curl::PostField.content('key', @api_key), Curl::PostField.content('image', image_url)) response = Crack::JSON.parse c.body_str raise ImgurError, response["rsp"]["error_msg"] if response["rsp"]["stat"] == "fail" response["rsp"]["image"] end |