discourse/lib/imgur.rb

25 lines
626 B
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
require 'rest_client'
require 'image_size'
module Imgur
def self.upload_file(file)
blob = file.read
response = RestClient.post(SiteSetting.imgur_endpoint, key: SiteSetting.imgur_api_key, image: Base64.encode64(blob))
json = JSON.parse(response.body)['upload'] rescue nil
return nil if json.blank?
# Resize the image
json['image']['width'], json['image']['height'] = ImageSizer.resize(json['image']['width'], json['image']['height'])
2013-02-25 11:42:20 -05:00
{url: json['links']['original'],
2013-02-05 14:16:51 -05:00
filesize: json['image']['size'],
width: json['image']['width'],
height: json['image']['height']}
end
end