Josh Sharpe
2008-Dec-10  04:15 UTC
[Facebooker-talk] events.members & attendence.user methods
I had some thoughts about creating a Events#members method.  It would be
pretty straight forward if a session attribute existed on the event, but
thats'' not the case.  I''m not sure that this is the best way
to hack this
out, but here goes:
So the diff on Session is to merge the session object onto the new event in
Session#events
    def events(options = {})
      @events ||= post(''facebook.events.get'', options) do
|response|
        response.map do |hash|
          Event.from_hash(hash.merge(:session => self))
        end
      end
    end
Then the Events#members method is pretty straight forward:
    def members
      @members ||= @session.event_members(@eid)
    end
This works...can do stuff like:
facebooker_user.events.first.members
The only problem is that it slams that session instance on every Event.  Is
that necessarily a bad thing?
Anyways, Attendence#user works basically the same way:
class Session
    def event_members(eid)
      @members ||= post(''facebook.events.getMembers'', :eid
=> eid) do
|response|
        response.map do |attendee_hash|
          Event::Attendance.from_hash(attendee_hash.merge(:session => self))
        end
      end
    end
end
class Attendence
      def user
        @user ||= User.new(uid, @session)
      end
end
Is anyone doing this similarly, differently?
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/facebooker-talk/attachments/20081209/cceceaac/attachment.html>