Java implementation of Cronofy API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
.travis.yml
LICENSE
README.md
pom.xml

README.md

CI Status

Build Status SonarCube

jcronofy

Java implementation of Cronofy API

How to use

Installation

Maven

<dependency>
    <groupId>org.biacode.jcronofy</groupId>
    <artifactId>jcronofy</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle

compile 'org.biacode.jcronofy:jcronofy:1.0.0'

Getting started

First of all, you need any implementation of javax.ws.rs.client.Client For example you can use jersey client

Add the following dependency to your maven pom.xml file

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>${jersey.client.version}</version>
</dependency>

Then you need pass client implementation to CronofyClient as constructor param.

Example to construct client implementation in spring framework.

In application context XML add the following XML definition

<bean id="cronofyJerseyClientBuilder"
          class="org.biacode.jcronofy.api.configuration.impl.CronofyJerseyClientBuilderImpl"/>

<bean id="cronofyJerseyClient" factory-bean="cronofyJerseyClientBuilder" factory-method="build"/>

<bean id="cronofyClient" class="org.biacode.jcronofy.api.client.impl.CronofyClientImpl">
    <constructor-arg name="client" ref="cronofyJerseyClient"/>
</bean>

If you simply need to test cronofy API.

Then construct jersey client as follows

package my.application;

import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import org.biacode.jcronofy.api.client.CronofyClient;
import org.biacode.jcronofy.api.client.impl.CronofyClientImpl;
import org.biacode.jcronofy.api.model.common.CronofyResponse;
import org.biacode.jcronofy.api.model.request.ListCalendarsRequest;
import org.biacode.jcronofy.api.model.response.ListCalendarsResponse;

import javax.ws.rs.client.ClientBuilder;

public class MainApplication {
    public static void main(final String[] args) {
        // Construct cronofy java client
        final CronofyClient cronofyClient = new CronofyClientImpl(ClientBuilder.newBuilder().register(JacksonJsonProvider.class).build());
        // List calendars
        final CronofyResponse<ListCalendarsResponse> calendarsResult = cronofyClient.listCalendars(new ListCalendarsRequest("your access token here"));
        System.out.println(calendarsResult.getResponse().toString());
        // Read events
        final CronofyResponse<ReadEventsResponse> eventsResult = cronofyClient.readEvents(new ReadEventsRequest("your access token here", "Etc/UTC"));
        // If an error occur
        if (eventsResult.hasError()) {
            System.out.println(eventsResult.getError());
        } else {
            System.out.println(eventsResult.getResponse());
        }
    }
}

You can find test access token in Cronofy Calendar Sendbox