Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created August 11, 2011 19:33
Show Gist options
  • Save ashaw/1140539 to your computer and use it in GitHub Desktop.
Save ashaw/1140539 to your computer and use it in GitHub Desktop.
class School < ActiveRecord::Base
def fb_affiliations
ids = []
# this could be wildly off, since we're not selecting on the school category, i.e.
#
# pages.select {|q| q['category'] == 'School'}
#
# because facebook is an arbitrary assemblage in which schools can be "interests," "organizations," "local businesses," &c.
# Our best chance here is to run through all the pages again and stash category/geo data from the individual graph endpoints,
# to distinguish between all the "Edison Elementary School" entries in the country. After we do that, we can then decouple
# mismatched school/pages and throw ones out where we don't have enough data. But the wider we cast our net the more likely
# we'll grab something useful...
pages = JSON.parse(RestClient.get("http://graph.facebook.com/search?q=#{URI.encode(self.name)}&type=page"))['data']
pages.map {|q| ids << q['id'] }
groups = JSON.parse(RestClient.get("http://graph.facebook.com/search?q=#{URI.encode(self.name)}&type=group"))['data']
groups.map {|q| ids << q['id'] }
# attach pages related to the school's town to the school.. may be able to grab more that way.
towns = JSON.parse(RestClient.get("http://graph.facebook.com/search?q=#{URI.encode(self.city + ', ' + self.state)}&type=page"))['data']
towns.map {|q| ids << q['id'] }
ids
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment