All Projects → contentful → Contentful.java

contentful / Contentful.java

Licence: apache-2.0
Java SDK for Contentful's Content Delivery API

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Contentful.java

Easyhttp
Android 网络请求框架,简单易用,so easy
Stars: ✭ 423 (+571.43%)
Mutual labels:  okhttp, retrofit
Mvvmhabit
goldze: 本人喜欢尝试新的技术,以后发现有好用的东西,我将会在企业项目中实战,没有问题了就会把它引入到MVVMHabit中,一直维护着这套框架,谢谢各位朋友的支持。如果觉得这套框架不错的话,麻烦点个 star,你的支持则是我前进的动力!
Stars: ✭ 6,789 (+10676.19%)
Mutual labels:  okhttp, retrofit
Viabus Architecture
让 Android 开发可以像流水线一样高效的,职责分离架构 ⚡ 不同于 MVP 的配置解耦,也不能和 似是而非 的 MVVM - Clean 同日而语。VIABUS 是世界范围内首个明确提出,通过职责分离,来真正实现 UI 和 业务并行开发的 Android 项目级开发架构和设计模式理念。
Stars: ✭ 485 (+669.84%)
Mutual labels:  okhttp, retrofit
AndroidGo
Android、Flutter 开发者帮助 APP。包含事件分发、性能分析、Google Jetpack组件、OkHttp、RxJava、Retrofit、Volley、Canvas绘制以及优秀博文代码案例等内容,帮助开发者快速上手!
Stars: ✭ 30 (-52.38%)
Mutual labels:  retrofit, okhttp
Jetpackmvvm
🐔🏀一个Jetpack结合MVVM的快速开发框架,基于MVVM模式集成谷歌官方推荐的JetPack组件库:LiveData、ViewModel、Lifecycle、Navigation组件 使用Kotlin语言,添加大量拓展函数,简化代码 加入Retrofit网络请求,协程,帮你简化各种操作,让你快速开发项目
Stars: ✭ 1,100 (+1646.03%)
Mutual labels:  okhttp, retrofit
DaMaiProject
大麦界面,实现多种方式网络访问、数据缓存
Stars: ✭ 24 (-61.9%)
Mutual labels:  retrofit, okhttp
Easygank
💊 The project build framework based on the Rx series and MVP pattern.
Stars: ✭ 750 (+1090.48%)
Mutual labels:  okhttp, retrofit
Android-Model-View-Presenter
No description or website provided.
Stars: ✭ 26 (-58.73%)
Mutual labels:  retrofit, okhttp
Awesome Third Library Source Analysis
📖 Deep understanding of popular open source library source code (optimizing...)
Stars: ✭ 866 (+1274.6%)
Mutual labels:  okhttp, retrofit
Mvvmhabitcomponent
👕基于MVVMHabit框架,结合阿里ARouter打造的一套Android MVVM组件化开发方案
Stars: ✭ 857 (+1260.32%)
Mutual labels:  okhttp, retrofit
gv4j
Unofficial Google Voice API for Java.
Stars: ✭ 18 (-71.43%)
Mutual labels:  retrofit, okhttp
Meteorite
一个基于Android MVP的简单明了的指引性通用架构,目的是帮助更多的开发者去全面了解实践开发相关的各种技术,快速搭建属于自已的APP。这个项目涉及到如下技术的实际应用:1、MVP 2、网络请求(Novate基于rxjava,okhttp,retrofit封装架构)3、DbFlow(可保存文件入SD卡) 4、6.0权限申请 5、XRecyclerView 6、万能Adapter7、异常处理 8、日志打印 9、屏幕适配 10、代码混淆 11、多渠道打包 12、内存泄露检测 13、热修复 14、升级更新 15、极光推送 工程更新完善中……欢迎关注 @特别感谢ZJ.Y的Logo支持。
Stars: ✭ 49 (-22.22%)
Mutual labels:  okhttp, retrofit
WanAndroidJetpack
🔥 WanAndroid 客户端,Kotlin + MVVM + Jetpack + Retrofit + Glide。基于 MVVM 架构,用 Jetpack 实现,网络采用 Kotlin 的协程和 Retrofit 配合使用!精美的 UI,便捷突出的功能实现,欢迎下载体验!
Stars: ✭ 124 (+96.83%)
Mutual labels:  retrofit, okhttp
Mvvm Juejin
高仿"掘金Android App": databinding + kotlin + rx 的优雅实践。(持续打磨中~)
Stars: ✭ 403 (+539.68%)
Mutual labels:  okhttp, retrofit
RetrofitHelper
💪 RetrofitHelper是一个支持配置多个BaseUrl,支持动态改变BaseUrl,动态配置超时时长的Retrofit帮助类
Stars: ✭ 15 (-76.19%)
Mutual labels:  retrofit, okhttp
Retrofitcache
RetrofitCache让retrofit2+okhttp3+rxjava配置缓存如此简单。通过注解配置,可以针对每一个接口灵活配置缓存策略;同时让每一个接口方便支持数据模拟,可以代码减小侵入性,模拟数据可以从内存,Assets,url轻松获取。
Stars: ✭ 647 (+926.98%)
Mutual labels:  okhttp, retrofit
Kriptofolio
Free open source minimalistic cryptocurrencies portfolio app for Android.
Stars: ✭ 79 (+25.4%)
Mutual labels:  retrofit, okhttp
RxHttp
基于RxJava2+Retrofit+OkHttp4.x封装的网络请求类库,亮点多多,完美兼容MVVM(ViewModel,LiveData),天生支持网络请求和生命周期绑定,天生支持多BaseUrl,支持文件上传下载进度监听,支持断点下载,支持Glide和网络请求公用一个OkHttpClient⭐⭐⭐
Stars: ✭ 25 (-60.32%)
Mutual labels:  retrofit, okhttp
Androidall
Android 程序员需要掌握的技术栈:数据结构算法、程序架构、设计模式、性能优化、插件化、热更新、Kotlin、NDK、Jetpack,以及常用的开源框架源码分析如 Flutter、Router、RxJava、Glide、LeakCanary、Dagger2、Retrofit、OkHttp、ButterKnife 等
Stars: ✭ 849 (+1247.62%)
Mutual labels:  okhttp, retrofit
Easygo
基于Kotlin、OkHttp的声明式网络框架,像写HTML界面一样写网络调用代码
Stars: ✭ 40 (-36.51%)
Mutual labels:  okhttp, retrofit

Contentful Java SDK
Join Contentful Community Slack   Join Contentful Community Forum

contentful.java - Contentful Java Delivery SDK

Build Status codecov

Java SDK for Content Delivery API and Content Preview API. It helps in easily accessing the content stored in Contentful using Java applications.

What is Contentful?

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.

Table of contents

Core Features

Getting Started

Setup

Install the Contentful dependency:

  • Maven
<dependency>
  <groupId>com.contentful.java</groupId>
  <artifactId>java-sdk</artifactId>
  <version>10.4.5</version>
</dependency>
  • Gradle
compile 'com.contentful.java:java-sdk:10.4.5'

This SDK requires Java 8 (or higher version) or Android 21.

Client Creation

The CDAClient manages all interactions with the Content Delivery API.

CDAClient client = CDAClient.builder()
    .setSpace("{space-key-goes-here}")
    .setToken("{access-token-goes-here}")
    .build();

The Space-id and Access Token are retrived from the Contentful WebApp.

First Request

Fetching content is achieved by calling the CDAClient.fetch()-method. It fetches all Resources from a Space. The following code fetches all Entries:

// Fetch entries
CDAArray array = 
    client
        .fetch(CDAEntry.class)
        .all();

Usage

Filtering

Filtering of Resources can be done by chaining method calls after the .fetch(). Using .one() and a Resource id retrieves only the specifyied Resource:

CDAEntry entry =
    client
        .fetch(CDAEntry.class)
        .one("{entry-id-goes-here}");

Fetching only Entries of a specific Content Type is done by adding the .withContentType({id}) call to the chain:

CDAArray result = 
    client
        .fetch(CDAEntry.class)
        .withContentType("{content-type-id-goes-here}")
        .orderBy("{some-field-id-to-order-by-goes-here}")
        .all();

Finally fetching Assets follows the same principles:

// Fetch an Asset with a specific id
CDAAsset asset =
    client
        .fetch(CDAAsset.class)
        .one("{asset-id-goes-here}");

Calls in Parallel

All of the above examples are executed synchronously. In order to request asynchronously, provide a callback to .all(…) or .one(…):

client
    .fetch(CDAAsset.class)
    .all(new CDACallback<CDAArray>() {
  @Override protected void onSuccess(CDAArray result) {
    // ...
  }
});

Note: The return value for any asynchronous methods is the Callback itself, making sure keeping a reference to it and clearing it according to its host lifecycle events is adviced.

If RxJava is required instead, the .observe() method can be used to get an Observable instance:

client
    .observe(CDAAsset.class)
    .one("jake")
    .subscribe(System.out::println);

Paging

If more then 100 Resources are in the Space, .fetchAll() only returns the first 100. If more Resources are needed, specify the limit with the .limit(X) for example:

CDAArray result = 
  client
    .fetch(CDAEntry.class)
    .limit(1000)
    .all();

The maximum number of Resources to be requested is 1000.

For more then 1000 Resources .skip(N), .limit(L) and .orderBy(F) methods are needed. By using .skip(N), the first N Resources are ignored and L, from .limit(L), items are returned.

To guarantee ordering, the use of the .orderBy method is required: It enforces the Array to be in a predictable order.

The following code is used to request all Entries:

// get the amount of Entries, without fetching the actual content
final int amountOfResourcesInContentful = 
  client
    .fetch(CDAEntry.class)
    .limit(0)
    .all()
    .total();

// create storage for the Entries
final List<CDAResource> resources = new ArrayList<CDAResource>(amountOfResourcesInContentful);

// use page size, based on usecase
final int PAGE_SIZE = 2;

// loop through all pages and store results
for(int page = 0; page * PAGE_SIZE < amountOfResourcesInContentful; ++page) {
  final CDAArray currentPagedItems = client
      .fetch(CDAEntry.class)
      .skip(page * PAGE_SIZE)
      .limit(PAGE_SIZE)
      .orderBy("sys.createdAt")
      .all();

  // add to current list of Entries
  resources.addAll(currentPagedItems.items());
}

Using the .reverseOrderBy() method reverses the order:

CDAArray result = 
    client
        .fetch(CDAEntry.class)
        .limit(23)
        .reverseOrderBy("sys.createdAt")
        .all();

The above snippet will fetch the first 23 Entries, sorted by creation date with the latest ones on top.

Sync is used to fetch all entries in a single call and to get only changed Resources in following calls.

Includes

The SDK contains a feature called link resolution, which will take a link and resolve them. So there is no need to look through entry id's manually, a simple .getField(…) retrieves and entry directly, no need to use the link elements themselves.

For this feature to work, the linked entry needs to be published (see preview) and the include level needs to be set to include this entry. A level of 2 means, that the links of links are getting resolved. Entries of deeper levels contain an empty field if the link could not be resolved. Finding the id of the not resolved field can be achieved through comparing the .rawFields with the .fields property of an Entry.

In order to change the level of includes, the following snippet can be used as a guide:

CDAArray found = client.fetch(CDAEntry.class)
        .include(1) // maximum is 10
        .all();

This only resolves the first level of includes. 10 is the maximum number of levels to be included and should be used sparingly, since this will bloat up the response by a lot.

Unwrapping

Unwrapping is the process of taking a CDAEntry and transforming it into custom types. The following code demonstrates the definition of a custom type:

import com.contentful.java.cda.TransformQuery.ContentfulEntryModel;
import com.contentful.java.cda.TransformQuery.ContentfulField;

@ContentfulEntryModel("cat")
public static class Cat {
  @ContentfulField
  String name;

  @ContentfulField("bestFriend")
  Cat mate;

  @ContentfulField
  CDAEntry favoriteFood;

  @ContentfulSystemField("id")
  String contentfulId;

  @ContentfulField(value = "likes", locale = "de-DE")
  List<String> germanFavorites;
}

If this SDK should return a given response like the one above instead of a CDAEntry, the following code snippet will accomplish that:

Cat happycat = client
    .observeAndTransform(Cat.class)
    .one("happycat")
    .blockingFirst();

In addition to returning the Content in a fashion flexible for various use-cases, this feature also uses the select filter to only return the fields required, making the response smaller and more focused.

Notes:

  • Specifying a value for the @ContentfulField-annotation , will use the value of the similarly called field id instead of the name of the custom field.
  • A locale can be used to specify a given locale of this entry. If no locale is given, the default locale will be used.
  • @ContentfulSystemField is used for CDAEntries attributes (sys.id, etc) to be inserted.
  • Currently only one type is transformed. A cat cannot have another content type transformed. Using CDAEntries instead is recommended.

Select

The amount of data returned by the API can be reduced by using the .select() method on a query. With this, Contentful only returns the selected fields. The SDK enforces that the sys fields (.getAttribute() on an Entry) will always be returned, since it is used for the proper functioning of the SDK.

If reducing the payload size is wanted, the following snippet can explain how to accomplish that

CDAArray found = client.fetch(CDAEntry.class)
    .withContentType("cat");
    .select("fields.name");

This snippet makes sure that the entries of type cat are only containing its name field. All other fields will be null or its respective default value.

Note: The content type has to be added through .withContentType(…) otherwise an error ensues.

Preview

The Content Delivery API only returns published Entries. The Content Preview API will return all Entries, even not published ones:

CDAClient client = 
    CDAClient.builder()
        .setSpace("space-key-goes-here")
        .setToken("access-token-goes-here")
        .preview()
        .build();

The Preview Access Token is exposed on the Contentful Web App.

Note: In Preview, Resources can be invalid since no validation is performed prior to publishing.

Sync

Fetching all Resources and retrieving only changes on subsequent calls is accomplished by using the .sync()-methods:

SynchronizedSpace space = client.sync().fetch();

The SynchronizedSpace contains all published Resources. If .preview() (see Preview) is used, it also contains all unpublished Resources.

If changes are to be fetched later, calling sync() again using the given SynchronizedSpace as a parameter is needed:

SynchronizedSpace later = client.sync(space).fetch();

If an Entry gets deleted, its id is returned in theSynchronizedSpace.deletedEntries() set. Same is true for the deleted Assets through SynchronizedSpace.deletedAssets().

Http Client

Changing the settings of the http client, without losing the information setup in the client build process, is achieved by requesting the .defaultCallFactoryBuilder() from the CDAClient.Builder, changing it and then reapplying it:

// create a client builder as usual
CDAClient.Builder clientBuilder = CDAClient.builder()
        .setSpace("space-id-goes-here")
        .setEnvironment("environment-id-goes-here")  // optional
        .setToken("cda-token-goes-here");

// request the http client with the settings from above (token, error interceptor, etc)
OkHttpClient httpClient = clientBuilder.defaultCallFactoryBuilder()
        .addInterceptor(interceptor) // adding a custom interceptor
        .connectTimeout(5, TimeUnit.SECONDS) // adding a timeout 
        .cache(new Cache(new File("/tmp"), CACHE_SIZE_BYTES)) // adding a simple http cache
        .build();

// reapply the http changes and build a contentful client
CDAClient cdaClient = clientBuilder.setCallFactory(httpClient).build();

Proguard

The ProGuard configuration file is used to minify Android Apps using this SDK.

Rich Text renderer library

There is Java SDK for Rich Text API. It helps in easily rendering rich text stored in Contentful using Java.

Pre-releases

Development versions of this SDK are available through

maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
implementation 'com.contentful.java:java-sdk:10.4.1-SNAPSHOT'
maven { url 'https://jitpack.io' }
implementation 'com.github.contentful:contentful.java:java-sdk-10.4.1-SNAPSHOT'

Documentation

See

License

Copyright (c) 2019 Contentful GmbH. See LICENSE.txt for further details.

Reaching Contentful

Questions

  • Use the community forum: Contentful Community Forum
  • Use the community slack channel: Contentful Community Slack

Bugs and Feature Requests

  • File an issue here File an issue.

Sharing Confidential Information

  • File a support ticket at our Contentful Customer Support: File support ticket

Getting involved

PRs Welcome

Code of Conduct

Contentful wants to provide a safe, inclusive, welcoming, and harassment-free space and experience for all participants, regardless of their identity markers.

Full Code of Conduct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].