This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcaltaskwarrior.groovy
executable file
·76 lines (66 loc) · 2.82 KB
/
gcaltaskwarrior.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.security.GeneralSecurityException;
import java.util.List;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.CalendarScopes;
import com.google.api.services.calendar.model.CalendarListEntry;
import com.google.common.collect.ImmutableSet;
public class GoogleCalendarTaskWarrior {
public static void main(String[] args) throws IOException,
GeneralSecurityException {
Calendar client = getCalendarService();
System.out.println("Getting calendars...");
@SuppressWarnings("unchecked")
List<CalendarListEntry> allCalendars = (List<CalendarListEntry>) client
.calendarList().list().execute().get("items");
for (CalendarListEntry aCalendar : allCalendars) {
System.out.println(aCalendar.getSummary() + "::"
+ URLDecoder.decode(aCalendar.getId(), "UTF-8")
// + " :: " + aCalendar.toPrettyString()
// + " :: " + new JSONObject(aCalendar) + "\n"
);
}
}
/************************************************************************
* Boilerplate
************************************************************************/
private static Calendar getCalendarService()
throws GeneralSecurityException, IOException {
System.out.println("Authenticating...");
HttpTransport httpTransport = GoogleNetHttpTransport
.newTrustedTransport();
Calendar client = new Calendar.Builder(
httpTransport,
JacksonFactory.getDefaultInstance(),
new AuthorizationCodeInstalledApp(
new GoogleAuthorizationCodeFlow.Builder(
httpTransport,
JacksonFactory.getDefaultInstance(),
GoogleClientSecrets.load(
JacksonFactory.getDefaultInstance(),
new InputStreamReader(
GoogleCalendarTaskWarrior.class
.getResourceAsStream("/client_secrets.json"))),
ImmutableSet.of(CalendarScopes.CALENDAR,
CalendarScopes.CALENDAR_READONLY))
.setDataStoreFactory(
new FileDataStoreFactory(
new java.io.File(
System.getProperty("user.home"),
".store/calendar_sample")))
.build(), new LocalServerReceiver())
.authorize("user")).setApplicationName(
"gcal-task-warrior").build();
return client;
}
}