Client

View as Markdown

Client

Initialize an instance of ‘Client’
NameTypeDescription
api_key (required)string
Stack API Key.
delivery_token (required)string
Stack Delivery token.
environment (required)string

Stack Environment name.

assets

Retrieves all assets of a stack by default.

require "contentstack";


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment");

@assets = @stack.assets.fetch;

asset

Retrieve a single asset with its UID.

NameTypeDescription
uidstring

The asset uid

require "contentstack";


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment");

@asset = @stack.asset("asset_uid").fetch;

content_types

This method returns comprehensive information of all the content types of a particular stack in your account.

require "contentstack";


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment");

@content_types = @stack.content_types;

content_type

Set the content type of which you want to retrieve the entries
NameTypeDescription
content_type_uidstring

UID of the existing content type

require "contentstack";


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment");

@content_type = @stack.content_type("content_type_uid");

live_preview_query

For live preview data to be fetched provide query parameter to this function

NameTypeDescription
queryobject

Query parameter for live preview contents.

require "contentstack";


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment");

@stack.live_preview_query({

	"live_preview": "live_preview_hash",

	"content_type_uid": "content_type_uid",

	"entry_uid": "entry_uid"

});

sync

Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates
NameTypeDescription
param.initboolean
initializing sync
param.localestring
initializing sync with entries of a specific locale
param.start_datestringDefault: initializing sync with entries published after a specific date
param.content_type_uidstring

initializing sync with entries of a specific content type

param.typestring

Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'

param.pagination_tokenstring

Fetching the next batch of entries using pagination token

param.sync_tokenstring

Performing subsequent sync after initial sync

For initializing sync:

require "contentstack";


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment");

@result = @stack..sync({'init': true});

For initializing sync with entries of a specific locale:

sync({'init': true, 'locale': 'en-us'});

For initializing sync with entries published after a specific date:

require "contentstack"; 


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment"); 

@result = @stack.sync({'init': true<span>,</span><span> </span><span>'start_date'</span><span>:</span><span> </span><span>'2018-10-22'</span>});

For initializing sync with entries of a specific content type:

require "contentstack"; 


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment"); 

@result = @stack.sync({'init': true, 'content_type_uid': 'session'});

For initializing sync with specific type:

require "contentstack"; 


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment"); 

@result = @stack.sync({'init': true, 'type': 'entry_published'});

For fetching the next batch of entries using pagination token:

require "contentstack"; 


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment"); 

@result = @stack.sync({'pagination_token': '<page_token>'});

For performing subsequent sync after initial sync:

require "contentstack"; 


@stack = Contentstack::Client.new("api_key", "delivery_token", "environment"); 

@result = @stack.sync({'sync_token': '<sync_token>'})