public class Stack extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Stack.PublishType |
| Modifier and Type | Field and Description |
|---|---|
protected Config |
config |
protected String |
content_type |
protected String |
contentType |
protected HashMap<String,Object> |
headerGroup_app |
protected String |
localeCode |
protected LinkedHashMap<String,Object> |
localHeader |
protected String |
pagination_token |
protected Stack.PublishType |
publishType |
protected String |
start_from_date |
protected String |
SYNC_KEY |
protected String |
sync_token |
protected String |
URL |
protected String |
URLSCHEMA |
protected String |
VERSION |
| Modifier | Constructor and Description |
|---|---|
protected |
Stack(String stackApiKey) |
| Modifier and Type | Method and Description |
|---|---|
protected Asset |
asset() |
Asset |
asset(String uid)
Takes asset uid as a parameter and returns @
Asset instance |
AssetLibrary |
assetLibrary()
assetLibrary returns AssetLibrary instance
|
ContentType |
contentType(String contentTypeName) |
String |
getAccessToken()
Returns accessToken of particular stack
|
String |
getApplicationKey()
Returns apiKey of particular stack
|
void |
getContentTypes(org.json.JSONObject params,
ContentTypesCallback callback) |
String |
ImageTransform(String image_url,
LinkedHashMap<String,Object> parameters) |
void |
removeHeader(String key)
Removes Header by key
|
protected void |
setConfig(Config config) |
void |
setHeader(String key,
String value)
Adds header to the stack by key and value
|
void |
sync(String contentType,
Date from_date,
Language language,
Stack.PublishType type,
SyncResultCallBack syncCallBack) |
void |
sync(SyncResultCallBack syncCallBack) |
void |
syncContentType(String content_type,
SyncResultCallBack syncCallBack) |
void |
syncFromDate(Date from_date,
SyncResultCallBack syncCallBack) |
void |
syncLocale(Language language,
SyncResultCallBack syncCallBack) |
void |
syncPaginationToken(String pagination_token,
SyncResultCallBack syncCallBack) |
void |
syncPublishType(Stack.PublishType type,
SyncResultCallBack syncCallBack) |
void |
syncToken(String sync_token,
SyncResultCallBack syncCallBack) |
protected LinkedHashMap<String,Object> localHeader
protected String URLSCHEMA
protected String URL
protected String VERSION
protected Config config
protected String SYNC_KEY
protected String content_type
protected String sync_token
protected String pagination_token
protected String contentType
protected String localeCode
protected Stack.PublishType publishType
protected String start_from_date
protected Stack(String stackApiKey)
protected void setConfig(Config config)
public ContentType contentType(String contentTypeName)
public Asset asset(String uid)
Asset instanceuid - uid of Assetprotected Asset asset()
public AssetLibrary assetLibrary()
public String getApplicationKey()
public String getAccessToken()
public void removeHeader(String key)
key - header key
public void setHeader(String key, String value)
key - header keyvalue - header value
Example stack.setHeader("delivery_token","blt843748744");
public String ImageTransform(String image_url, LinkedHashMap<String,Object> parameters)
image_url - on which we want to manipulate.parameters - It is an second parameter in which we want to place different manipulation key and value in array form
//'blt5d4sample2633b' is a dummy Stack API key
//'blt6d0240b5sample254090d' is dummy access token.
Stack stack = Contentstack.stack("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag", false);
// resize the image by specifying width and height
LinkedHashMap imageParams = new LinkedHashMap();
imageParams.put("width", 100);
imageParams.put("height",100);
imageUrl = Stack.ImageTransform(image_url, parameters);
stack.ImageTransform(image_url, parameters);
public void getContentTypes(org.json.JSONObject params,
ContentTypesCallback callback)
params - query parameterscallback - ContentTypesCallback
This call returns comprehensive information of all the content types available in a particular stack in your account.
JSONObject params = new JSONObject();
params.put("include_snippet_schema", true);
params.put("limit", 3);
stack.getContentTypes(new ContentTypesCallback() {
public void onCompletion(ContentTypesModel contentTypesModel, Error error) {
if (error == null){
// do your stuff.
}
}
});
public void sync(SyncResultCallBack syncCallBack)
syncCallBack - returns callback for sync result.
The Sync request performs a complete sync of your app data.
It returns all the published entries and assets of the specified stack in response.
The response also contains a sync token, which you need to store,
since this token is used to get subsequent delta updates later.
stack.sync(SyncResultCallBack syncCallBack){ }
public void syncPaginationToken(String pagination_token, SyncResultCallBack syncCallBack)
pagination_token - If the response is paginated, use the pagination token under this parameter.syncCallBack - returns callback for sync result
If the result of the initial sync (or subsequent sync) contains more than 100 records,
the response would be paginated. It provides pagination token in the response. However,
you do not have to use the pagination token manually to get the next batch,
the SDK does that automatically until the sync is complete.
Pagination token can be used in case you want to fetch only selected batches.
It is especially useful if the sync process is interrupted midway (due to network issues, etc.).
In such cases, this token can be used to restart the sync process from where it was interrupted.
// dummy pagination_token = "blt7f35951d259183fba680e1";
stack.syncPaginationToken(pagination_token, new SyncResultCallBack()) {}
public void syncToken(String sync_token, SyncResultCallBack syncCallBack)
sync_token - Use the sync token that you received in the previous/initial sync under this parameter.syncCallBack - returns callback for sync result
You can use the sync token (that you receive after initial sync) to get the updated content next time.
The sync token fetches only the content that was added after your last sync,
and the details of the content that was deleted or updated.
//dummy sync_token = "blt28937206743728463";
stack.syncToken(sync_token, new SyncResultCallBack() ){ }
public void syncFromDate(Date from_date, SyncResultCallBack syncCallBack)
from_date - Enter the start date for initial sync.syncCallBack - Returns callback for sync result.
You can also initialize sync with entries published after a specific date. To do this, use syncWithDate
and specify the start date as its value.
// dummy date final Date start_date = sdf.parse("2018-10-07");
stack.syncFromDate(start_date, new SyncResultCallBack()) { }
public void syncContentType(String content_type, SyncResultCallBack syncCallBack)
content_type - Provide uid of your content_typesyncCallBack - Returns callback for sync result.
You can also initialize sync with entries of only specific content_type.
To do this, use syncContentType and specify the content type uid as its value.
However, if you do this, the subsequent syncs will only include the entries of the specified content_type.
// dummy content_type like "session"
stack.syncContentType(String content_type, new SyncResultCallBack()){ }
public void syncLocale(Language language, SyncResultCallBack syncCallBack)
language - Select the required locale from the Language class.syncCallBack - Returns callback for sync result.
You can also initialize sync with entries of only specific locales.
To do this, use syncLocale and specify the locale code as its value.
However, if you do this, the subsequent syncs will only include the entries of the specified locales.
// dummy language- Language.ENGLISH_UNITED_STATES
stackInstance.syncLocale(Language.ENGLISH_UNITED_STATES, new SyncResultCallBack() ) { }
public void syncPublishType(Stack.PublishType type, SyncResultCallBack syncCallBack)
type - - Use the type parameter to get a specific type of content
like ( asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted, content_type_deleted.)syncCallBack - returns callback for sync result.
Use the type parameter to get a specific type of content. You can pass one of the following values:
asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted, content_type_deleted.
If you do not specify any value, it will bring all published entries and published assets.
stackInstance.syncPublishType(Stack.PublishType.entry_published, new SyncResultCallBack()) { }
public void sync(String contentType, Date from_date, Language language, Stack.PublishType type, SyncResultCallBack syncCallBack)
contentType - your content type idfrom_date - start datelanguage - language as Languagetype - type as PublishTypesyncCallBack - Callback
You can also initialize sync with entries that satisfy multiple parameters.
To do this, use syncWith and specify the parameters.
However, if you do this, the subsequent syncs will only include the entries of the specified parameters
stackInstance.sync(String contentType, Date from_date, Language language, PublishType type, SyncResultCallBack syncCallBack) { }
Copyright © 2021 Contentstack.. All rights reserved.