Class: ImgurGateway

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename: nil, title: nil) ⇒ ImgurGateway

Returns a new instance of ImgurGateway.



7
8
9
10
# File 'lib/imgur_gateway.rb', line 7

def initialize(filename: nil, title: nil)
  @filename = filename
  @title = title || image_title
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



5
6
7
# File 'lib/imgur_gateway.rb', line 5

def filename
  @filename
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/imgur_gateway.rb', line 5

def title
  @title
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/imgur_gateway.rb', line 5

def url
  @url
end

Instance Method Details

#uploadObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/imgur_gateway.rb', line 12

def upload
  return false unless filename
  client = Imgur.new(imgur_api_key)
  image = Imgur::LocalImage.new(filename, title: title)
  uploaded = client.upload(image)
  @url = uploaded.link
rescue Exception => e
  puts "Error uploading to imgur #{e}"
  return false
end