Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Foursquare Badge Support #484

Merged
merged 9 commits into from

2 participants

@bassdread
Collaborator

Adds badge fetching and storing to Foursquare.

Connectors/foursquare/foursquare.synclet
@@ -13,7 +13,12 @@
{
"frequency": 60,
"name": "recent"
+ },
+ {
+ "frequency": 5,
@erictj
erictj added a note

Would you mind kicking this frequency up to something like 3600. Probably around the same amount of scheduling frequency as new contacts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@erictj

Woo! Looks like you got it working! Made one comment on the frequency. Otherwise looks great.

@bassdread
Collaborator

No problem, I left the debug value in by mistake. I bumped it to 3600.

@erictj

Awwwesome!

@erictj erictj merged commit 7fdf0f7 into LockerProject:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
54 Connectors/foursquare/badges.js
@@ -0,0 +1,54 @@
+/*
+*
+* Copyright (C) 2011, The Locker Project
+* All rights reserved.
+*
+* Please see the LICENSE file for more information.
+*
+*/
+
+var fs = require('fs')
+ , request = require('request')
+ , auth
+ , seenIDs = {}
+ , lastBadges = {}
+ , newBadges = []
+ , badges = []
+ ;
+
+exports.sync = function(processInfo, cb) {
+ auth = processInfo.auth;
+ if (processInfo.config && processInfo.config.badges) {
+ lastBadges = processInfo.config.badges;
+ }
+ exports.syncBadges(function(err) {
+ var responseObj = {data : {}, config : {}};
+ responseObj.data.badges = newBadges;
+ responseObj.config.badges = seenIDs;
+ cb(err, responseObj);
+ });
+};
+
+
+exports.syncBadges = function (callback) {
+ getBadges(auth.accessToken, function(err, resp, data) {
+ if(err || !data || !JSON.parse(data).response.badges) return callback("broke" + err);
+ var badges_json = JSON.parse(data).response.badges;
+ if (badges_json === undefined) {
+ return callback('error attempting to get badge data - ' + data);
+ }
+ badges = JSON.stringify(badges_json);
+ for (var badge in badges_json) {
+ if (badges_json[badge]['unlocks'].length > 0){
+ newBadges.push({obj: badges_json[badge], timestamp: Date.now()});
+ seenIDs[badges_json[badge].id] = true;
+ }
+ }
+
+ callback();
+ });
+}
+
+function getBadges(token, callback) {
+ request.get('https://api.foursquare.com/v2/users/self/badges.json?v=20111202&oauth_token=' + token, callback);
+}
View
8 Connectors/foursquare/foursquare.synclet
@@ -13,7 +13,12 @@
{
"frequency": 60,
"name": "recent"
+ },
+ {
+ "frequency": 3600,
+ "name": "badges"
}
+
],
"mongoId" : {
"photos": "photoID"
@@ -22,7 +27,8 @@
"contact/foursquare",
"profile/foursquare",
"recents/foursquare",
- "checkin/foursquare"
+ "checkin/foursquare",
+ "badges/foursquare"
],
"provider": "foursquare",
"action": "Connect to a Foursquare account",
Something went wrong with that request. Please try again.