Class: Contentstack::Client
- Inherits:
-
Object
- Object
- Contentstack::Client
- Defined in:
- lib/contentstack/client.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Instance Method Summary collapse
- #asset(uid) ⇒ Object
- #assets ⇒ Object
- #content_type(uid) ⇒ Object
- #content_types ⇒ Object
-
#initialize(api_key, delivery_token, environment, options = {}) ⇒ Client
constructor
Initialize “Contentstack” Client instance.
-
#sync(params) ⇒ Object
Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates.
Constructor Details
#initialize(api_key, delivery_token, environment, options = {}) ⇒ Client
Initialize “Contentstack” Client instance
9 10 11 12 13 |
# File 'lib/contentstack/client.rb', line 9 def initialize(api_key, delivery_token, environment, ={}) @region = [:region].nil? ? Contentstack::Region::US : [:region] @host = [:host].nil? ? get_default_region_hosts(@region) : [:host] API.init_api(api_key, delivery_token, environment, @host) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/contentstack/client.rb', line 7 def host @host end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
7 8 9 |
# File 'lib/contentstack/client.rb', line 7 def region @region end |
Instance Method Details
#asset(uid) ⇒ Object
27 28 29 |
# File 'lib/contentstack/client.rb', line 27 def asset(uid) Asset.new(uid) end |
#assets ⇒ Object
23 24 25 |
# File 'lib/contentstack/client.rb', line 23 def assets AssetCollection.new end |
#content_type(uid) ⇒ Object
19 20 21 |
# File 'lib/contentstack/client.rb', line 19 def content_type(uid) ContentType.new({uid: uid}) end |
#content_types ⇒ Object
15 16 17 |
# File 'lib/contentstack/client.rb', line 15 def content_types ContentType.all end |
#sync(params) ⇒ Object
Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates
Stack.sync({'init': true}) // For initializing sync
Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
Stack.sync({'init': true, 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
Stack.sync({'init': true, 'content_type_uid': 'session'}) //For initializing sync with entries of a specific content type
Stack.sync({'init': true, 'type': 'entry_published'}) // 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'.
Stack.sync({'pagination_token': '<btlsomething>'}) // For fetching the next batch of entries using pagination token
Stack.sync({'sync_token': '<btlsomething>'}) // For performing subsequent sync after initial sync
49 50 51 52 |
# File 'lib/contentstack/client.rb', line 49 def sync(params) sync_result = API.get_sync_items(params) SyncResult.new(sync_result) end |