Class: WGif::Uploader
- Inherits:
-
Object
- Object
- WGif::Uploader
- Defined in:
- lib/wgif/uploader.rb
Constant Summary collapse
- UPLOAD_ENDPOINT =
'https://api.imgur.com/3/image'
Instance Method Summary collapse
-
#initialize(client_id) ⇒ Uploader
constructor
A new instance of Uploader.
- #upload(filename) ⇒ Object
Constructor Details
#initialize(client_id) ⇒ Uploader
Returns a new instance of Uploader.
10 11 12 |
# File 'lib/wgif/uploader.rb', line 10 def initialize(client_id) @client_id = client_id end |
Instance Method Details
#upload(filename) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wgif/uploader.rb', line 14 def upload(filename) File.open(filename, 'r') do |file| response = Typhoeus.post(UPLOAD_ENDPOINT, body: { image: file }, headers: auth_header) if response.success? image_url(response) else fail WGif::ImgurException, (response) end end end |