Class: Flickr::PhotoCollection
- Inherits:
-
Array
- Object
- Array
- Flickr::PhotoCollection
- 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
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#perpage ⇒ Object
readonly
Returns the value of attribute perpage.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(photos_api_response = {}, api_key = nil) ⇒ PhotoCollection
constructor
builds a PhotoCollection from given params, such as those returned from photos.search API call.
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. Note all the info is contained in the value of the first (and only) key-value pair of the response. The key will vary depending on the original object the photos are related to (e.g ‘photos’, ‘photoset’, etc)
234 235 236 237 238 239 240 |
# File 'lib/flickr.rb', line 234 def initialize(photos_api_response={}, api_key=nil) photos = photos_api_response.values.first [ "page", "pages", "perpage", "total" ].each { |i| instance_variable_set("@#{i}", photos[i])} collection = 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
#page ⇒ Object (readonly)
Returns the value of attribute page.
227 228 229 |
# File 'lib/flickr.rb', line 227 def page @page end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
227 228 229 |
# File 'lib/flickr.rb', line 227 def pages @pages end |
#perpage ⇒ Object (readonly)
Returns the value of attribute perpage.
227 228 229 |
# File 'lib/flickr.rb', line 227 def perpage @perpage end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
227 228 229 |
# File 'lib/flickr.rb', line 227 def total @total end |