com.google.api.services.calendar.model.Events Java Examples
The following examples show how to use
com.google.api.services.calendar.model.Events.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleCalendarExporterTest.java From data-transfer-project with Apache License 2.0 | 6 votes |
@Before public void setup() throws IOException { calendarClient = mock(Calendar.class); calendarCalendars = mock(Calendar.Calendars.class); calendarCalendarList = mock(Calendar.CalendarList.class); calendarListRequest = mock(Calendar.CalendarList.List.class); calendarEvents = mock(Calendar.Events.class); eventListRequest = mock(Calendar.Events.List.class); credentialFactory = mock(GoogleCredentialFactory.class); googleCalendarExporter = new GoogleCalendarExporter(credentialFactory, calendarClient); when(calendarClient.calendars()).thenReturn(calendarCalendars); when(calendarClient.calendarList()).thenReturn(calendarCalendarList); when(calendarCalendarList.list()).thenReturn(calendarListRequest); when(calendarClient.events()).thenReturn(calendarEvents); when(calendarEvents.list(CALENDAR_ID)).thenReturn(eventListRequest); when(eventListRequest.setMaxAttendees(MAX_ATTENDEES)).thenReturn(eventListRequest); verifyNoInteractions(credentialFactory); }
Example #2
Source File: CheckupReminders.java From Crimson with Apache License 2.0 | 6 votes |
/** * Fetch a list of the next 10 events from the primary calendar. * * @return List of Strings describing returned events. * @throws IOException */ private List<String> getDataFromApi() throws IOException { // List the next 10 events from the primary calendar. DateTime now = new DateTime(System.currentTimeMillis()); List<String> eventStrings = new ArrayList<String>(); Events events = mService.events().list("primary") .setMaxResults(10) .setTimeMin(now) .setOrderBy("startTime") .setSingleEvents(true) .execute(); List<Event> items = events.getItems(); for (Event event : items) { DateTime start = event.getStart().getDateTime(); if (start == null) { // All-day events don't have start times, so just use // the start date. start = event.getStart().getDate(); } eventStrings.add( String.format("%s (%s)", event.getSummary(), start)); } return eventStrings; }
Example #3
Source File: AnnouncementThread.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private List<Event> getEvents(GuildSettings gs, CalendarData cd, Calendar service, Announcement a) { if (!allEvents.containsKey(gs.getGuildID())) { Logger.getLogger().announcement("getting events for guild...", gs.getGuildID() + "", a.getAnnouncementId() + "", "N/a"); try { Events events = service.events().list(cd.getCalendarAddress()) .setMaxResults(15) .setTimeMin(new DateTime(System.currentTimeMillis())) .setOrderBy("startTime") .setSingleEvents(true) .setShowDeleted(false) .execute(); List<Event> items = events.getItems(); allEvents.put(gs.getGuildID(), items); } catch (IOException e) { Logger.getLogger().exception(null, "Failed to get events list! 01ae2304 | Guild: " + gs.getGuildID() + " | Announcement: " + a.getAnnouncementId(), e, true, this.getClass()); return new ArrayList<>(); } } return allEvents.get(gs.getGuildID()); }
Example #4
Source File: AnnouncementThread.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private List<Event> getEvents(GuildSettings gs, CalendarData cd, Calendar service, Announcement a) { if (!allEvents.containsKey(gs.getGuildID())) { Logger.getLogger().announcement("getting events for guild...", gs.getGuildID() + "", a.getAnnouncementId() + "", "N/a"); try { Events events = service.events().list(cd.getCalendarAddress()) .setMaxResults(15) .setTimeMin(new DateTime(System.currentTimeMillis())) .setOrderBy("startTime") .setSingleEvents(true) .setShowDeleted(false) .execute(); List<Event> items = events.getItems(); allEvents.put(gs.getGuildID(), items); } catch (IOException e) { Logger.getLogger().exception(null, "Failed to get events list! 01ae2304 | Guild: " + gs.getGuildID() + " | Announcement: " + a.getAnnouncementId(), e, true, this.getClass()); return new ArrayList<>(); } } return allEvents.get(gs.getGuildID()); }
Example #5
Source File: GCalEventDownloader.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * @{inheritDoc} */ @Override protected void execute() { Events myFeed = downloadEventFeed(); if (myFeed != null) { List<Event> entries = myFeed.getItems(); if (entries.size() > 0) { logger.debug("found {} calendar events to process", entries.size()); try { if (scheduler.isShutdown()) { logger.warn("Scheduler has been shut down - probably due to exceptions?"); } cleanJobs(); processEntries(entries); } catch (SchedulerException se) { logger.error("scheduling jobs throws exception", se); } } else { logger.debug("gcal feed contains no events ..."); } } }
Example #6
Source File: CheckupReminders.java From Crimson with Apache License 2.0 | 5 votes |
private void setReminderNow(String name, String address, String full_date) { long calID = 3; long startMillis = 0; long endMillis = 0; Calendar beginTime = Calendar.getInstance(); beginTime.set(2017, 02, 11, 15, 30); startMillis = beginTime.getTimeInMillis(); Calendar endTime = Calendar.getInstance(); endTime.set(2017, 02, 12, 15, 45); endMillis = endTime.getTimeInMillis(); ContentResolver cr = getContentResolver(); ContentValues values = new ContentValues(); values.put(CalendarContract.Events.DTSTART, startMillis); values.put(CalendarContract.Events.DTEND, endMillis); values.put(CalendarContract.Events.TITLE, "Eye Checkup"); values.put(CalendarContract.Events.DESCRIPTION, name + " - " + address); values.put(CalendarContract.Events.CALENDAR_ID, calID); values.put(CalendarContract.Events.EVENT_TIMEZONE, "Asia/Kolkata"); Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values); long eventID = Long.parseLong(uri.getLastPathSegment()); Toast.makeText(this, "EventID " + eventID, Toast.LENGTH_LONG).show(); progressDialog.dismiss(); }
Example #7
Source File: CalendarQuickstart.java From java-samples with Apache License 2.0 | 5 votes |
public static void main(String... args) throws IOException, GeneralSecurityException { // Build a new authorized API client service. final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); Calendar service = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT)) .setApplicationName(APPLICATION_NAME) .build(); // List the next 10 events from the primary calendar. DateTime now = new DateTime(System.currentTimeMillis()); Events events = service.events().list("primary") .setMaxResults(10) .setTimeMin(now) .setOrderBy("startTime") .setSingleEvents(true) .execute(); List<Event> items = events.getItems(); if (items.isEmpty()) { System.out.println("No upcoming events found."); } else { System.out.println("Upcoming events"); for (Event event : items) { DateTime start = event.getStart().getDateTime(); if (start == null) { start = event.getStart().getDate(); } System.out.printf("%s (%s)\n", event.getSummary(), start); } } }
Example #8
Source File: GoogleCalendarExporter.java From data-transfer-project with Apache License 2.0 | 4 votes |
private ExportResult<CalendarContainerResource> getCalendarEvents( TokensAndUrlAuthData authData, String id, Optional<PaginationData> pageData) { Calendar.Events.List listRequest; Events listResult; // Get event information try { listRequest = getOrCreateCalendarInterface(authData) .events() .list(id) .setMaxAttendees(GoogleStaticObjects.MAX_ATTENDEES); if (pageData.isPresent()) { StringPaginationToken paginationToken = (StringPaginationToken) pageData.get(); Preconditions.checkState( paginationToken.getToken().startsWith(EVENT_TOKEN_PREFIX), "Token is not applicable"); listRequest.setPageToken( ((StringPaginationToken) pageData.get()) .getToken() .substring(EVENT_TOKEN_PREFIX.length())); } listResult = listRequest.execute(); } catch (IOException e) { return new ExportResult<>(e); } // Set up continuation data PaginationData nextPageData = null; if (listResult.getNextPageToken() != null) { nextPageData = new StringPaginationToken(EVENT_TOKEN_PREFIX + listResult.getNextPageToken()); } ContinuationData continuationData = new ContinuationData(nextPageData); // Process event list List<CalendarEventModel> eventModels = new ArrayList<>(listResult.getItems().size()); for (Event eventData : listResult.getItems()) { CalendarEventModel model = convertToCalendarEventModel(id, eventData); eventModels.add(model); } CalendarContainerResource calendarContainerResource = new CalendarContainerResource(null, eventModels); // Get result type ExportResult.ResultType resultType = ResultType.CONTINUE; if (nextPageData == null) { resultType = ResultType.END; } return new ExportResult<>(resultType, calendarContainerResource, continuationData); }
Example #9
Source File: GoogleCalendarExporterTest.java From data-transfer-project with Apache License 2.0 | 4 votes |
/** Sets up a response for a single event */ private void setUpSingleEventResponse() throws IOException { eventListResponse = new Events().setItems(Collections.singletonList(EVENT)); when(eventListRequest.execute()).thenReturn(eventListResponse); }
Example #10
Source File: GetEventsWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public Events getAllEvents(com.google.api.services.calendar.Calendar client, String calendarId) throws IOException { return client.events().list(calendarId).execute(); }
Example #11
Source File: GCalEventDownloader.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * Connects to Google-Calendar Service and returns the specified Events * * @return the corresponding Events or <code>null</code> if an error * occurs. <i>Note:</i> We do only return events if their startTime lies between * <code>now</code> and <code>now + 2 * refreshInterval</code> to reduce * the amount of events to process. */ private static Events downloadEventFeed() { // TODO: teichsta: there could be more than one calendar url in openHAB.cfg // for now we accept this limitation of downloading just one feed ... if (StringUtils.isBlank(calendar_name)) { logger.warn("Login aborted no calendar name defined"); return null; } // authorization CalendarListEntry calendarID = GCalGoogleOAuth.getCalendarId(calendar_name); if (calendarID == null) { return null; } DateTime start = new DateTime(new Date(), TimeZone.getTimeZone(calendarID.getTimeZone())); DateTime end = new DateTime(new Date(start.getValue() + (2 * refreshInterval)), TimeZone.getTimeZone(calendarID.getTimeZone())); logger.debug("Downloading calendar feed for time interval: {} to {} ", start, end); Events feed = null; try { Credential credential = GCalGoogleOAuth.getCredential(false); // set up global Calendar instance Calendar client = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential) .setApplicationName("openHAB").build(); Calendar.Events.List l = client.events().list(calendarID.getId()).setSingleEvents(true).setTimeMin(start) .setTimeMax(end); // add the fulltext filter if it has been configured if (StringUtils.isNotBlank(filter)) { l = l.setQ(filter); } feed = l.execute(); } catch (IOException e1) { logger.error("Event fetch failed: {}", e1.getMessage()); } try { if (feed != null) { checkIfFullCalendarFeed(feed.getItems()); } return feed; } catch (Exception e) { logger.error("downloading CalendarEventFeed throws exception: {}", e.getMessage()); } return null; }