Class: Hexapic::Repository::FlickrRepository

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

Constant Summary collapse

API_KEY =
'bd053065ce6662cb4b2f4c0be2b65266'

Instance Method Summary collapse

Constructor Details

#initializeFlickrRepository

Returns a new instance of FlickrRepository.



49
50
51
52
# File 'lib/hexapic/repository.rb', line 49

def initialize
  @flickr = Flickr.new(api_key: API_KEY, verify_ssl: false)
  puts 'Using Flickr'
end

Instance Method Details

#find_pictures(tags) ⇒ Object

Raises:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hexapic/repository.rb', line 54

def find_pictures(tags)
  options = {}
  options[:tag_mode] = 'and'
  options[:tags] = tags
  options[:sort] = 'relevance'
  options[:content_type] = '1'
  options[:extras] = 'url_q,url_sq,url_s'
  puts "Getting last images by tags #{tags}"
  pics = @flickr.search(options).sample(COUNT).map do |photo|
    Picture.new(photo.source('Large Square'), photo.url, photo.filename)
  end

  raise ImagesNotFound.new("Found only #{pics.size} images. Need #{COUNT}.") if pics.size < COUNT 
  pics
end