Skip to content

Commit

Permalink
Support for new dashboard counter APIs, removed logger from fb_connec…
Browse files Browse the repository at this point in the history
…t.rb
  • Loading branch information
Raphomet authored and mmangino committed Feb 25, 2010
1 parent ce602e0 commit 59b356f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
21 changes: 21 additions & 0 deletions lib/facebooker/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,27 @@ def to_i
def to_s
id.to_s
end


### NEW DASHBOARD API STUFF

def dashboard_count
session.post('facebook.dashboard.getCount', { :uid => uid })
end

def dashboard_count=(new_count)
session.post('facebook.dashboard.setCount', { :uid => uid, :count => new_count })
end

def dashboard_increment_count
session.post('facebook.dashboard.incrementCount', { :uid => uid })
end

def dashboard_decrement_count
session.post('facebook.dashboard.decrementCount', { :uid => uid })
end



##
# Two Facebooker::User objects should be considered equal if their Facebook ids are equal
Expand Down
30 changes: 29 additions & 1 deletion lib/facebooker/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,30 @@ def self.process(data)
end
end

class DashboardGetCount < Parser
def self.process(data)
element('dashboard_getCount_response', data).content.strip.to_i
end
end

class DashboardSetCount < Parser
def self.process(data)
element('dashboard_setCount_response', data).content.strip == '1'
end
end

class DashboardIncrementCount < Parser
def self.process(data)
element('dashboard_incrementCount_response', data).content.strip == '1'
end
end

class DashboardDecrementCount < Parser
def self.process(data)
element('dashboard_decrementCount_response', data).content.strip == '1'
end
end

class Errors < Parser#:nodoc:
EXCEPTIONS = {
1 => Facebooker::Session::UnknownError,
Expand Down Expand Up @@ -754,7 +778,11 @@ class Parser
'facebook.sms.canSend' => SmsCanSend,
'facebook.comments.add' => CommentsAdd,
'facebook.comments.remove' => CommentsRemove,
'facebook.comments.get' => CommentsGet
'facebook.comments.get' => CommentsGet,
'facebook.dashboard.setCount' => DashboardSetCount,
'facebook.dashboard.getCount' => DashboardGetCount,
'facebook.dashboard.incrementCount' => DashboardIncrementCount,
'facebook.dashboard.decrementCount' => DashboardDecrementCount
}
end
end
28 changes: 27 additions & 1 deletion test/facebooker/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,27 @@ def test_can_rsvp_to_event
result = @user.rsvp_event(1000, 'attending')
assert result
end

def test_can_set_dashboard_count
@session.expects(:post).with('facebook.dashboard.setCount', {:uid => @user.uid, :count => 12})
@user.dashboard_count = 12
end

def test_can_increment_dashboard_count
@session.expects(:post).with('facebook.dashboard.incrementCount', {:uid => @user.uid})
@user.dashboard_increment_count
end

def test_can_decrement_dashboard_count
@session.expects(:post).with('facebook.dashboard.decrementCount', {:uid => @user.uid})
@user.dashboard_decrement_count
end

def test_can_get_dashboard_count
@session.expects(:post).with('facebook.dashboard.getCount', {:uid => @user.uid}).returns(12)
assert_equal 12, @user.dashboard_count
end

def test_threads_should_return_an_array_of_thread_instances_containing_messages_and_attachments
expect_http_posts_with_responses(example_threads)
threads = @user.threads
Expand Down Expand Up @@ -377,7 +397,6 @@ def test_threads_should_return_populated_fields
end

private

def example_profile_photos_get_xml
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<photos_get_response xmlns=\"http://api.facebook.com/1.0/\"
Expand Down Expand Up @@ -668,4 +687,11 @@ def example_threads
XML
end


def dashboard_get_count_xml
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<dashboard_getCount_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">12</dashboard_getCount_response>
XML
end
end

0 comments on commit 59b356f

Please sign in to comment.