Skip to content

Instantly share code, notes, and snippets.

@tiff
Created December 27, 2009 18:20
Show Gist options
  • Save tiff/264354 to your computer and use it in GitHub Desktop.
Save tiff/264354 to your computer and use it in GitHub Desktop.
/**
* "Happy Birthday Nenad" OpenSocial Script
* UNTESTED
* Probably won't work in most OpenSocial containers
* due to privacy settings
*/
var NENADS_USER_ID = '<UserId>'; // eg. VIEWER
var req = opensocial.newDataRequest();
var params = {};
params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.BIRTHDAY];
req.add(req.newFetchPersonRequest(NENADS_USER_ID, params), "nenad"));
req.send(function(data) {
var profileData = data.get("nenad").getData();
var today = new Date();
var birthday = profileData.getField(opensocial.Person.Field.BIRTHDAY);
bithday = createDateObject(birthday);
if (birthday.getDate() == today.getDate() && birthday.getMonth() == today.getMonth()) {
alert("Dude seems like it's your big day. You better shout out a few drinks when you're back in the office!");
} else {
alert("Today is not your birthday!");
}
});
/**
* Expects a dateStr like "31-12-2009"
*/
function createDateObject(dateStr) {
var dateObj = new Date();
var dateArr = dateStr.split("-");
var day = dateArr[0];
var month = dateArr[1] - 1; // (0 => January, 1 => February, ...)
var year = dateArr[2];
with (dateObj) {
setMonth(month);
setDate(day);
setYear(year);
}
return dateObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment