Skip to content
Browse files

Added the Cameraplus::PageMetadata class.

  • Loading branch information...
1 parent 726b08b commit 2310f370500e12d0d347694f81deb4c6926050e0 @kevintuhumury kevintuhumury committed
Showing with 191 additions and 0 deletions.
  1. +1 −0 lib/cameraplus.rb
  2. +73 −0 lib/cameraplus/page_metadata.rb
  3. +117 −0 spec/cameraplus/page_metadata_spec.rb
View
1 lib/cameraplus.rb
@@ -6,6 +6,7 @@
require "cameraplus/api/page"
require "cameraplus/user"
+require "cameraplus/page_metadata"
require "cameraplus/page"
require "cameraplus/photo"
require "cameraplus/photo_exif"
View
73 lib/cameraplus/page_metadata.rb
@@ -0,0 +1,73 @@
+module Cameraplus
+ class PageMetadata
+
+ attr_reader :url, :created_at, :location, :location_name, :tweet_text, :tweet_id, :view_count, :comment_count, :user, :photos, :comments
+
+ def self.find(identifier, options = {})
+ new Cameraplus::API::Page.find(identifier, options), identifier
+ end
+
+ def initialize(data, identifier)
+ @data = data
+ @identifier = identifier
+ parse
+ end
+
+ private
+
+ def parse
+ parse_metadata
+ parse_user
+ parse_photos
+ parse_comments
+ end
+
+ def parse_metadata
+ @url = parsed_url
+ @created_at = parsed_created_at
+ @location = parsed_location
+ @location_name = parsed_location_name
+ @tweet_text = @data.page.tweet.text
+ @tweet_id = @data.page.tweet.id.to_i
+ @view_count = @data.page.views
+ @comment_count = @data.page.comments.to_i
+ end
+
+ def parse_user
+ @user ||= Cameraplus::User.new(user: @data.page.tweet)
+ end
+
+ def parse_photos
+ @photos ||= @data.pictures.map { |photo| Photo.new photo }
+ end
+
+ def parse_comments
+ @comments ||= @data.comments.map { |comment| Comment.new comment }
+ end
+
+ def parsed_url
+ "#{Cameraplus::API::Request.base_uri}/#{@identifier}"
+ end
+
+ def parsed_created_at
+ DateTime.parse @data.page.timestamp if has_timestamp?
+ end
+
+ def parsed_location
+ @data.page.location.coords if has_location?
+ end
+
+ def parsed_location_name
+ @data.page.location.name if has_location?
+ end
+
+ def has_timestamp?
+ @data.page.has_key? "timestamp"
+ end
+
+ def has_location?
+ @data.page.has_key? "location"
+ end
+
+ end
+end
View
117 spec/cameraplus/page_metadata_spec.rb
@@ -0,0 +1,117 @@
+require "spec_helper"
+
+describe Cameraplus::PageMetadata do
+
+ use_vcr_cassette :page
+
+ subject { Cameraplus::PageMetadata.find "b72Z" }
+
+ it "should be a Page" do
+ subject.should be_a Cameraplus::PageMetadata
+ end
+
+ context ".find" do
+
+ it "finds the url of the specified page" do
+ subject.url.should eq "http://camerapl.us/b72Z"
+ end
+
+ it "finds the created at datetime of the specified page" do
+ subject.created_at.should eq DateTime.parse("2011-07-01 21:50:40")
+ end
+
+ it "finds the location of the specified page" do
+ subject.location.should eq "42.574017 18.641312"
+ end
+
+ it "finds the location name of the specified page" do
+ subject.location_name.should eq "Kotor, Montenegro"
+ end
+
+ it "finds the tweet text of the specified page" do
+ subject.tweet_text.should eq "Tiny Town of Kotor, Montenegro #mybestphoto"
+ end
+
+ it "finds the tweet id of the specified page" do
+ subject.tweet_id.should eq 86914646237384704
+ end
+
+ it "finds the view count of the specified page" do
+ subject.view_count.should eq 925
+ end
+
+ it "finds the comment count of the specified page" do
+ subject.comment_count.should eq 6
+ end
+
+ end
+
+ context "#user" do
+
+ it "should be a User" do
+ subject.user.should be_a Cameraplus::User
+ end
+
+ it "has an username" do
+ subject.user.username.should eq "lucyk"
+ end
+
+ it "has a name" do
+ subject.user.name.should eq "Oleg Lutsenko"
+ end
+
+ end
+
+ 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
+
+ context "with a Cameraplus::Photo" do
+
+ it "should have recipes" do
+ subject.photos.first.recipes.should be_an Array
+ end
+
+ it "should contain a Cameraplus::PhotoRecipe" do
+ subject.photos.first.recipes.first.should be_a Cameraplus::PhotoRecipe
+ end
+
+ it "should have exif data" do
+ subject.photos.last.exif.should be_an Array
+ end
+
+ it "should contain a Cameraplus::PhotoExif" do
+ subject.photos.first.exif.first.should be_a Cameraplus::PhotoExif
+ end
+
+ end
+
+ end
+
+ context "#comments" do
+
+ it "should be an Array" do
+ subject.comments.should be_an Array
+ end
+
+ it "should contain a Cameraplus::Comment" do
+ subject.comments.first.should be_a Cameraplus::Comment
+ end
+
+ it "should know the number of comments" do
+ subject.comments.size.should eq 6
+ end
+
+ it "should know the authors of the comments" do
+ subject.comments.map(&:author).should eq ["Lisa Bettany", "Oleg Lutsenko", "Oliver Penack", "John Goundry \u2714", "Jason Hansen", "Jonathan Feuer"]
+ end
+
+ end
+
+end

0 comments on commit 2310f37

Please sign in to comment.
Something went wrong with that request. Please try again.