Skip to content

Commit

Permalink
Add SV ruby group to meetup importer
Browse files Browse the repository at this point in the history
Possibly fix omniauth (was it broken everwhere or just for me?)
by upgrading to latest version.
  • Loading branch information
tjgrathwell committed Jul 7, 2013
1 parent 7f771a5 commit 7ac4f01
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 232 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ GEM
railties (>= 3.0.0)
faker (1.1.2)
i18n (~> 0.5)
faraday (0.8.6)
faraday (0.8.7)
multipart-post (~> 1.1)
faye-websocket (0.4.7)
eventmachine (>= 0.12.0)
Expand All @@ -108,7 +108,7 @@ GEM
execjs (>= 1.2.9)
sprockets (>= 2.0.3)
tilt
hashie (1.2.0)
hashie (2.0.5)
hike (1.2.3)
http_parser.rb (0.5.3)
httpauth (0.2.0)
Expand All @@ -129,8 +129,8 @@ GEM
jquery-rails
railties (>= 3.1.0)
json (1.7.7)
jwt (0.1.5)
multi_json (>= 1.0)
jwt (0.1.8)
multi_json (>= 1.5)
launchy (2.2.0)
addressable (~> 2.3)
listen (0.7.3)
Expand All @@ -151,10 +151,10 @@ GEM
jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
omniauth (1.1.3)
hashie (~> 1.2)
omniauth (1.1.4)
hashie (>= 1.2, < 3)
rack
omniauth-meetup (0.0.6)
omniauth-meetup (0.0.7)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.0)
omniauth-oauth2 (1.1.1)
Expand Down
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ PORT=3000
With the `.env` file in place, simply run `foreman start` in your Bridge Troll directory instead of starting with `rails server`.

#### Historical Meetup Importing
To import historical data from the SF Ruby Meetup group, use the rake task `rake meetup:import`. This requires you set up a MEETUP_API_KEY in your local environment, which you can find on Meetup at http://www.meetup.com/meetup_api/key/.
To import historical data from Meetup, use the rake task `rake meetup:import`. This requires you set up a MEETUP_API_KEY in your local environment, which you can find on Meetup at http://www.meetup.com/meetup_api/key/.

#### Meetup OAuth
To test authenticating with Meetup using your localhost server, you need to [register a new OAuth Consumer at Meetup](http://www.meetup.com/meetup_api/oauth_consumers/).
Expand Down
9 changes: 9 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'meetups'

class Event < ActiveRecord::Base
after_initialize :set_defaults
after_save :reorder_waitlist!
Expand Down Expand Up @@ -46,6 +48,13 @@ def historical?
meetup_volunteer_event_id || meetup_student_event_id
end

def meetup_url meetup_event_id
return nil unless historical?

meetup_group_url = MeetupEventInfo.url_for_event(meetup_event_id)
"http://#{meetup_group_url}/events/#{meetup_event_id}/"
end

def at_limit?
if student_rsvp_limit
student_rsvps.count >= student_rsvp_limit
Expand Down
19 changes: 12 additions & 7 deletions app/services/meetup_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,24 @@ def assert_valid_response url, response_json
return false
end

def import
def all_meetup_events
MEETUP_EVENTS.values.flatten
end

def import group = nil
return unless assert_key_exists

MEETUP_EVENTS.each_with_index do |event_data, index|
puts "Importing event #{index+1} of #{MEETUP_EVENTS.length} (students: #{event_data[:student_event_id]}, volunteers: #{event_data[:volunteer_event_id]})"
events = group ? MEETUP_EVENTS[group] : all_meetup_events
events.each_with_index do |event_data, index|
puts "Importing event #{index+1} of #{events.length} (students: #{event_data[:student_event_id]}, volunteers: #{event_data[:volunteer_event_id]})"
import_student_and_volunteer_event(event_data)
end
end

def import_single student_event_id
return unless assert_key_exists

event_data = MEETUP_EVENTS.select { |event| event[:student_event_id] == student_event_id.to_i }.first
event_data = all_meetup_events.find { |event| event[:student_event_id] == student_event_id.to_i }
raise "No event data found for #{student_event_id}" unless event_data.present?

puts "Importing event (students: #{event_data[:student_event_id]}, volunteers: #{event_data[:volunteer_event_id]})"
Expand Down Expand Up @@ -143,11 +148,11 @@ def keep_rsvp?(rsvp, role)
end
end

def dump_events
def dump_events group = :sf
start_milis = DateTime.parse('2009-06-01').to_i * 1000
puts "Fetching first set of results..."
puts "Fetching first set of results for #{group}..."
event_jsons = get_api_response_for('/2/events', {
group_id: 134063,
group_id: MEETUP_GROUP_IDS[group],
time: "#{start_milis},",
status: 'past'
})['results']
Expand Down
Loading

0 comments on commit 7ac4f01

Please sign in to comment.