Class: Hexapic::Repository::InstagramRepository

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

Constant Summary collapse

CLIENT_ID =
'417c3ee8c9544530b83aa1c24de2abb3'

Instance Method Summary collapse

Constructor Details

#initializeInstagramRepository

Returns a new instance of InstagramRepository.



22
23
24
25
# File 'lib/hexapic/repository.rb', line 22

def initialize
  @instagram = Instagram.client(client_id: CLIENT_ID)
  puts 'Using Instagram'
end

Instance Method Details

#find_pictures(tag) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/hexapic/repository.rb', line 27

def find_pictures(tag)
  tag = URI.encode(tag.split(',').first)
  puts "Getting last images by tag #{tag}"
  pics = @instagram.tag_recent_media(tag).sample(COUNT).map do |r|
    url = r.images.standard_resolution.url
    Picture.new(url, url, url.split('/').last)
  end

  raise ImagesNotFound.new("Found only #{pics.size} images. Need #{COUNT}.") if pics.size < COUNT 
  pics
rescue Exception => e
  raise NoInternet.new(e.message)
end