Class: WGif::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/wgif/uploader.rb

Constant Summary collapse

UPLOAD_ENDPOINT =
'https://api.imgur.com/3/image'

Instance Method Summary collapse

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, error_message(response)
    end
  end
end