-
-
Save adekbadek/d28da825ed964bfd36fb8aa51419b5c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// here a module is imported, webpack will know that it should look for it in node_modules folder | |
import request from 'superagent' | |
const CALENDAR_ID = 'tb8ckdrm61bdsj6jfm7khob4u5@group.calendar.google.com' | |
const API_KEY = 'AIzaSyAOuDzSlG24RPBn3OKVAyjW3OK_EJhCUbp' | |
let url = `https://www.googleapis.com/calendar/v3/calendars/${CALENDAR_ID}/events?key=${API_KEY}` | |
// export means that this function will be available to any module that imports this module | |
export function getEvents (callback) { | |
request | |
.get(url) | |
.end((err, resp) => { | |
if (!err) { | |
// create array to push events into | |
const events = [] | |
// in practice, this block should be wrapped in a try/catch block, | |
// because as with any external API, we can't be sure if the data will be what we expect | |
JSON.parse(resp.text).items.map((event) => { | |
events.push({ | |
// an event from Google Calendar can be a full day event or a regular one | |
start: event.start.date || event.start.dateTime, | |
end: event.end.date || event.end.dateTime, | |
title: event.summary, | |
}) | |
}) | |
callback(events) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment