Permalink
Browse files

Added events method to Facebooker::User

git-svn-id: svn+ssh://rubyforge.org/var/svn/facebooker/trunk/facebooker@216 06148572-b36b-44fe-9aa8-f68b04d8b080
  • Loading branch information...
1 parent 517f81e commit 1b579de87ad14f4b1867b73e98ecfbb15ea94e00 kyleslat committed May 19, 2008
Showing with 53 additions and 1 deletion.
  1. +11 −0 lib/facebooker/models/user.rb
  2. +42 −1 test/user_test.rb
@@ -39,6 +39,17 @@ def initialize(*args)
end
end
+ # Returns a user's events, params correspond to API call parameters (except UID):
+ # http://wiki.developers.facebook.com/index.php/Events.get
+ # E.g:
+ # @user.events(:start_time => Time.now.to_i, :end_time => 1.month.from_now.to_i)
+ # # => Returns events betwen now and a month from now
+ def events(params={})
+ @events ||= @session.post('facebook.events.get', {:uid => self.id}.merge(params)).map do |event|
+ Event.from_hash(event)
+ end
+ end
+
#
# Set the list of friends, given an array of User objects. If the list has been retrieved previously, will not set
View
@@ -78,7 +78,17 @@ def test_can_set_status_with_string
@user.status="my status"
end
-
+ def test_get_events
+ @user = Facebooker::User.new(9507801, @session)
+ expect_http_posts_with_responses(example_events_get_xml)
+ events = @user.events
+ assert_equal "29511517904", events.first.eid
+ end
+
+ def test_can_get_events
+ @user.expects(:events)
+ @user.events
+ end
def test_to_s
assert_equal("1234",@user.to_s)
@@ -115,4 +125,35 @@ def example_profile_photos_get_xml
</photos_get_response>"
end
+ def example_events_get_xml
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+ <events_get_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\" list=\"true\">
+ <event>
+ <eid>29511517904</eid>
+ <name>PUMA SALE</name>
+ <tagline/>
+ <nid>0</nid>
+ <pic>http://profile.ak.facebook.com/object3/370/66/s29511517904_6952.jpg</pic>
+ <pic_big>http://profile.ak.facebook.com/object3/370/66/n29511517904_6952.jpg</pic_big>
+ <pic_small>http://profile.ak.facebook.com/object3/370/66/t29511517904_6952.jpg</pic_small>
+ <host>PUMA</host>
+ <description>PUMA SALE</description>
+ <event_type>Education</event_type>
+ <event_subtype>Study Group</event_subtype>
+ <start_time>1212166800</start_time>
+ <end_time>1212364800</end_time>
+ <creator>1234261165</creator>
+ <update_time>1209768148</update_time>
+ <location>PUMA LOT</location>
+ <venue>
+ <street>5 LYBERTY WAY</street>
+ <city>Westford</city>
+ <state>Massachusetts</state>
+ <country>United States</country>
+ <latitude>42.5792</latitude>
+ <longitude>-71.4383</longitude>
+ </venue>
+ </event>
+ </events_get_response>"
+ end
end

0 comments on commit 1b579de

Please sign in to comment.