Class: Flickr::Photos::PhotoResponse

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

Overview

wrapping class to hold a photos response from the flickr api

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ PhotoResponse

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
    


11
12
13
14
15
# File 'lib/flickr/photo_response.rb', line 11

def initialize(attributes)
  attributes.each do |k,v|
    send("#{k}=", v)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

passes all unknown request to the photos array if it responds to the method



34
35
36
# File 'lib/flickr/photo_response.rb', line 34

def method_missing(method, *args, &block)
  self.photos.respond_to?(method) ? self.photos.send(method, *args, &block) : super
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



4
5
6
# File 'lib/flickr/photo_response.rb', line 4

def api
  @api
end

#methodObject

Returns the value of attribute method.



4
5
6
# File 'lib/flickr/photo_response.rb', line 4

def method
  @method
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/flickr/photo_response.rb', line 4

def options
  @options
end

#pageObject

Returns the value of attribute page.



4
5
6
# File 'lib/flickr/photo_response.rb', line 4

def page
  @page
end

#pagesObject

Returns the value of attribute pages.



4
5
6
# File 'lib/flickr/photo_response.rb', line 4

def pages
  @pages
end

#per_pageObject

Returns the value of attribute per_page.



4
5
6
# File 'lib/flickr/photo_response.rb', line 4

def per_page
  @per_page
end

#photosObject

Returns the value of attribute photos.



4
5
6
# File 'lib/flickr/photo_response.rb', line 4

def photos
  @photos
end

#totalObject

Returns the value of attribute total.



4
5
6
# File 'lib/flickr/photo_response.rb', line 4

def total
  @total
end

Instance Method Details

#<<(photo) ⇒ Object

Add a Flickr::Photos::Photo object to the photos array. It does nothing if you pass a non photo object



18
19
20
21
# File 'lib/flickr/photo_response.rb', line 18

def <<(photo)
  self.photos ||= []
  self.photos << photo if photo.is_a?(Flickr::Photos::Photo)
end

#next_pageObject

gets the next page from flickr if there are anymore pages in the current photos object



24
25
26
# File 'lib/flickr/photo_response.rb', line 24

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

#previous_pageObject

gets the previous page from flickr if there is a previous page in the current photos object



29
30
31
# File 'lib/flickr/photo_response.rb', line 29

def previous_page
  api.send(self.method, options.merge(:page => self.page.to_i - 1)) if self.page.to_i > 1
end