Class: Flickr::Photos::PhotoResponse
- Defined in:
- lib/flickr/photo_response.rb
Overview
wrapping class to hold a photos response from the flickr api
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
-
#method ⇒ Object
Returns the value of attribute method.
-
#options ⇒ Object
Returns the value of attribute options.
-
#page ⇒ Object
Returns the value of attribute page.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#photos ⇒ Object
Returns the value of attribute photos.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
-
#<<(photo) ⇒ Object
Add a Flickr::Photos::Photo object to the photos array.
-
#initialize(attributes) ⇒ PhotoResponse
constructor
creates an object to hold the search response.
-
#method_missing(method, *args, &block) ⇒ Object
passes all unknown request to the photos array if it responds to the method.
-
#next_page ⇒ Object
gets the next page from flickr if there are anymore pages in the current photos object.
-
#previous_page ⇒ Object
gets the previous page from flickr if there is a previous page in the current photos object.
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
#api ⇒ Object
Returns the value of attribute api.
4 5 6 |
# File 'lib/flickr/photo_response.rb', line 4 def api @api end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/flickr/photo_response.rb', line 4 def method @method end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/flickr/photo_response.rb', line 4 def @options end |
#page ⇒ Object
Returns the value of attribute page.
4 5 6 |
# File 'lib/flickr/photo_response.rb', line 4 def page @page end |
#pages ⇒ Object
Returns the value of attribute pages.
4 5 6 |
# File 'lib/flickr/photo_response.rb', line 4 def pages @pages end |
#per_page ⇒ Object
Returns the value of attribute per_page.
4 5 6 |
# File 'lib/flickr/photo_response.rb', line 4 def per_page @per_page end |
#photos ⇒ Object
Returns the value of attribute photos.
4 5 6 |
# File 'lib/flickr/photo_response.rb', line 4 def photos @photos end |
#total ⇒ Object
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_page ⇒ Object
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, .merge(:page => self.page.to_i + 1)) if self.page.to_i < self.pages.to_i end |
#previous_page ⇒ Object
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, .merge(:page => self.page.to_i - 1)) if self.page.to_i > 1 end |