Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * "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;
- }
Add Comment
Please, Sign In to add comment