How to use the googleapis.calendar function in googleapis

To help you get started, we’ve selected a few googleapis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bdm1981 / roomRequest-Spark-Bot / module / gSuiteCommand.js View on Github external
const moment = require('moment-timezone');
const google = require('googleapis');
require('dotenv').config();
const gAuth = require('./authorize');
const time = require('./timeNLP');
const Manager = require('./manager');
const service = google.admin('directory_v1');
const calendar = google.calendar('v3');

// array for handling the conversation state
var tracker = new Manager.Convo();

var gCmd = module.exports = {
    findBuilding: function(auth, buildingId){
      return new Promise(function(resolve, reject){
        service.resources.calendars.list({
          auth: auth,
          customer: 'my_customer',
          query: `buildingId=${buildingId}`
        }, function(err, building){
          if(err){
            console.error('The API returned an error: ' + err);
            reject(err);
          }else{
github Skookum / hubot-slack-gcal / scripts / events.js View on Github external
robot.emit('google:authenticate', msg, function(err, oauth) {
      var group_name = msg.match[2],
          group = groups[group_name],
          startTime = new Date().toISOString(),
          endTime = new Date();
      endTime.setHours(endTime.getHours()+1);
      endTime = endTime.toISOString();
      if(group) {
        var req = googleapis.calendar('v3').freebusy.query({ auth: oauth, resource: { items: _.map(_.keys(group), function(g) { return { id: g } }), timeMin: startTime, timeMax: endTime } }, function (err, availability) {
          if(err) { msg.reply("Error getting calendar availability"); return console.log(err); }
          var available = [];
          _.each(availability.calendars, function(c, id) {
            if(!c.errors && c.busy.length == 0) {
              available.push(group[id][0]);
            }
          });
          if(available.length == 0) return msg.send("There are no " + group_name + "s available in the next hour");
          msg.send("These " + group_name + "s are free for the next hour:\n" + available.join("\n"));
        });
      } else {
        msg.reply("I don't know anything about " + group_name);
      }
    });
  });
github httparty / matchjs / server / calendar / calendarHandler.js View on Github external
var description = req.query.description || req.session.mentorshipEvent.description;
      var start = req.query.start || req.session.mentorshipEvent.start;
      var end = req.query.end || req.session.mentorshipEvent.end;

      var event = {
        'summary': summary,
        'description': description,
        'start': {
          'dateTime': start,
        },
        'end': {
          'dateTime': end,
        }
      };

      var calendar = google.calendar('v3');

      calendar.events.insert({
        auth: oauth2Client,
        calendarId: 'primary',
        resource: event,
      }, function(err, event) {
        if (err) {
          console.log('There was an error contacting the Google Calendar service: ' + err);
          return;
        }
        //redirect to newly exported event
        res.redirect(event.htmlLink);
      });
    }
  } 
};
github matryer / bitbar-plugins / Time / googlecal.30m.js View on Github external
function listEvents(oauth2Client) {
  var calendar = google.calendar('v3');
  var processedCalendars = 0;
  var today = moment().format('L');
  var tomorrow = moment().add(1, 'days').format('L');
  var start = moment(new Date(cfg.startDate));
  var dateLimit, evnts = {};

  if (!(cfg.calendarId instanceof Array)) {
    cfg.calendarId = cfg.calendarId.split(',');
  }

  if (cfg.days) {
    dateLimit = moment(start).add((cfg.days - 1), 'days').format('L');

    if (cfg.showEmptyDays) {
      for (var x = 0; x < cfg.days; x++) {
        evnts[moment(start).add(x, 'days').format('L')] = [];
github iamnickvolpe / view-original / server / google.js View on Github external
ref.once("value", function(snapshot) {
    var credentials = snapshot.child('credentials').child('google').val();
    oauth2Client.credentials = credentials;
    
    if (credentials) {
      google.calendar('v3').calendarList.list({
      auth: oauth2Client
      }, function(err, response) {
        if (err) {
          res.send({'success': false, 'error': err});
          return;
        }
        res.send(response.items);
      });
    }
  });
}
github RobertDNelson / Peggy / Modules / eventsBoard.js View on Github external
var http = require('http');
var dateFormat = require("date-format-lite");
var google = require('googleapis');
var calendar = google.calendar('v3');

var defaultParams = {
  calendarId: 'explorecoco.com_mjo4fpfd0f53vt5nemrci5nuj4@group.calendar.google.com',
  orderBy: 'startTime',
  singleEvents: true,
  maxResults: 11,
  fields: 'items(summary,start)',
  key: 'AIzaSyBd50j18XdFyya_oR8QrJFNOjE-JpdsRIg'
}

function update() {
  var date = new Date();
  date.setHours(0);
  date.setMinutes(0);
  date.setSeconds(0);
github GladysAssistant / Gladys / api / services / GoogleCalendarService.js View on Github external
/** 
  * Gladys Project
  * http://gladysproject.com
  * Software under licence Creative Commons 3.0 France 
  * http://creativecommons.org/licenses/by-nc-sa/3.0/fr/
  * You may not use this software for commercial purposes.
  * @author :: Pierre-Gilles Leymarie
  */


var google = require('googleapis');
var calendar = google.calendar('v3');
var OAuth2Client = google.auth.OAuth2;
var oauth2Client = new OAuth2Client( sails.config.googleapi.consumer_key , sails.config.googleapi.consumer_secret , sails.getBaseurl() + '/googleapi/create');

/**
 * Description
 * @method getGoogleCalendar
 * @param {} access_token
 * @param {} refresh_token
 * @param {} userId
 * @param {} callback
 * @return 
 */
function getGoogleCalendar(access_token,refresh_token,userId, callback){

	oauth2Client.setCredentials({
		access_token: access_token,
github Skookum / hubot-slack-gcal / scripts / events.js View on Github external
getPrimaryCalendar(oauth, function(err, calendar_o) {
        if(err || !calendar_o) return msg.reply("Could not find your primary calendar");
        var calendar = calendar_o.id;
        googleapis.calendar('v3').events.get({ auth: oauth, alwaysIncludeEmail: true, calendarId: calendar, eventId: event }, function(err, event) {
          if(err) return msg.reply('Error getting event: ' + err);
          var attendees = event.attendees;
          var me = _.find(attendees, function(a) { return a.self });
          if(!me) return msg.reply("You are not invited to " + event.summary);
          me.responseStatus = response_map[msg.match[2]];
          googleapis.calendar('v3').events.patch({ auth: oauth, calendarId: calendar, eventId: event.id, resource: { attendees: attendees } }, function(err, event) {
            if(err) return msg.reply('Error saving status: ' + err);
            msg.reply("OK, you responded " + msg.match[2] + " to " + event.summary);
          });
        });
      });
    });
github yurykorzun / notinphilly / server / api / event / event.controller.js View on Github external
var google = require('googleapis');
var calendar = google.calendar('v3');
var nodeGeocoder = require('node-geocoder');
var apiSettings = require('../../config/apiSettings');
var logger      = require('../../components/logger');

var geocoderOptions = {
  provider: 'google',
  httpAdapter: 'https',
  apiKey: apiSettings.GOOGLE_API_KEY
};
var geocoder = nodeGeocoder(geocoderOptions);

exports.getGoogleEvents = function(req, res, next) {

    var yesterday = new Date();
    yesterday.setDate(yesterday.getDate()-1);
github simplificator / sitincator / src / gcal / client.js View on Github external
const google = require('googleapis');

let _auth, _calendarId;
const calendar = google.calendar('v3');

const MILLISECONDS_PER_MINUTE = 60000;

module.exports = class Client {
  constructor(calendarId, auth) {
    _calendarId = calendarId
    _auth = auth;
  }

  listEvents() {
    const timeMin = new Date(new Date().setHours(0, 0, 0, 0)).toISOString();
    const timeMax = new Date(new Date().setHours(23, 59, 59)).toISOString();
    return new Promise((resolve, reject) => {
      calendar.events.list({
        auth: _auth,
        calendarId: _calendarId,