basic google calendar working
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
function getInformation(information)
|
||||
{
|
||||
var elements = information.split(" ");
|
||||
//console.log(elements);
|
||||
|
||||
date = elements[1];
|
||||
//console.log(date);
|
||||
datePortion = "20" + date.substring(6) + "-" + date.substring(0, 2) + "-" + date.substring(3, 5);
|
||||
//console.log(datePortion);
|
||||
|
||||
militaryTime = true;
|
||||
for (var i = 0; i < elements.length; i++)
|
||||
{
|
||||
if (elements[i].toLowerCase().substring(5) === "pm" || elements[i].toLowerCase().substring(5) === "am")
|
||||
{
|
||||
militaryTime = false;
|
||||
}
|
||||
}
|
||||
//console.log(militaryTime);
|
||||
|
||||
timePortion1 = "";
|
||||
timePortion2 = " ";
|
||||
if (militaryTime)
|
||||
{
|
||||
timePortion1 = elements[2] + ":00-07:00";
|
||||
timePortion2 = elements[3] + ":00-07:00";
|
||||
//console.log(timePortion1);
|
||||
//console.log(timePortion2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (elements[2].substring(5).toLowerCase() === "am")
|
||||
{
|
||||
timePortion1 = elements[2].substring(0, 5) + ":00-07:00";
|
||||
}
|
||||
else
|
||||
{
|
||||
hour = parseInt(elements[2].substring(0, 2)) + 12;
|
||||
timePortion1 = hour + elements[2].substring(2, 5) + ":00-07:00";
|
||||
}
|
||||
|
||||
if (elements[3].substring(5).toLowerCase() === "am")
|
||||
{
|
||||
timePortion2 = elements[3].substring(0, 5) + ":00-07:00";
|
||||
}
|
||||
else
|
||||
{
|
||||
hour = parseInt(elements[3].substring(0, 2)) + 12;
|
||||
timePortion2 = hour + elements[3].substring(2, 5) + ":00-07:00";
|
||||
}
|
||||
}
|
||||
console.log([elements[0], datePortion + "T" + timePortion1, datePortion + "T" + timePortion2]);
|
||||
return [elements[0], datePortion + "T" + timePortion1, datePortion + "T" + timePortion2];
|
||||
}
|
||||
|
||||
function makeEvent(information)
|
||||
{
|
||||
fields = getInformation(information);
|
||||
|
||||
var event = {
|
||||
'summary': fields[0],
|
||||
'location': '',
|
||||
'description': '',
|
||||
'start': {
|
||||
'dateTime': fields[1],
|
||||
'timeZone': 'America/Los_Angeles'
|
||||
},
|
||||
'end': {
|
||||
'dateTime': fields[2],
|
||||
'timeZone': 'America/Los_Angeles'
|
||||
},
|
||||
'recurrence': [
|
||||
'RRULE:FREQ=DAILY;COUNT=1'
|
||||
],
|
||||
'attendees': [
|
||||
],
|
||||
'reminders': {
|
||||
'useDefault': false,
|
||||
'overrides': [
|
||||
{'method': 'email', 'minutes': 24 * 60},
|
||||
{'method': 'popup', 'minutes': 10}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
var request = gapi.client.calendar.events.insert({
|
||||
'calendarId': 'primary',
|
||||
'resource': event
|
||||
});
|
||||
|
||||
request.execute(function(event) {
|
||||
alert('Event created: ' + event.htmlLink);
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// Client ID and API key from the Developer Console
|
||||
var CLIENT_ID = '951578952608-pnrc56tttl9dd2u67keg43hj5rhn6eid.apps.googleusercontent.com';
|
||||
|
||||
// Array of API discovery doc URLs for APIs used by the quickstart
|
||||
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"];
|
||||
|
||||
// Authorization scopes required by the API; multiple scopes can be
|
||||
// included, separated by spaces.
|
||||
var SCOPES = "https://www.googleapis.com/auth/calendar";
|
||||
|
||||
var authorizeButton = document.getElementById('authorize-button');
|
||||
var signoutButton = document.getElementById('signout-button');
|
||||
/**
|
||||
* On load, called to load the auth2 library and API client library.
|
||||
*/
|
||||
function handleClientLoad() {
|
||||
gapi.load('client:auth2', initClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the API client library and sets up sign-in state
|
||||
* listeners.
|
||||
*/
|
||||
function initClient() {
|
||||
gapi.client.init({
|
||||
discoveryDocs: DISCOVERY_DOCS,
|
||||
clientId: CLIENT_ID,
|
||||
scope: SCOPES
|
||||
}).then(function () {
|
||||
// Listen for sign-in state changes.
|
||||
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
|
||||
|
||||
// Handle the initial sign-in state.
|
||||
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
|
||||
authorizeButton.onclick = handleAuthClick;
|
||||
signoutButton.onclick = handleSignoutClick;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the signed in status changes, to update the UI
|
||||
* appropriately. After a sign-in, the API is called.
|
||||
*/
|
||||
function updateSigninStatus(isSignedIn) {
|
||||
if (isSignedIn) {
|
||||
console.log('logged-in');
|
||||
} else {
|
||||
console.log('logged out');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign in the user upon button click.
|
||||
*/
|
||||
function handleAuthClick(event) {
|
||||
gapi.auth2.getAuthInstance().signIn();
|
||||
}
|
||||
|
||||
function handleSignoutClick(event) {
|
||||
gapi.auth2.getAuthInstance().signOut();
|
||||
}
|
||||
Reference in New Issue
Block a user