Class: Flickr::PhotoSet

Inherits:
Base
  • Object
show all
Defined in:
lib/flickr-wrapper/photoset.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#user_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#sets

Constructor Details

#initialize(id, title, description, photo_count) ⇒ PhotoSet

Returns a new instance of PhotoSet.



4
5
6
# File 'lib/flickr-wrapper/photoset.rb', line 4

def initialize id, title, description, photo_count
  @id, @title, @description, @photo_count = id, title, description, photo_count
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/flickr-wrapper/photoset.rb', line 2

def description
  @description
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/flickr-wrapper/photoset.rb', line 2

def id
  @id
end

#photo_countObject

Returns the value of attribute photo_count.



2
3
4
# File 'lib/flickr-wrapper/photoset.rb', line 2

def photo_count
  @photo_count
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/flickr-wrapper/photoset.rb', line 2

def title
  @title
end

Class Method Details

.find(user_id, id) ⇒ Object

Get information regarding set by searching with the set’s ID



15
16
17
18
19
20
21
22
# File 'lib/flickr-wrapper/photoset.rb', line 15

def self.find user_id, id
  # Keep scope of the user that made the call
  @user_id = user_id
  
  query = Flickr::Query.new(@user_id).execute('flickr.photosets.getInfo', :photoset_id => id)
  # Find should return a single entity
  parse(query).first
end

.list(user_id) ⇒ Object

Class methods require scope of the user, it is to be sent into the method



9
10
11
12
# File 'lib/flickr-wrapper/photoset.rb', line 9

def self.list user_id
  query = Flickr::Query.new user_id
  parse(query.execute('flickr.photosets.getList'))
end

Instance Method Details

#machine_tagsObject

Return a list of machine_tags for the set Queries: > photosets.getPhotos (1 call) > Photo.find ID (n calls)



52
53
54
55
56
57
58
59
60
# File 'lib/flickr-wrapper/photoset.rb', line 52

def machine_tags
  tags = []
  photos.each do |photo|
    photo.machine_tags.each do |tag|
      tags << tag
    end
  end
  tags.uniq
end

#photosObject

Get the photos within a set Queries: > photosets.getPhotos (1 call) > Photo.find ID (n calls)



28
29
30
31
32
# File 'lib/flickr-wrapper/photoset.rb', line 28

def photos
  return (Flickr::Query.new(user_id).execute('flickr.photosets.getPhotos', :photoset_id => id)/:photo).parallel_map(Flickr::MAX_THREADS) do |photo|
    Flickr::Photo.find user_id, photo[:id]
  end
end

#similarObject

Search for photosets that have similar tags



63
64
65
66
67
68
69
# File 'lib/flickr-wrapper/photoset.rb', line 63

def similar
  sets = []
  Flickr::PhotoSet.list(user_id).each do |set|
    sets << set unless (self.tags & set.tags).empty? or set == self
  end
  sets.uniq
end

#tagsObject

Return a list of tags for the set Queries: > photosets.getPhotos (1 call) > Photo.find ID (n calls)



38
39
40
41
42
43
44
45
46
# File 'lib/flickr-wrapper/photoset.rb', line 38

def tags
  tags = []
  photos.each do |photo|
    photo.tags.each do |tag|
      tags << tag.value
    end
  end
  tags.uniq
end