Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jhubert/iparty
base: 5f1e6fc4c2
...
head fork: jhubert/iparty
compare: 88084104c7
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 42 additions and 20 deletions.
  1. +1 −0  app/controllers/guest_controller.rb
  2. +41 −20 app/models/event.rb
View
1  app/controllers/guest_controller.rb
@@ -8,6 +8,7 @@ def index
def party
@event = Event.find_by_facebook_eid(params[:id])
@event = Event.create_from_facebook_graph_and_facebook_eid(current_user.koala, params[:id]) unless @event.present?
+ redirect_to guest_path, :notice => 'We could not find that event. Make sure you are invited to it on facebook.' unless @event
end
def payment
View
61 app/models/event.rb
@@ -2,32 +2,53 @@ class Event < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :user_id, :facebook_eid, :name, :image_url, :start_time, :end_time, :venue_facebook_vid, :venue_name, :venue_latitude, :venue_longitude, :donation_amount, :facebook_owner_id
- validates_presence_of :facebook_eid, :venue_facebook_vid
+ validates_presence_of :facebook_eid
belongs_to :user
def self.create_from_facebook_graph_and_facebook_eid(koala, eid, attrs = {})
# TODO: what happens if the event doesn't exist?
- fb_event_data = koala.get_object(eid)
-
- # TODO: what happens if a venue doesn't exist?
- fb_venue_data = koala.get_object(fb_event_data['venue']['id'])
-
- # Merge the data, but don't override the passed in attributes
- attrs.reverse_merge!(
- :facebook_eid => fb_event_data['id'],
- :facebook_owner_id => fb_event_data['owner'] && fb_event_data['owner']['id'],
- :name => fb_event_data['name'],
- :image_url => fb_event_data['pic'],
- :start_time => fb_event_data['start_time'],
- :end_time => fb_event_data['end_time'],
- :venue_facebook_vid => fb_venue_data['id'],
- :venue_name => fb_venue_data['name'],
- :venue_latitude => fb_venue_data['location']['latitude'],
- :venue_longitude => fb_venue_data['location']['longitude']
- )
+ begin
+ fb_event_data = koala.get_object(eid)
+ rescue
+ fb_event_data = nil
+ end
- Event.create(attrs)
+ if fb_event_data.present?
+ attrs.reverse_merge!(
+ :facebook_eid => fb_event_data['id'],
+ :facebook_owner_id => fb_event_data['owner'] && fb_event_data['owner']['id'],
+ :name => fb_event_data['name'],
+ :image_url => fb_event_data['pic'],
+ :start_time => fb_event_data['start_time'],
+ :end_time => fb_event_data['end_time']
+ )
+
+ # TODO: what happens if a venue doesn't exist?
+ if fb_event_data['venue']['id'].present?
+ fb_venue_data = koala.get_object(fb_event_data['venue']['id'])
+ elsif fb_event_data['venue']['name'].present?
+ fb_venue_data = fb_event_data['venue']
+ fb_venue_data['name'] ||= ([fb_venue_data['street'], fb_venue_data['city'], fb_venue_data['country']].join(', '))
+ else
+ fb_venue_data = {
+ 'name' => 'Unknown'
+ }
+ end
+
+ attrs.reverse_merge!({
+ :venue_facebook_vid => fb_venue_data['id'],
+ :venue_name => fb_venue_data['name'],
+ :venue_latitude => fb_venue_data['location'] && fb_venue_data['location']['latitude'],
+ :venue_longitude => fb_venue_data['location'] && fb_venue_data['location']['longitude']
+ })
+
+ # Merge the data, but don't override the passed in attributes
+
+ return Event.create(attrs)
+ else
+ return false
+ end
end
def donate_with_user(user, amount = nil)

No commit comments for this range

Something went wrong with that request. Please try again.