Permalink
Browse files

oops. add some files

  • Loading branch information...
1 parent e74c27b commit 3dffcbce669171481c7dd6482bd907d157ee828f Tim Riley committed May 10, 2008
Showing with 180 additions and 112 deletions.
  1. +6 −0 .gitignore
  2. +75 −0 app/models/flickr_photo.rb
  3. 0 log/.gitignore
  4. +99 −0 spec/models/flickr_photo_spec.rb
  5. +0 −112 spec/models/photo_spec.rb
View
@@ -0,0 +1,6 @@
+log/*.log
+tmp/**/*
+.DS_Store
+doc/api
+doc/app
+coverage
View
@@ -0,0 +1,75 @@
+class FlickrPhoto
+
+ attr_accessor :id
+
+ def initialize(id)
+ @id = id
+ end
+
+ def attributes
+ @attributes ||= get_attributes
+ end
+
+ def attributes=(attrs)
+ # FIXME there must be a better way to do this.
+ @attributes = attrs
+ end
+
+ def title
+ attributes[:title]
+ end
+ def description
+ attributes[:description]
+ end
+ def taken_at
+ attributes[:taken_at]
+ end
+ def updated_at
+ attributes[:updated_at]
+ end
+ def thumb_source_url
+ attributes[:thumb_source_url]
+ end
+ def medium_source_url
+ attributes[:medium_source_url]
+ end
+ def fullsize_source_url
+ attributes[:fullsize_source_url]
+ end
+
+ # FIXME this will have to return an array of FlickrPhoto objects now.
+ def self.find_all_by_user_and_tag(user_nsid, tag)
+ flickr.photos.search(:user_id => user_nsid, :tags => tag, :extras => 'last_update').collect { |photo| [photo.id, photo.lastupdate] }
+ end
+
+ protected
+
+ def get_attributes
+ attrs = {}
+
+ info = flickr.photos.getInfo(:photo_id => @id)
+ urls = flickr.photos.getSizes(:photo_id => @id)
+
+ attrs[:title] = info.title
+ attrs[:description] = info.description
+ attrs[:taken_at] = info.dates.taken ? Time.parse(info.dates.taken) : nil # not everything has exif data
+ attrs[:flickr_updated_at] = info.dates.lastupdate
+
+ urls.each do |u|
+ case u.label
+ when 'Thumbnail':
+ attrs[:thumb_source_url] = fix_url(u.source)
+ when 'Medium':
+ attrs[:medium_source_url] = fix_url(u.source)
+ when 'Original':
+ attrs[:fullsize_source_url] = fix_url(u.source)
+ end
+ end
+
+ attrs
+ end
+
+ def fix_url(str)
+ str.gsub('\\','').gsub('http: ', 'http:')
+ end
+end
View
No changes.
@@ -0,0 +1,99 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe FlickrPhoto do
+
+end
+
+#
+# describe "class method" do
+#
+# describe "new_from_flickr" do
+#
+# describe "when photo found" do
+#
+# before(:each) do
+# @flickr_photo = mock(FlickRaw::Response)
+# @flickr_photo.stub!(:id).and_return('325946210')
+# @flickr_photo.stub!(:title).and_return("Last time's the charm")
+# @flickr_photo.stub!(:description).and_return("I hunkered down every night in the library for four weeks to write my last essay.")
+# flickr_photo_dates = mock(FlickRaw::Response)
+# flickr_photo_dates.stub!(:taken).and_return("2006-11-12 15: 05: 00")
+# @flickr_photo.stub!(:dates).and_return(flickr_photo_dates)
+#
+# @thumb_url = mock(FlickRaw::Response)
+# @thumb_url.stub!(:label).and_return('Thumbnail')
+# @thumb_url.stub!(:source).and_return("http://farm1.static.flickr.com/134/325946210_3d6af571cb_t.jpg")
+# @medium_url = mock(FlickRaw::Response)
+# @medium_url.stub!(:label).and_return('Medium')
+# @medium_url.stub!(:source).and_return("http://farm1.static.flickr.com/134/325946210_3d6af571cb.jpg")
+# @fullsize_url = mock(FlickRaw::Response)
+# @fullsize_url.stub!(:label).and_return('Original')
+# @fullsize_url.stub!(:source).and_return("http://farm1.static.flickr.com/134/325946210_3d6af571cb_o.jpg")
+#
+# @flickr_photo_urls = [@thumb_url, @medium_url, @fullsize_url]
+# end
+#
+# it "should create a photo object with title matching the flickr photo's title" do
+# flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
+# flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
+# Photo.new_from_flickr(@flickr_photo.id).title.should == @flickr_photo.title
+# end
+#
+# it "should create a photo object with description matching the flickr photo's description" do
+# flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
+# flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
+# Photo.new_from_flickr(@flickr_photo.id).description.should == @flickr_photo.description
+# end
+#
+# it "should have a taken_at date that matches the response from flickr" do
+# flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
+# flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
+# Photo.new_from_flickr(@flickr_photo.id).taken_at.to_s.should == Time.parse(@flickr_photo.dates.taken).to_s
+# end
+#
+# it "should have a thumb source url that matches the flickr photo" do
+# flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
+# flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
+# Photo.new_from_flickr(@flickr_photo.id).thumb_source_url.should == @thumb_url.source
+# end
+#
+# it "should have a medium source url that matches the flickr photo" do
+# flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
+# flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
+# Photo.new_from_flickr(@flickr_photo.id).medium_source_url.should == @medium_url.source
+# end
+#
+# it "should have a thumb source url that matches the flickr photo" do
+# flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
+# flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
+# Photo.new_from_flickr(@flickr_photo.id).fullsize_source_url.should == @fullsize_url.source
+# end
+#
+# end
+#
+#
+# describe "when photo not found" do
+# it "should raise a photo not found exception" do
+# flickr.photos.should_receive(:getInfo).with(:photo_id => 'badid').and_raise(FlickRaw::FailedResponse.new('Photo "badid" not found (invalid ID)', '1', 'flickr.photos.getInfo'))
+# lambda{
+# Photo.new_from_flickr('badid')
+# }.should raise_error(FlickRaw::FailedResponse)
+# end
+# end
+# end
+#
+# describe "search_flickr_by_user_and_tag" do
+# it "should return an empty array if no photos are found with the tag" do
+# flickr.photos.should_receive(:search).with(:user_id => '24905543@N00', :tags => 'study').and_return([])
+# Photo.search_flickr_by_user_and_tag('24905543@N00', 'study').should == []
+# end
+#
+# it "should return an array of ids for the user's photos with the tag" do
+# flickr_photo_1 = mock(FlickRaw::Response)
+# flickr_photo_1.stub!(:id).and_return('325946210')
+# flickr_photo_2 = mock(FlickRaw::Response)
+# flickr_photo_2.stub!(:id).and_return('282010363')
+# flickr.photos.should_receive(:search).with(:user_id => '24905543@N00', :tags => 'study').and_return([flickr_photo_1, flickr_photo_2])
+# Photo.search_flickr_by_user_and_tag('24905543@N00', 'study').should == [flickr_photo_1.id, flickr_photo_2.id]
+# end
+# end
View
@@ -129,116 +129,4 @@ def valid_flickr_photo_attributes
it_should_behave_like "a photo matching a flickr photo"
end
end
- #
- # describe "class method" do
- #
- # describe "new_from_flickr" do
- #
- # describe "when photo found" do
- #
- # before(:each) do
- # @flickr_photo = mock(FlickRaw::Response)
- # @flickr_photo.stub!(:id).and_return('325946210')
- # @flickr_photo.stub!(:title).and_return("Last time's the charm")
- # @flickr_photo.stub!(:description).and_return("I hunkered down every night in the library for four weeks to write my last essay.")
- # flickr_photo_dates = mock(FlickRaw::Response)
- # flickr_photo_dates.stub!(:taken).and_return("2006-11-12 15: 05: 00")
- # @flickr_photo.stub!(:dates).and_return(flickr_photo_dates)
- #
- # @thumb_url = mock(FlickRaw::Response)
- # @thumb_url.stub!(:label).and_return('Thumbnail')
- # @thumb_url.stub!(:source).and_return("http://farm1.static.flickr.com/134/325946210_3d6af571cb_t.jpg")
- # @medium_url = mock(FlickRaw::Response)
- # @medium_url.stub!(:label).and_return('Medium')
- # @medium_url.stub!(:source).and_return("http://farm1.static.flickr.com/134/325946210_3d6af571cb.jpg")
- # @fullsize_url = mock(FlickRaw::Response)
- # @fullsize_url.stub!(:label).and_return('Original')
- # @fullsize_url.stub!(:source).and_return("http://farm1.static.flickr.com/134/325946210_3d6af571cb_o.jpg")
- #
- # @flickr_photo_urls = [@thumb_url, @medium_url, @fullsize_url]
- # end
- #
- # it "should create a photo object with title matching the flickr photo's title" do
- # flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
- # flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
- # Photo.new_from_flickr(@flickr_photo.id).title.should == @flickr_photo.title
- # end
- #
- # it "should create a photo object with description matching the flickr photo's description" do
- # flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
- # flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
- # Photo.new_from_flickr(@flickr_photo.id).description.should == @flickr_photo.description
- # end
- #
- # it "should have a taken_at date that matches the response from flickr" do
- # flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
- # flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
- # Photo.new_from_flickr(@flickr_photo.id).taken_at.to_s.should == Time.parse(@flickr_photo.dates.taken).to_s
- # end
- #
- # it "should have a thumb source url that matches the flickr photo" do
- # flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
- # flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
- # Photo.new_from_flickr(@flickr_photo.id).thumb_source_url.should == @thumb_url.source
- # end
- #
- # it "should have a medium source url that matches the flickr photo" do
- # flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
- # flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
- # Photo.new_from_flickr(@flickr_photo.id).medium_source_url.should == @medium_url.source
- # end
- #
- # it "should have a thumb source url that matches the flickr photo" do
- # flickr.photos.should_receive(:getInfo).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo)
- # flickr.photos.should_receive(:getSizes).with(:photo_id => @flickr_photo.id).and_return(@flickr_photo_urls)
- # Photo.new_from_flickr(@flickr_photo.id).fullsize_source_url.should == @fullsize_url.source
- # end
- #
- # end
- #
- #
- # describe "when photo not found" do
- # it "should raise a photo not found exception" do
- # flickr.photos.should_receive(:getInfo).with(:photo_id => 'badid').and_raise(FlickRaw::FailedResponse.new('Photo "badid" not found (invalid ID)', '1', 'flickr.photos.getInfo'))
- # lambda{
- # Photo.new_from_flickr('badid')
- # }.should raise_error(FlickRaw::FailedResponse)
- # end
- # end
- # end
- #
- # describe "search_flickr_by_user_and_tag" do
- # it "should return an empty array if no photos are found with the tag" do
- # flickr.photos.should_receive(:search).with(:user_id => '24905543@N00', :tags => 'study').and_return([])
- # Photo.search_flickr_by_user_and_tag('24905543@N00', 'study').should == []
- # end
- #
- # it "should return an array of ids for the user's photos with the tag" do
- # flickr_photo_1 = mock(FlickRaw::Response)
- # flickr_photo_1.stub!(:id).and_return('325946210')
- # flickr_photo_2 = mock(FlickRaw::Response)
- # flickr_photo_2.stub!(:id).and_return('282010363')
- # flickr.photos.should_receive(:search).with(:user_id => '24905543@N00', :tags => 'study').and_return([flickr_photo_1, flickr_photo_2])
- # Photo.search_flickr_by_user_and_tag('24905543@N00', 'study').should == [flickr_photo_1.id, flickr_photo_2.id]
- # end
- # end
- #
- # describe "import_by_user_and_tag" do
- # it "should raise an argument exception if tag is not passed" do
- #
- # end
- #
- # it "should raise an argument exception if user NSID is not passed" do
- #
- # end
- #
- # it "should do nothing if all the returned photos have already been imported" do
- #
- # end
- #
- # it "should create photo objects for any photos that are not already imported" do
- #
- # end
- # end
- # end
end

0 comments on commit 3dffcbc

Please sign in to comment.