Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

Commit

Permalink
add ability to find meetup organizers using api.meetup.com
Browse files Browse the repository at this point in the history
  • Loading branch information
lzcabrera committed Jan 14, 2015
1 parent 1d24587 commit 4a1920b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -19,6 +19,7 @@ gem "rails-assets-moment"
gem "underscore-rails"
gem "gmaps4rails"
gem "geocoder"
gem "faraday"

group :development, :test do
gem 'pry'
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Expand Up @@ -63,6 +63,8 @@ GEM
erubis (2.7.0)
eventmachine (1.0.4)
execjs (2.2.2)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
ffi (1.9.6)
ffi (1.9.6-x86-mingw32)
geocoder (1.2.6)
Expand All @@ -73,6 +75,7 @@ GEM
highline (1.6.21)
hike (1.2.3)
hitimes (1.2.2)
hitimes (1.2.2-x86-mingw32)
hooks (0.4.0)
uber (~> 0.0.4)
i18n (0.6.11)
Expand Down Expand Up @@ -121,6 +124,7 @@ GEM
mini_portile (0.6.2)
minitest (5.5.0)
multi_json (1.10.1)
multipart-post (2.0.0)
nokogiri (1.6.5)
mini_portile (~> 0.6.0)
nokogiri (1.6.5-x86-mingw32)
Expand Down Expand Up @@ -215,6 +219,7 @@ DEPENDENCIES
capybara
coderay!
ember-middleman
faraday
geocoder
gmaps4rails
highline
Expand Down
17 changes: 17 additions & 0 deletions Rakefile
Expand Up @@ -106,6 +106,18 @@ def geocode_meetups
end
end

def find_meetup_organizers
data_path = 'meetups.yml'
puts "Getting organizers data from api.meetup.com for #{data_path}..."

data = YAML.load_file(File.expand_path("./data/#{data_path}"))
data["locations"].each do |loc|
loc["groups"].each do |group|
MeetupsData::GroupOrganizer.from_hash(group).find_organizers
end
end
end

def build
system "middleman build"
end
Expand Down Expand Up @@ -177,3 +189,8 @@ desc "Find coordinates for meetup locations"
task :geocode do
geocode_meetups
end

desc "Find organizers for meetup user group_urlname"
task :findorganizers do
find_meetup_organizers
end
71 changes: 71 additions & 0 deletions lib/meetups_data.rb
@@ -1,4 +1,5 @@
require 'geocoder'
require 'faraday'

module MeetupsData
class GroupGeocoder
Expand Down Expand Up @@ -47,4 +48,74 @@ def self.from_hash(data)
self.new(data)
end
end

class GroupOrganizer
attr_reader :data

def initialize(data)
@data = data
end

def find_organizers

return if !data["url"].include? 'http://www.meetup.com/'

return if has_organizers?

group_urlname = parse_url_name_from_url(data["url"])
get_organizers(group_urlname)

end

def has_organizers?
data.has_key?("organizers")
end

def parse_url_name_from_url(meetup_url)
urlname = meetup_url.split('http://www.meetup.com/')
return urlname[1].to_s.chomp("/")
end

def get_organizers(meetup_urlname)

api_call = "https://api.meetup.com/2/groups?group_urlname=#{meetup_urlname}&key=4916132d485b32663336351f342b3d6a"

conn = Faraday.new(:url => api_call) do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
end

group_response = conn.get '/2/groups', { :group_urlname => meetup_urlname, :key => '4916132d485b32663336351f342b3d6a' }

json = JSON.parse(group_response.body)

unless (json['results'].empty?)
results = json['results'][0]
organizer = results['organizer'].to_hash

profile_response = conn.get '/2/members', { :member_id => organizer['member_id'], :key => '4916132d485b32663336351f342b3d6a' }
json = JSON.parse(profile_response.body)

profile = Hash.new
profile['organizer'] = organizer['name']

unless (json['results'].empty?)
results = json['results'][0]
photo = results['photo'].to_hash

profile['profileImage'] = photo['thumb_link']

end

data["organizers"] = profile

end

end

def self.from_hash(data)
self.new(data)
end
end

end

0 comments on commit 4a1920b

Please sign in to comment.