Class: Flico::ImageFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword) ⇒ ImageFile

Returns a new instance of ImageFile.



12
13
14
# File 'lib/flico/image_file.rb', line 12

def initialize(keyword)
  @keyword = keyword
end

Instance Attribute Details

#keywordObject

Returns the value of attribute keyword.



10
11
12
# File 'lib/flico/image_file.rb', line 10

def keyword
  @keyword
end

Instance Method Details

#fetch_from_flickrObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/flico/image_file.rb', line 16

def fetch_from_flickr
  Flickr::BaseApi.new.get_photo(keyword)
rescue NoImage => e
  puts "Image not found for keyword '#{keyword}'. Message: #{e.message}. Retrying"
  unless (tries -= 1).positive?
    raise ApplicationError, "Failed getting image after retrying #{MAX_KEYWORD_RETRIES} times"
  end

  retry
rescue FetchingError => e
  raise ApplicationError, e.message
end