Skip to content

Commit

Permalink
Allow access to the Pages of a User.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevintuhumury committed Mar 19, 2012
1 parent 8b7daa1 commit 3c581e5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
34 changes: 25 additions & 9 deletions lib/cameraplus/user.rb
@@ -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
Expand Down
18 changes: 17 additions & 1 deletion spec/cameraplus/user_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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.