/* @flow */ import { getCalendarEntries, googleApi, loadGoogleAPI, signIn, updateProfile } from '../../google-api'; /** * A stateless collection of action creators that implements the expected * interface for interacting with the Google API in order to get calendar data. * * @type {Object} */ export const googleCalendarApi = { /** * Retrieves the current calendar events. * * @param {number} fetchStartDays - The number of days to go back * when fetching. * @param {number} fetchEndDays - The number of days to fetch. * @returns {function(): Promise} */ getCalendarEntries, /** * Returns the email address for the currently logged in user. * * @returns {function(Dispatch<*>): Promise} */ getCurrentEmail() { return updateProfile(); }, /** * Initializes the google api if needed. * * @returns {function(Dispatch<*>, Function): Promise} */ load() { return (dispatch: Dispatch<*>, getState: Function) => { const { googleApiApplicationClientID } = getState()['features/base/config']; return dispatch(loadGoogleAPI(googleApiApplicationClientID)); }; }, /** * Prompts the participant to sign in to the Google API Client Library. * * @returns {function(Dispatch<*>): Promise} */ signIn, /** * Returns whether or not the user is currently signed in. * * @returns {function(): Promise} */ _isSignedIn() { return () => googleApi.isSignedIn(); } };