Sha256: c095f629b8a109b44158bbb8683633b7bc97f70f40c4ce7f52854687f26f69d4

Contents?: true

Size: 1.3 KB

Versions: 42

Compression:

Stored size: 1.3 KB

Contents

# wrapping class to hold a photos response from the flickr api
#
class Flickr::Photos::PhotoResponse
  attr_accessor :page, :pages, :per_page, :total, :photos, :api, :method, :options
  
  # creates an object to hold the search response.
  # 
  # Params
  # * attributes (Required)
  #     a hash of attributes used to set the initial values of the response object
  def initialize(attributes)
    attributes.each do |k,v|
      send("#{k}=", v)
    end
  end

  # Add a Flickr::Photos::Photo object to the photos array.  It does nothing if you pass a non photo object
  def <<(photo)
    self.photos ||= []
    self.photos << photo if photo.is_a?(Flickr::Photos::Photo)
  end

  # gets the next page from flickr if there are anymore pages in the current photos object
  def next_page
    api.send(self.method, options.merge(:page => self.page.to_i + 1)) if self.page.to_i < self.pages.to_i
  end

  # gets the previous page from flickr if there is a previous page in the current photos object
  def previous_page
    api.send(self.method, options.merge(:page => self.page.to_i - 1)) if self.page.to_i > 1
  end
  
  # passes all unknown request to the photos array if it responds to the method
  def method_missing(method, *args, &block)
    self.photos.respond_to?(method) ? self.photos.send(method, *args, &block) : super
  end
end

Version data entries

42 entries across 42 versions & 13 rubygems

Version Path
flickr_fu-0.3.4 lib/flickr/photo_response.rb
flickr_fu-0.3.3 lib/flickr/photo_response.rb
ayn-flickr_fu-0.3.5 lib/flickr/photo_response.rb
ayn-flickr_fu-0.3.6 lib/flickr/photo_response.rb
ayn-flickr_fu-0.3.7 lib/flickr/photo_response.rb
ayn-flickr_fu-0.3.9 lib/flickr/photo_response.rb
commonthread-flickr_fu-0.1.6 lib/flickr/photo_response.rb
commonthread-flickr_fu-0.2.0 lib/flickr/photo_response.rb
commonthread-flickr_fu-0.2.1 lib/flickr/photo_response.rb
commonthread-flickr_fu-0.2.2 lib/flickr/photo_response.rb
commonthread-flickr_fu-0.3.0 lib/flickr/photo_response.rb
maciej-flickr_fu-0.3.0 lib/flickr/photo_response.rb
rmm5t-flickr_fu-0.3.1 lib/flickr/photo_response.rb
rschenk-flickr_fu-0.3.2 lib/flickr/photo_response.rb
thewebfellas-flickr_fu-0.1.6 lib/flickr/photo_response.rb
fotonauts-flickr_fu-0.3.13 lib/flickr/photo_response.rb
fotonauts-flickr_fu-0.3.11 lib/flickr/photo_response.rb
fotonauts-flickr_fu-0.3.10 lib/flickr/photo_response.rb
fotonauts-flickr_fu-0.3.9 lib/flickr/photo_response.rb
fotonauts-flickr_fu-0.3.8 lib/flickr/photo_response.rb