Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
cache all photos in class variable
Browse files Browse the repository at this point in the history
  • Loading branch information
himynameisjonas committed Jan 29, 2011
1 parent 9a3f0d8 commit 2d59f61
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/photo.rb
@@ -1,6 +1,7 @@
class Photo
attr_accessor :id, :thumbnail_url, :large_url, :index
require 'open-uri'
@@allphotos = nil

def initialize(attributes = {})
attributes.each do |name, value|
Expand All @@ -9,6 +10,7 @@ def initialize(attributes = {})
end

def self.all
return @@allphotos if @@allphotos
doc = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=c794c3f00be2130085e3cdef2f06aeb6&photoset_id=72157625847846478&extras=url_sq%2Curl_m%2Curl_l%2Curl_o"))
photos = Array.new
doc.css("photo").to_a.each_index do |index|
Expand All @@ -20,7 +22,7 @@ def self.all
:index => index
)
end
photos
@@allphotos = photos
end

def self.find(id)
Expand Down

0 comments on commit 2d59f61

Please sign in to comment.