Class: FlickIt::KeywordsController

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

Instance Method Summary collapse

Constructor Details

#initializeKeywordsController

Returns a new instance of KeywordsController.



3
4
5
# File 'lib/keywords_controller.rb', line 3

def initialize
  @flickr_api = FlickrApi.new
end

Instance Method Details

#get_photos_for_keywordsObject

Gets keywords from command line and creates an array of images for the keywords. Fills the array with random key word if there are less than 10 words entered or replaces the word if a photo is not found



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/keywords_controller.rb', line 8

def get_photos_for_keywords
  keywords = ARGV.map do |keyword|
    puts "Getting photos for #{keyword}"
    photo_results = @flickr_api.get_flickr_search_result(keyword)
    if photo_results.nil?
      puts "No photos found for #{keyword}"
      photo_results = get_random_keyword_photos
    end
    photo_results.first
  end
  fill_keywords_array(keywords)
end