Class Stack

java.lang.Object
com.contentstack.sdk.Stack

public class Stack
extends Object
A stack is a repository or a container that holds all the content/assets of your site. It allows multiple users to create, edit, approve, and publish their content within a single space.
  • Field Details

  • Constructor Details

  • Method Details

    • setConfig

      protected void setConfig​(Config config)
    • contentType

      public ContentType contentType​(String contentTypeName)
    • asset

      public Asset asset​(String uid)
      Takes asset uid as a parameter and returns @Asset instance
      Parameters:
      uid - uid of Asset
      Returns:
      Asset instance
    • asset

      protected Asset asset()
    • assetLibrary

      public AssetLibrary assetLibrary()
      assetLibrary returns AssetLibrary instance
      Returns:
    • getApplicationKey

      public String getApplicationKey()
      Returns apiKey of particular stack
      Returns:
    • getAccessToken

      public String getAccessToken()
      Returns accessToken of particular stack
      Returns:
    • removeHeader

      public void removeHeader​(String key)
      Removes Header by key
      Parameters:
      key -
    • setHeader

      public void setHeader​(String key, String value)
      Adds header to the stack by key and value
      Parameters:
      key -
      value -
    • ImageTransform

      public String ImageTransform​(String image_url, LinkedHashMap<String,​Object> parameters)
      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
      Returns:
      String ImageTransform function is define for image manipulation with different parameters in second parameter in array form

      Example :
        //'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);
    • getContentTypes

      public void getContentTypes​(org.json.JSONObject params, ContentTypesCallback callback)
      Parameters:
      params - query parameters
      callback - ContentTypesCallback This call returns comprehensive information of all the content types available in a particular stack in your account.

      Example :
      
       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.
        }
       }
       });
      
    • sync

      public void sync​(SyncResultCallBack syncCallBack)
      Parameters:
      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.

      Example :
      
       stack.sync(SyncResultCallBack syncCallBack){  }
      
       
    • syncPaginationToken

      public void syncPaginationToken​(String pagination_token, SyncResultCallBack syncCallBack)
      Parameters:
      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.

      Example :
      
       // dummy pagination_token = "blt7f35951d259183fba680e1";
         stack.syncPaginationToken(pagination_token, new SyncResultCallBack()) {}
      
      
       
    • syncToken

      public void syncToken​(String sync_token, SyncResultCallBack syncCallBack)
      Parameters:
      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.

      Example :
      
        //dummy sync_token = "blt28937206743728463";
        stack.syncToken(sync_token, new SyncResultCallBack() ){ }
      
       
    • syncFromDate

      public void syncFromDate​(Date from_date, SyncResultCallBack syncCallBack)
      Parameters:
      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.

      Example :
      
         // dummy date final Date start_date = sdf.parse("2018-10-07");
         stack.syncFromDate(start_date, new SyncResultCallBack()) { }
      
      
        
    • syncContentType

      public void syncContentType​(String content_type, SyncResultCallBack syncCallBack)
      Parameters:
      content_type - Provide uid of your content_type
      syncCallBack - 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.

      Example :
      
       // dummy content_type like "session"
       stack.syncContentType(String content_type, new SyncResultCallBack()){  }
      
        
    • syncLocale

      public void syncLocale​(Language language, SyncResultCallBack syncCallBack)
      Parameters:
      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.

      Example :
      
       // dummy language- Language.ENGLISH_UNITED_STATES
       stackInstance.syncLocale(Language.ENGLISH_UNITED_STATES, new SyncResultCallBack() ) { }
      
       
    • syncPublishType

      public void syncPublishType​(Stack.PublishType type, SyncResultCallBack syncCallBack)
      Parameters:
      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.

      Example :
      
         stackInstance.syncPublishType(Stack.PublishType.entry_published, new SyncResultCallBack()) { }
      
        
    • sync

      public void sync​(String contentType, Date from_date, Language language, Stack.PublishType type, SyncResultCallBack syncCallBack)
      Parameters:
      contentType - your content type id
      from_date - start date
      language - language as Language
      type - type as PublishType
      syncCallBack - 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

      Example :
      
        stackInstance.sync(String contentType, Date from_date, Language language, PublishType type,  SyncResultCallBack syncCallBack) { }