Permalink
Browse files

Allow access to the Pages of a User.

  • Loading branch information...
1 parent 8b7daa1 commit 3c581e50cc73294fbba0cb184907ca9013d2a07b @kevintuhumury kevintuhumury committed Mar 19, 2012
Showing with 42 additions and 10 deletions.
  1. +25 −9 lib/cameraplus/user.rb
  2. +17 −1 spec/cameraplus/user_spec.rb
View
@@ -1,19 +1,35 @@
module Cameraplus
class User
- attr_reader :id, :username, :name, :avatar, :page_count, :photo_count
+ attr_reader :id, :username, :name, :avatar, :page_count, :photo_count, :pages
+
+ def self.find(identifier, options = {})
+ new Cameraplus::API::User.find(identifier, options)
+ end
def initialize(data)
- @id = data.user.userid.to_i
- @username = data.user.username
- @name = data.user.realname
- @avatar = data.user.avatar
- @page_count = data.user.pages.to_i
- @photo_count = data.user.pictures.to_i
+ @data = data
+ parse
end
- def self.find(identifier, options = {})
- new Cameraplus::API::User.find(identifier, options)
+ private
+
+ def parse
+ parse_user
+ parse_pages
+ end
+
+ def parse_user
+ @id = @data.user.userid.to_i
+ @username = @data.user.username
+ @name = @data.user.realname
+ @avatar = @data.user.avatar
+ @page_count = @data.user.pages.to_i
+ @photo_count = @data.user.pictures.to_i
+ end
+
+ def parse_pages
+ @pages ||= @data.pages.map { |page| Page.new(page) }
end
end
@@ -7,7 +7,7 @@
let(:user) { Cameraplus::User.find "mostlylisa" }
it "should be a User" do
- user.class.should eq Cameraplus::User
+ user.should be_a Cameraplus::User
end
context ".find" do
@@ -38,4 +38,20 @@
end
+ context "#pages" do
+
+ it "should be an Array" do
+ user.pages.should be_a Array
+ end
+
+ it "should contain a Cameraplus::Page" do
+ user.pages.first.should be_a Cameraplus::Page
+ end
+
+ it "should have one page" do
+ user.pages.size.should eq 1
+ end
+
+ end
+
end

0 comments on commit 3c581e5

Please sign in to comment.