use of com.github.drbookings.core.datamodel.api.Booking in project drbookings by DrBookings.
the class RunnableImportGoogleCalendar method process.
@Override
protected List<Booking> process(final IProgressMonitor monitor) throws Exception {
try {
if (logger.isInfoEnabled()) {
logger.info("Adding from " + url);
}
// initialize the transport
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// initialize the data store factory
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
// authorization
final Credential credential = authorize();
// set up global Calendar instance
final Calendar client = new com.google.api.services.calendar.Calendar.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName("drbookings").build();
final CalendarList list = client.calendarList().list().execute();
String id = null;
for (final CalendarListEntry item : list.getItems()) {
if (item.getSummary().contains("airbnb")) {
id = item.getId();
}
}
final Events feed = client.events().list(id).execute();
final List<Booking> result = new ArrayList<>();
for (final Event item : feed.getItems()) {
System.out.println(item);
result.add(new BookingBean(item.getSummary(), LocalDate.parse(item.getStart().getDate().toString()), LocalDate.parse(item.getEnd().getDate().toString())));
}
return result;
} finally {
monitor.done();
}
}
Aggregations