Search in sources :

Example 1 with Booking

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();
    }
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) Calendar(com.google.api.services.calendar.Calendar) ArrayList(java.util.ArrayList) Booking(com.github.drbookings.core.datamodel.api.Booking) BookingBean(com.github.drbookings.core.datamodel.impl.BookingBean) FileDataStoreFactory(com.google.api.client.util.store.FileDataStoreFactory) CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) Events(com.google.api.services.calendar.model.Events) Event(com.google.api.services.calendar.model.Event) CalendarList(com.google.api.services.calendar.model.CalendarList)

Aggregations

Booking (com.github.drbookings.core.datamodel.api.Booking)1 BookingBean (com.github.drbookings.core.datamodel.impl.BookingBean)1 Credential (com.google.api.client.auth.oauth2.Credential)1 FileDataStoreFactory (com.google.api.client.util.store.FileDataStoreFactory)1 Calendar (com.google.api.services.calendar.Calendar)1 CalendarList (com.google.api.services.calendar.model.CalendarList)1 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)1 Event (com.google.api.services.calendar.model.Event)1 Events (com.google.api.services.calendar.model.Events)1 ArrayList (java.util.ArrayList)1