Permalink
Browse files

Allow access to Photos from a Page.

  • Loading branch information...
1 parent cc3e1ed commit 8b7daa10239a425284a1e7010208ded1147d738a @kevintuhumury kevintuhumury committed Mar 19, 2012
Showing with 79 additions and 32 deletions.
  1. +25 −9 lib/cameraplus/page.rb
  2. +54 −23 spec/cameraplus/page_spec.rb
View
@@ -1,17 +1,33 @@
module Cameraplus
class Page
- attr_reader :url, :timestamp, :location, :location_name, :tweet_text, :tweet_id, :view_count, :comment_count
+ attr_reader :url, :timestamp, :location, :location_name, :tweet_text, :tweet_id, :view_count, :comment_count, :photos
def initialize(data)
- @url = data.url
- @timestamp = data.timestamp
- @location = data.location
- @location_name = data.locationname
- @tweet_text = data.tweettext
- @tweet_id = data.tweetid
- @view_count = data.views.to_i
- @comment_count = data.comments.to_i
+ @data = data
+ parse
+ end
+
+ private
+
+ def parse
+ parse_page
+ parse_photos
+ end
+
+ def parse_page
+ @url = @data.url
+ @timestamp = @data.timestamp
+ @location = @data.location
+ @location_name = @data.locationname
+ @tweet_text = @data.tweettext
+ @tweet_id = @data.tweetid.to_i
+ @view_count = @data.views
+ @comment_count = @data.comments.to_i
+ end
+
+ def parse_photos
+ @photos ||= @data.images.map { |image| Photo.new(image) }
end
end
@@ -12,42 +12,73 @@
comments: 1,
location: "45.43383498680353 12.34226474539595",
locationname: "Venice, Venice",
- images: []
+ images: [ photo ]
+ }
+ end
+
+ let(:photo) do
+ {
+ "800px" => "http:\/\/pics.campl.us\/f\/0\/0b497f01791c851db1a17f81e0621a5c.jpg",
+ "120px" => "http:\/\/pics.campl.us\/t\/0\/0b497f01791c851db1a17f81e0621a5c.jpg",
+ "480px" => "http:\/\/pics.campl.us\/iphone\/0\/0b497f01791c851db1a17f81e0621a5c.jpg",
+ :fullwidth => 800,
+ :fullheight => 590,
+ :location => "45.43383498680353 12.34226474539595"
}
end
subject { Cameraplus::Page.new(data) }
- it "has an url" do
- subject.url.should eq "http://campl.us/iao4"
- end
+ context "instance" do
- it "has a timestamp" do
- subject.timestamp.should eq "2012-03-14 22:53:49"
- end
+ it "has an url" do
+ subject.url.should eq "http://campl.us/iao4"
+ end
- it "has a location" do
- subject.location.should eq "45.43383498680353 12.34226474539595"
- end
+ it "has a timestamp" do
+ subject.timestamp.should eq "2012-03-14 22:53:49"
+ end
- it "has a location name" do
- subject.location_name.should eq "Venice, Venice"
- end
+ it "has a location" do
+ subject.location.should eq "45.43383498680353 12.34226474539595"
+ end
- it "has a tweet text" do
- subject.tweet_text.should eq "Carnival in Venice, a travel photographer''s dream shoot!"
- end
+ it "has a location name" do
+ subject.location_name.should eq "Venice, Venice"
+ end
- it "has a tweet id" do
- subject.tweet_id.should eq "180064216093437954"
- end
+ it "has a tweet text" do
+ subject.tweet_text.should eq "Carnival in Venice, a travel photographer''s dream shoot!"
+ end
+
+ it "has a tweet id" do
+ subject.tweet_id.should eq 180064216093437954
+ end
+
+ it "has a view count" do
+ subject.view_count.should eq 1951
+ end
+
+ it "has a comment count" do
+ subject.comment_count.should eq 1
+ end
- it "has a view count" do
- subject.view_count.should eq 1951
end
- it "has a comment count" do
- subject.comment_count.should eq 1
+ context "#photos" do
+
+ it "should be an Array" do
+ subject.photos.should be_an Array
+ end
+
+ it "should contain a Cameraplus::Photo" do
+ subject.photos.first.should be_a Cameraplus::Photo
+ end
+
+ it "should have one photo" do
+ subject.photos.size.should eq 1
+ end
+
end
end

0 comments on commit 8b7daa1

Please sign in to comment.