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.



19
20
21
22
# File 'lib/hexapic/repository.rb', line 19

def initialize
  @instagram = API::Instagram.new(CLIENT_ID)
  puts 'Using Instagram'
end

Instance Method Details

#find_pictures(tag) ⇒ Object

Raises:



24
25
26
27
28
29
30
31
32
33
# File 'lib/hexapic/repository.rb', line 24

def find_pictures(tag)
  tag.delete(',')
  puts "Getting last images by tag #{tag}"
  pics = @instagram.search(tag).sample(COUNT).map do |r|
    Picture.new(r[:url], r[:link], r[:id])
  end

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

#find_pictures_by_username(username) ⇒ Object

Raises:



35
36
37
38
39
40
41
42
43
# File 'lib/hexapic/repository.rb', line 35

def find_pictures_by_username(username)
  puts "Getting last images from user #{username}"
  pics = @instagram.search_by_user(username).sample(COUNT).map do |r|
    Picture.new(r[:url], r[:link], r[:id])
  end

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