Class Stack


  • public class Stack
    extends Object
    MIT License Copyright (c) 2012 - 2019 Contentstack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    • Field Detail

      • loggerLevel

        public static org.apache.log4j.Level loggerLevel
      • LOG_TAKE_OFF_STACKTRACE

        public static boolean LOG_TAKE_OFF_STACKTRACE
      • URLSCHEMA

        protected String URLSCHEMA
      • VERSION

        protected String VERSION
      • config

        protected Config config
      • SYNC_KEY

        protected String SYNC_KEY
      • content_type

        protected String content_type
      • sync_token

        protected String sync_token
      • pagination_token

        protected String pagination_token
      • contentType

        protected String contentType
      • localeCode

        protected String localeCode
      • start_from_date

        protected String start_from_date
    • Constructor Detail

      • Stack

        protected Stack​(String stackApiKey)
    • Method Detail

      • setConfig

        protected void setConfig​(Config config)
      • asset

        protected Asset asset()
      • getApplicationKey

        public String getApplicationKey()
      • getAccessToken

        public String getAccessToken()
      • removeHeader

        public void removeHeader​(String key)
      • setHeader

        public void setHeader​(String key,
                              String 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(context, "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​(ContentTypesCallback callback)
        Parameters:
        callback - ContentTypesCallback This call returns comprehensive information of all the content types available in a particular stack in your account.

        Example :
         stack.getContentTypes(false, new ContentTypesCallback() {
         public void onCompletion(ContentTypesModel contentTypesModel, Error error) {
         Stack.log(TAG,"contentTypesModel: "+ contentTypesModel.getResponseJSON());
         include_count = contentTypesModel.getCount();
        
         }
         });
        
      • 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) { }
        
        
         
      • log

        public static void log​(String TAG,
                               String logMsg)