Java implementation of Cronofy API
Maven
<dependency>
<groupId>org.biacode.jcronofy</groupId>
<artifactId>jcronofy</artifactId>
<version>1.2.0</version>
</dependency>
Gradle
compile 'org.biacode.jcronofy:jcronofy:1.2.0'
Snapshot repository
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
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.
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>
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