lib/facebook_events.rb in facebook_events-0.0.2 vs lib/facebook_events.rb in facebook_events-0.0.3
- old
+ new
@@ -1,33 +1,37 @@
class FacebookEvents
require 'mini_fb'
- require 'facebook_events/event'
require "facebook_events/version"
- # Get events for a Facebook page or user by id.
- # Requires environment variables for Facebook APP ID and APP Secret:
- # FacebookEvents::FACEBOOK_APP_ID = ...
- # FacebookEvents::FACEBOOK_SECRET = ...
+ attr_reader :facebook_id
- attr_reader :facebook_id, :auth_token, :list
-
def initialize(facebook_id)
@facebook_id = facebook_id
@auth_token = get_auth_token
- @list = get_events
end
+ def self.list(facebook_id)
+ facebook_resource = new(facebook_id)
+ events = []
+ event_list = facebook_resource.get_events_list(facebook_id)
+ event_list.each do |event|
+ events << facebook_resource.get_event_details(event.id)
+ end
+ events
+ end
+
+ def get_events_list(facebook_id)
+ MiniFB.get(@auth_token, @facebook_id, :type => 'events').data
+ end
+
+ def get_event_details(facebook_id)
+ MiniFB.get(@auth_token, facebook_id).to_hash
+ end
+
private
def get_auth_token
MiniFB.authenticate_as_app(FACEBOOK_APP_ID, FACEBOOK_SECRET)['access_token']
- end
-
- def get_events
- list = MiniFB.get(@auth_token, @facebook_id, :type => 'events').data
- list.map do |e|
- FacebookEvents::Event.new(MiniFB.get(@auth_token, e.id))
- end
end
end
\ No newline at end of file