Skip to content

Instantly share code, notes, and snippets.

@ilnurnasyrov2
Created February 6, 2018 16:45
Show Gist options
  • Save ilnurnasyrov2/7548ff56b3c0dff99cf79bf51193edb9 to your computer and use it in GitHub Desktop.
Save ilnurnasyrov2/7548ff56b3c0dff99cf79bf51193edb9 to your computer and use it in GitHub Desktop.
Sample of imgur api usage
require "httparty"
require "base64"
# Put there your client id
client_id = "..."
binary_file = IO.read("image.jpg");
base64_encoded_file = Base64.encode64(binary_file);
response = HTTParty.post(
"https://api.imgur.com/3/image",
headers: {
"Authorization" => "Client-ID #{client_id}"
},
body: {
image: base64_encoded_file
}
)
JSON.parse(response.body) #=>
# {"data"=>
# {"id"=>"iDZ0Q7R",
# "title"=>nil,
# "description"=>nil,
# "datetime"=>1517935328,
# "type"=>"image/jpeg",
# "animated"=>false,
# "width"=>240,
# "height"=>160,
# "size"=>21017,
# "views"=>0,
# "bandwidth"=>0,
# "vote"=>nil,
# "favorite"=>false,
# "nsfw"=>nil,
# "section"=>nil,
# "account_url"=>nil,
# "account_id"=>0,
# "is_ad"=>false,
# "in_most_viral"=>false,
# "has_sound"=>false,
# "tags"=>[],
# "ad_type"=>0,
# "ad_url"=>"",
# "in_gallery"=>false,
# "deletehash"=>"3ZXNFuzv9yKUz33",
# "name"=>"",
# "link"=>"https://i.imgur.com/iDZ0Q7R.jpg"},
# "success"=>true,
# "status"=>200}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment