Loading repository data…
Loading repository data…
contentful / repository
Java library for using the Contentful Content Management API
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
Java SDK for Content Management API. It helps in editing and creating content stored in Contentful with Java applications.
Contentful provides a content infrastructure for digital teams to power content in websites, apps, and devices. Contentful, unlike any other CMS, is built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.
Install the Contentful dependency:
<dependency>
<groupId>com.contentful.java</groupId>
<artifactId>cma-sdk</artifactId>
<version>3.4.23</version>
</dependency>
compile 'com.contentful.java:cma-sdk:3.4.23'
This SDK requires Java 8 (or higher version).
The CMAClient manages all interactions with the Content Management API.
final CMAClient client =
new CMAClient
.Builder()
.setAccessToken("<access_token>")
.build();
The Access Token can easily be obtained through the management API documentation.
By selecting a Module, say .entries() and using its manipulator methods, like .fetchAll(), changes can be applied to the underlying resources. Resources can be fetched as following:
final CMAArray<CMAEntry> array =
client
.entries()
.fetchAll();
A client performs various operations on different types of Resources (such as Assets, Content Types, Entries, Spaces, etc). Every type of Resource is represented by a Module in the CMAClient class, for example:
client.spaces() // returns the Spaces Module
client.entries() // returns the Entries Module
client.assets() // returns the Assets Module
…
Each Module contains a set of methods that perform various operations on the specified Resource type. Every method has a corresponding asynchronous extension which can be accessed through the async() method of the Module, for example the following synchronous call
final CMAArray<CMASpace> array =
client
.spaces()
.fetchAll(
"space_id",
"environment_id"
);
can be expressed by this asynchronous call:
final CMAArray<CMASpace> array =
client
.spaces()
.async()
.fetchAll(
"space_id",
"environment_id",
new CMACallback<CMAArray<CMASpace>>() {
@Override protected void onSuccess(CMAArray<CMASpace> result) {
// success
}
@Override protected void onFailure(RetrofitError retrofitError) {
// failure
}
});
Note: The default
CMACallbackhas an emptyonFailure()implementation. If failures are of interest, overriding this method is mandatory.
Note: [The CMA documentation][docs] offers more code snippets for all Modules.
Instead of repeating the Space and _Environment _ids with every call like so
final CMAArray<CMAEntry> array =
client
.entries()
.fetchAll(
"space_id",
"environment_id",
);
the client can be configured to always use the same values:
final CMAClient client =
new CMAClient
.Builder()
.setAccessToken("<access_token>")
.setSpaceId("<space_id>")
.setEnvironmentId("<environment_id>")
.build();
This changes the parameters Modules are using:
final CMAArray<CMAEntry> array =
client
.entries()
.fetchAll();
Words of warning
The Modules apiKeys, environments, roles, spaceMemberships, uiExtensions, uploads, and webhooks, do not support Environments different to master. If the above configuration is used with these Modules, they throw an exception. Creation of a new client without specifying an Environment id is needed:
final CMAArray<CMAApiKey> array =
client
.apiKeys()
.fetchAll(
"spaceid"
);
The SDK uses [Retrofit][2] as a REST client, which detects [OkHttp][3] in the classpath and uses it if available, or else it falls back to the default HttpURLConnection.
The recommended approach would be to add [OkHttp][3] as a dependency to your project, but that is completely optional.
It is possible to specify a custom client to be used, refer to the [official documentation][4] for instructions.
In order to create and update rich text fields, the following rule set is enforced from Contentful:
For supported and tested combinations of Nodes, please take a look at the Rich Text End to End tests, those will be kept updated over time and should give an overview on what is possible.
Snapshots of the development version are available through
snapshots repository][snap]maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
compile 'com.contentful.java:cma-sdk:3.3.3-SNAPSHOT'
maven { url 'https://jitpack.io' }
compile 'com.github.contentful:contentful.java:cma-sdk-3.3.3-SNAPSHOT'
See
Copyright (C) 2019 Contentful GmbH. See LICENSE.txt for further details.