Class: Flickr::PhotoCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/flickr.rb

Overview

A collection of photos is returned as a PhotoCollection, a subclass of Array. This allows us to retain the pagination info returned by Flickr and make it accessible in a friendly way

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(photos_api_response = {}, api_key = nil) ⇒ PhotoCollection

builds a PhotoCollection from given params, such as those returned from photos.search API call



227
228
229
230
231
232
# File 'lib/flickr.rb', line 227

def initialize(photos_api_response={}, api_key=nil)
  [ "page", "pages", "perpage", "total" ].each { |i| instance_variable_set("@#{i}", photos_api_response["photos"][i])} 
  collection = photos_api_response['photos']['photo'] || []
  collection = [collection] if collection.is_a? Hash
  collection.each { |photo| self << Photo.new(photo.delete('id'), api_key, photo) }
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



223
224
225
# File 'lib/flickr.rb', line 223

def page
  @page
end

#pagesObject (readonly)

Returns the value of attribute pages.



223
224
225
# File 'lib/flickr.rb', line 223

def pages
  @pages
end

#perpageObject (readonly)

Returns the value of attribute perpage.



223
224
225
# File 'lib/flickr.rb', line 223

def perpage
  @perpage
end

#totalObject (readonly)

Returns the value of attribute total.



223
224
225
# File 'lib/flickr.rb', line 223

def total
  @total
end