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.
- #live_preview_query(query = {}) ⇒ Object
-
#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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/contentstack/client.rb', line 13 def initialize(api_key, delivery_token, environment, ={}) raise Contentstack::Error.new(Contentstack::ErrorMessages::API_KEY_INVALID) if api_key.class != String raise Contentstack::Error.new(Contentstack::ErrorMessages::API_KEY_REQUIRED) if api_key.empty? raise Contentstack::Error.new(Contentstack::ErrorMessages::DELIVERY_TOKEN_INVALID) if delivery_token.class != String raise Contentstack::Error.new(Contentstack::ErrorMessages::DELIVERY_TOKEN_REQUIRED) if delivery_token.empty? raise Contentstack::Error.new(Contentstack::ErrorMessages::ENVIRONMENT_INVALID) if environment.class != String raise Contentstack::Error.new(Contentstack::ErrorMessages::ENVIRONMENT_REQUIRED) if environment.empty? @region = [:region].nil? ? Contentstack::Region::US : [:region] # @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host] #removed for not supporting custom host with regions @host = get_host_by_region(@region, ) # Added new method for custom host support with different regions @live_preview = !.key?(:live_preview) ? {} : [:live_preview] @branch = [:branch].nil? ? "" : [:branch] @proxy_details = [:proxy].nil? ? "" : [:proxy] @timeout = [:timeout].nil? ? 3000 : [:timeout] @retryDelay = [:retryDelay].nil? ? 3000 : [:retryDelay] @retryLimit = [:retryLimit].nil? ? 5 : [:retryLimit] @errorRetry = [:errorRetry].nil? ? [408, 429] : [:errorRetry] = { "timeout" => @timeout.to_s, "retryDelay"=> @retryDelay, "retryLimit"=> @retryLimit, "errorRetry" => @errorRetry } raise Contentstack::Error.new(Contentstack::ErrorMessages::PROXY_URL_REQUIRED) if @proxy_details.present? && @proxy_details[:url].empty? raise Contentstack::Error.new(Contentstack::ErrorMessages::PROXY_PORT_REQUIRED) if @proxy_details.present? && @proxy_details[:port].empty? API.init_api(api_key, delivery_token, environment, @host, @branch, @live_preview, @proxy_details, ) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/contentstack/client.rb', line 11 def host @host end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
11 12 13 |
# File 'lib/contentstack/client.rb', line 11 def region @region end |
Instance Method Details
#asset(uid) ⇒ Object
53 54 55 |
# File 'lib/contentstack/client.rb', line 53 def asset(uid) Asset.new(uid) end |
#assets ⇒ Object
49 50 51 |
# File 'lib/contentstack/client.rb', line 49 def assets AssetCollection.new end |
#content_type(uid) ⇒ Object
45 46 47 |
# File 'lib/contentstack/client.rb', line 45 def content_type(uid) ContentType.new({uid: uid}) end |
#content_types ⇒ Object
41 42 43 |
# File 'lib/contentstack/client.rb', line 41 def content_types ContentType.all end |
#live_preview_query(query = {}) ⇒ Object
57 58 59 |
# File 'lib/contentstack/client.rb', line 57 def live_preview_query(query={}) API.live_preview_query(query) 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': '<pagination>'}) // For fetching the next batch of entries using pagination token
Stack.sync({'sync_token': '<sync>'}) // For performing subsequent sync after initial sync
78 79 80 81 |
# File 'lib/contentstack/client.rb', line 78 def sync(params) sync_result = API.get_sync_items(params) SyncResult.new(sync_result) end |