class Flico::FlickrCommand
Public Class Methods
new(search_command:, sizes_command:)
click to toggle source
# File lib/flico/flickr_command.rb, line 5 def initialize(search_command:, sizes_command:) @search_command = search_command @sizes_command = sizes_command end
setup(flickraw)
click to toggle source
# File lib/flico/flickr_command.rb, line 10 def self.setup(flickraw) new(search_command: SearchCommand.new(flickraw), sizes_command: SizesCommand.new(flickraw)) end
Public Instance Methods
call(keyword)
click to toggle source
# File lib/flico/flickr_command.rb, line 14 def call(keyword) unless keyword.nil? puts "Searching images for keyword: #{keyword}" results = @search_command.call(keyword) unless results.count == 0 get_image_url(results.first['id']) else STDERR.puts "No Image for keyword: #{keyword}" end else STDERR.puts "Missing Keywords (can't be nil)" end end
Private Instance Methods
get_image_url(photo_id)
click to toggle source
# File lib/flico/flickr_command.rb, line 30 def get_image_url(photo_id) sizes = @sizes_command.call(photo_id) mid = sizes.count / 2 sizes[mid]['source'] end