Class: Flico::FlickrCommand

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_command:, sizes_command:) ⇒ FlickrCommand

Returns a new instance of FlickrCommand.



5
6
7
8
# File 'lib/flico/flickr_command.rb', line 5

def initialize(search_command:, sizes_command:)
  @search_command = search_command
  @sizes_command = sizes_command
end

Class Method Details

.setup(flickraw) ⇒ Object



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

def self.setup(flickraw)
  new(search_command: SearchCommand.new(flickraw), sizes_command: SizesCommand.new(flickraw))
end

Instance Method Details

#call(keyword) ⇒ Object



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

def call(keyword)
  if keyword.nil?
    warn "Missing Keywords (can't be nil)"
  else
    puts "Searching images for keyword: #{keyword}"
    results = @search_command.call(keyword)
    if results.count.zero?
      warn "No Image for keyword: #{keyword}"
    else
      get_image_url(results.first['id'])
    end
  end
end