contentstack 0.0.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +4 -0
- data/CHANGELOG.md +54 -0
- data/CODE_OF_CONDUCT.md +1 -2
- data/Gemfile +8 -0
- data/Gemfile.lock +61 -0
- data/LICENSE.txt +1 -1
- data/README.md +108 -11
- data/contentstack.gemspec +1 -1
- data/lib/contentstack.rb +8 -3
- data/lib/contentstack/api.rb +18 -8
- data/lib/contentstack/client.rb +41 -5
- data/lib/contentstack/content_type.rb +1 -1
- data/lib/contentstack/entry.rb +169 -2
- data/lib/contentstack/query.rb +14 -0
- data/lib/contentstack/region.rb +6 -0
- data/lib/contentstack/sync_result.rb +30 -0
- data/lib/contentstack/version.rb +1 -1
- data/spec/content_type_spec.rb +17 -0
- data/spec/contentstack_spec.rb +22 -0
- data/spec/entry_spec.rb +69 -3
- data/spec/fixtures/category_content_type.json +1 -0
- data/spec/fixtures/category_entry.json +1 -1
- data/spec/fixtures/product_entry.json +1 -1
- data/spec/fixtures/sync_init.json +2975 -0
- data/spec/query_spec.rb +6 -1
- data/spec/spec_helper.rb +20 -3
- data/spec/sync_spec.rb +27 -0
- metadata +12 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed2009d779c953b80883a4d8c8d267cca918c3a784450513643f308ae79645c1
|
4
|
+
data.tar.gz: 4a48fc25a61c332e8f338941828b87836db709eb0c7f819b5e926f1d264ae5d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c74b89fabfe984e5d068cc6a1c1dcf40b8d098730959677572e71f7f6c0f989bd82d131b87f23f66f83a80c73104197fa008d7ba3685baaf491f2fe214f829a
|
7
|
+
data.tar.gz: e3d42fd8f4fc573a08dae949fe85d0576a7bc9290e724941468439f8afe4093f979b7f992c0572667e0942fe7a9c262ca8b3c42d13f5a7d8c762c9e02695f39a
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
## CHANGELOG
|
2
|
+
------------------------------------------------
|
3
|
+
|
4
|
+
## Version 0.3.0
|
5
|
+
### Date: 17th-Mar-2021
|
6
|
+
### New Features
|
7
|
+
- Sync API module support added
|
8
|
+
|
9
|
+
------------------------------------------------
|
10
|
+
## Version 0.2.0
|
11
|
+
|
12
|
+
### New Features
|
13
|
+
- Entry
|
14
|
+
- locale - function for passing locale is added
|
15
|
+
- only - function for getting only specified field
|
16
|
+
- except - function for getting field except specified field
|
17
|
+
- include_reference - function for including reference in entry
|
18
|
+
- include_schema - function for including schema along with entry added
|
19
|
+
- include_content_type - function for including content type details along with entry added
|
20
|
+
- include_owner - function for getting owner of entry
|
21
|
+
- include_fallback - function for getting published fallback locale content, if specified locale content is not published
|
22
|
+
|
23
|
+
- Query
|
24
|
+
- include_fallback - function for getting published fallback locale content, if specified locale content is not published
|
25
|
+
|
26
|
+
|
27
|
+
------------------------------------------------
|
28
|
+
|
29
|
+
## Version 0.1.0
|
30
|
+
|
31
|
+
### Bug
|
32
|
+
- Stack Tokens Moved to Headers
|
33
|
+
|
34
|
+
------------------------------------------------
|
35
|
+
|
36
|
+
## Version 0.0.4
|
37
|
+
|
38
|
+
### Enhancement
|
39
|
+
- Region support added
|
40
|
+
|
41
|
+
------------------------------------------------
|
42
|
+
|
43
|
+
## Version 0.0.3
|
44
|
+
|
45
|
+
### Enhancement
|
46
|
+
- Query - function for passing locale is added.
|
47
|
+
|
48
|
+
------------------------------------------------
|
49
|
+
|
50
|
+
## Version 0.0.1
|
51
|
+
|
52
|
+
- Initial release
|
53
|
+
|
54
|
+
------------------------------------------------
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -22,8 +22,7 @@ include:
|
|
22
22
|
|
23
23
|
Examples of unacceptable behavior by participants include:
|
24
24
|
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
27
26
|
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
27
|
* Public or private harassment
|
29
28
|
* Publishing others' private information, such as a physical or electronic
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (6.0.3.1)
|
5
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
|
+
i18n (>= 0.7, < 2)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
tzinfo (~> 1.1)
|
9
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
concurrent-ruby (1.1.6)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
docile (1.3.2)
|
17
|
+
hashdiff (1.0.1)
|
18
|
+
i18n (1.8.2)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
minitest (5.14.1)
|
21
|
+
public_suffix (4.0.4)
|
22
|
+
rspec (3.9.0)
|
23
|
+
rspec-core (~> 3.9.0)
|
24
|
+
rspec-expectations (~> 3.9.0)
|
25
|
+
rspec-mocks (~> 3.9.0)
|
26
|
+
rspec-core (3.9.1)
|
27
|
+
rspec-support (~> 3.9.1)
|
28
|
+
rspec-expectations (3.9.1)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.9.0)
|
31
|
+
rspec-mocks (3.9.1)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.9.0)
|
34
|
+
rspec-support (3.9.2)
|
35
|
+
safe_yaml (1.0.5)
|
36
|
+
simplecov (0.18.5)
|
37
|
+
docile (~> 1.1)
|
38
|
+
simplecov-html (~> 0.11)
|
39
|
+
simplecov-html (0.12.2)
|
40
|
+
thread_safe (0.3.6)
|
41
|
+
tzinfo (1.2.7)
|
42
|
+
thread_safe (~> 0.1)
|
43
|
+
webmock (3.8.3)
|
44
|
+
addressable (>= 2.3.6)
|
45
|
+
crack (>= 0.3.2)
|
46
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
47
|
+
yard (0.9.25)
|
48
|
+
zeitwerk (2.3.0)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
activesupport
|
55
|
+
rspec
|
56
|
+
simplecov
|
57
|
+
webmock
|
58
|
+
yard
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
2.1.4
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2012-2021 Contentstack. All Rights Reserved
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -19,8 +19,16 @@ Or you can run this command in your terminal (you might need administrator privi
|
|
19
19
|
gem install contentstack
|
20
20
|
|
21
21
|
To start using the SDK in your application, you will need to initialize the stack by providing the values for the keys given in the code snippet below.
|
22
|
-
|
23
|
-
|
22
|
+
```ruby
|
23
|
+
# with default region
|
24
|
+
client = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name")
|
25
|
+
|
26
|
+
# with specific region
|
27
|
+
client = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name",{"region": Contentstack::Region::EU})
|
28
|
+
|
29
|
+
# with custom host
|
30
|
+
client = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name",{"host": "https://custom-cdn.contentstack.com"})
|
31
|
+
```
|
24
32
|
|
25
33
|
## **Key Concepts for using Contentstack**
|
26
34
|
|
@@ -46,23 +54,44 @@ A publishing environment corresponds to one or more deployment servers or a cont
|
|
46
54
|
|
47
55
|
## **Contentstack Ruby SDK: 5-minute Quickstart**
|
48
56
|
|
49
|
-
### **Initializing your SDK
|
57
|
+
### **Initializing your SDK**
|
50
58
|
|
51
59
|
To initialize the SDK, you need to provide values for the keys given in the snippet below:
|
52
|
-
|
53
|
-
|
60
|
+
```ruby
|
61
|
+
@stack = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name")
|
62
|
+
```
|
54
63
|
|
55
64
|
To get the API credentials mentioned above, log in to your Contentstack account and then in your top panel navigation, go to Settings > Stack to view the API Key and Access Token.
|
56
65
|
|
57
66
|
### **Querying content from your stack**
|
58
67
|
|
59
68
|
To fetch all entries of of a content type, use the query given below:
|
60
|
-
|
61
|
-
|
69
|
+
```ruby
|
70
|
+
@entry = stack.content_type(<<CONTENT_TYPE_UID>>).query();
|
71
|
+
```
|
62
72
|
|
63
73
|
To fetch a specific entry from a content type, use the following query:
|
64
|
-
|
65
|
-
|
74
|
+
```ruby
|
75
|
+
@entry = stack.content_type(<<CONTENT_TYPE_UID>>).entry(<<ENTRY_UID>>);
|
76
|
+
```
|
77
|
+
|
78
|
+
### Get Multiple Entries
|
79
|
+
To retrieve multiple entries of a content type, specify the content type UID. You can also specify search parameters to filter results:
|
80
|
+
```ruby
|
81
|
+
@query = @stack.content_type('blog').query
|
82
|
+
@entries = @query.where('title', 'welcome')
|
83
|
+
.include_schema
|
84
|
+
.include_count
|
85
|
+
.fetch
|
86
|
+
puts "Total Entries -- #{@entries.count}"
|
87
|
+
@entries.each{|entry| puts "#{entry.get('title')}" }
|
88
|
+
```
|
89
|
+
|
90
|
+
To retrieve localized versions of entries, you can use the query attribute:
|
91
|
+
```ruby
|
92
|
+
entry = @stack.content_type('content_type_uid').query.locale('locale_code').fetch()
|
93
|
+
```
|
94
|
+
> Note: Currently, the above query works in case of retrieving localized versions of multiple entries only.
|
66
95
|
|
67
96
|
## **Advanced Queries**
|
68
97
|
|
@@ -70,6 +99,19 @@ You can query for content types, entries, assets and more using our Ruby API Ref
|
|
70
99
|
|
71
100
|
[Ruby API Reference Doc](http://www.rubydoc.info/gems/contentstack)
|
72
101
|
|
102
|
+
### Paginating Responses
|
103
|
+
In a single instance, the [Get Multiple Entries](https://www.contentstack.com/docs/developers/ruby/get-started-with-ruby-sdk/#get-multiple-entries) query will retrieve only the first 100 items of the specified content type. You can paginate and retrieve the rest of the items in batches using the [skip](https://www.rubydoc.info/gems/contentstack/Contentstack/Query#skip-instance_method) and [limit](https://www.rubydoc.info/gems/contentstack/Contentstack/Query#limit-instance_method) parameters in subsequent requests.
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
@stack = Contentstack::Client.new("api_key", "delivery_token", "environment")
|
107
|
+
@entries = @stack.content_type('category').query
|
108
|
+
.limit(20)
|
109
|
+
.skip(50)
|
110
|
+
.fetch
|
111
|
+
```
|
112
|
+
|
113
|
+
> Note: Currently, the Ruby SDK does not support multiple content types referencing in a single query. For more information on how to query entries and assets, refer the Queries section of our Content Delivery API documentation.
|
114
|
+
|
73
115
|
## **Working with Images**
|
74
116
|
|
75
117
|
We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.
|
@@ -78,8 +120,63 @@ For example, if you want to crop an image (with width as 300 and height as 400),
|
|
78
120
|
|
79
121
|
[Read Image Delivery API documentation](https://www.contentstack.com/docs/apis/image-delivery-api/).
|
80
122
|
|
81
|
-
SDK functions for Image Delivery API coming soon.
|
82
123
|
|
124
|
+
## **Using the Sync API with Ruby SDK**
|
125
|
+
|
126
|
+
The Sync API takes care of syncing your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates. Contentstack’s Ruby SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack Ruby SDK.
|
127
|
+
[Read Sync API documentation](https://www.contentstack.com/docs/platforms/ruby#using-the-sync-api-with-ruby-sdk).
|
128
|
+
|
129
|
+
### Initial sync
|
130
|
+
|
131
|
+
The Initial Sync process performs a complete sync of your app data. It returns all the published entries and assets of the specified stack in response.
|
132
|
+
|
133
|
+
To start the Initial Sync process, use the syncStack method.
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
@sync_result = @stack.sync({init: true})
|
137
|
+
# @sync_result.items: contains sync data
|
138
|
+
# @sync_result.pagination_token: for fetching the next batch of entries using pagination token
|
139
|
+
# @sync_result.sync_token: for performing subsequent sync after initial sync
|
140
|
+
```
|
141
|
+
|
142
|
+
The response also contains a sync token, which you need to store, since this token is used to get subsequent delta updates later, as shown in the Subsequent Sync section below.
|
143
|
+
|
144
|
+
You can also fetch custom results in initial sync by using advanced sync queries.
|
145
|
+
|
146
|
+
### Sync pagination
|
147
|
+
|
148
|
+
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. You will need to use this token to get the next batch of data.
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
@sync_result = @stack.sync({pagination_token : "<pagination_token>"})
|
152
|
+
# @sync_result.items: contains sync data
|
153
|
+
# @sync_result.pagination_token: For fetching the next batch of entries using pagination token
|
154
|
+
# @sync_result.sync_token: For performing subsequent sync after initial sync
|
155
|
+
```
|
156
|
+
|
157
|
+
### Subsequent sync
|
158
|
+
|
159
|
+
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.
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
@sync_result = @stack.sync({sync_token : "<sync_token>"})
|
163
|
+
# @sync_result.items: contains sync data
|
164
|
+
# @sync_result.pagination_token: For fetching the next batch of entries using pagination token
|
165
|
+
# @sync_result.sync_token: For performing subsequent sync after initial sync
|
166
|
+
```
|
167
|
+
|
168
|
+
### Advanced sync queries
|
169
|
+
|
170
|
+
You can use advanced sync queries to fetch custom results while performing initial sync.
|
171
|
+
[Read advanced sync queries documentation](https://www.contentstack.com/docs/guide/synchronization/using-the-sync-api-with-ruby-sdk#advanced-sync-queries)
|
172
|
+
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
@sync_result = @stack.sync({init : true, locale: "<locale>" content_type_uid: "<content_type_uid>"})
|
176
|
+
# @sync_result.items: contains sync data
|
177
|
+
# @sync_result.pagination_token: For fetching the next batch of entries using pagination token
|
178
|
+
# @sync_result.sync_token: For performing subsequent sync after initial sync
|
179
|
+
```
|
83
180
|
## **Helpful Links**
|
84
181
|
|
85
182
|
* [Contentstack Website](https://www.contentstack.com)
|
@@ -90,7 +187,7 @@ SDK functions for Image Delivery API coming soon.
|
|
90
187
|
|
91
188
|
## **The MIT License (MIT)**
|
92
189
|
|
93
|
-
Copyright © 2012-
|
190
|
+
Copyright © 2012-2021 [Contentstack](https://www.contentstack.com). All Rights Reserved
|
94
191
|
|
95
192
|
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:
|
96
193
|
|
data/contentstack.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.required_ruby_version = '>= 2.0'
|
13
13
|
|
14
14
|
s.license = "MIT"
|
15
|
-
s.homepage = "https://github.com/
|
15
|
+
s.homepage = "https://github.com/contentstack/contentstack-ruby"
|
16
16
|
|
17
17
|
s.summary = %q{Contentstack Ruby client for the Content Delivery API}
|
18
18
|
s.description = %q{Contentstack Ruby client for the Content Delivery API}
|
data/lib/contentstack.rb
CHANGED
@@ -2,15 +2,20 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
|
2
2
|
|
3
3
|
require "contentstack/version"
|
4
4
|
require "contentstack/client"
|
5
|
+
require "contentstack/region"
|
5
6
|
require "util"
|
6
7
|
|
7
8
|
|
8
|
-
# ==
|
9
|
-
#
|
9
|
+
# == Contentstack - Ruby SDK
|
10
|
+
# Contentstack is a content management system that facilitates the process of publication by separating the content from site-related programming and design.
|
10
11
|
# == Installation
|
11
12
|
# gem install contentstack
|
12
13
|
# == Initialize the Stack
|
13
|
-
# @stack = Contentstack::Client.new("site_api_key", "
|
14
|
+
# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
|
15
|
+
# == Initialize the Stack for EU region
|
16
|
+
# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"region": Contentstack::Region::EU })
|
17
|
+
# == Initialize the Stack for custom host
|
18
|
+
# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
|
14
19
|
# == Usage
|
15
20
|
# ==== Get single entry
|
16
21
|
# @stack.content_type('blog').entry('<entry_uid_here>').fetch
|
data/lib/contentstack/api.rb
CHANGED
@@ -6,11 +6,13 @@ require 'open-uri'
|
|
6
6
|
|
7
7
|
module Contentstack
|
8
8
|
class API
|
9
|
-
def self.init_api(api_key,
|
10
|
-
@host =
|
9
|
+
def self.init_api(api_key, delivery_token, environment,host)
|
10
|
+
@host = host
|
11
11
|
@api_version = '/v3'
|
12
12
|
@environment = environment
|
13
|
-
@
|
13
|
+
@api_key = api_key
|
14
|
+
@access_token = delivery_token
|
15
|
+
@headers = {environment: @environment}
|
14
16
|
end
|
15
17
|
|
16
18
|
def self.fetch_content_types(uid="")
|
@@ -27,9 +29,9 @@ module Contentstack
|
|
27
29
|
send_request(path, query)
|
28
30
|
end
|
29
31
|
|
30
|
-
def self.fetch_entry(content_type, entry_uid)
|
32
|
+
def self.fetch_entry(content_type, entry_uid, query)
|
31
33
|
path = "/content_types/#{content_type}/entries/#{entry_uid}"
|
32
|
-
send_request(path)
|
34
|
+
send_request(path, query)
|
33
35
|
end
|
34
36
|
|
35
37
|
def self.get_assets(asset_uid=nil)
|
@@ -38,17 +40,25 @@ module Contentstack
|
|
38
40
|
send_request(path)
|
39
41
|
end
|
40
42
|
|
43
|
+
def self.get_sync_items(query)
|
44
|
+
path = "/stacks/sync"
|
45
|
+
send_request(path, query)
|
46
|
+
end
|
47
|
+
|
41
48
|
private
|
42
49
|
def self.send_request(path, q=nil)
|
43
50
|
q ||= {}
|
44
51
|
|
45
52
|
q.merge!(@headers)
|
46
|
-
q.merge!({timestamp: Time.now.to_i})
|
47
53
|
|
48
54
|
query = "?" + q.to_query
|
49
55
|
# puts "Request URL:- #{@host}#{@api_version}#{path}#{query} \n\n"
|
50
56
|
|
51
|
-
ActiveSupport::JSON.decode(open("#{@host}#{@api_version}#{path}#{query}"
|
57
|
+
ActiveSupport::JSON.decode(open("#{@host}#{@api_version}#{path}#{query}",
|
58
|
+
"api_key" => @api_key,
|
59
|
+
"access_token"=> @access_token,
|
60
|
+
"user_agent"=> "ruby-sdk/#{Contentstack::VERSION}",
|
61
|
+
"x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}").read)
|
52
62
|
end
|
53
63
|
end
|
54
|
-
end
|
64
|
+
end
|
data/lib/contentstack/client.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'contentstack/api'
|
2
2
|
require 'contentstack/content_type'
|
3
3
|
require 'contentstack/asset_collection'
|
4
|
-
|
4
|
+
require 'contentstack/sync_result'
|
5
5
|
module Contentstack
|
6
6
|
class Client
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
attr_reader :region, :host
|
8
|
+
# Initialize "Contentstack" Client instance
|
9
|
+
def initialize(api_key, delivery_token, environment, options={})
|
10
|
+
@region = options[:region].nil? ? Contentstack::Region::US : options[:region]
|
11
|
+
@host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host]
|
12
|
+
API.init_api(api_key, delivery_token, environment, @host)
|
10
13
|
end
|
11
|
-
|
12
14
|
|
13
15
|
def content_types
|
14
16
|
ContentType.all
|
@@ -25,5 +27,39 @@ module Contentstack
|
|
25
27
|
def asset(uid)
|
26
28
|
Asset.new(uid)
|
27
29
|
end
|
30
|
+
|
31
|
+
|
32
|
+
# Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates
|
33
|
+
#
|
34
|
+
# Stack.sync({'init': true}) // For initializing sync
|
35
|
+
#
|
36
|
+
# Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
|
37
|
+
#
|
38
|
+
# Stack.sync({'init': true, 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
|
39
|
+
#
|
40
|
+
# Stack.sync({'init': true, 'content_type_uid': 'session'}) //For initializing sync with entries of a specific content type
|
41
|
+
#
|
42
|
+
# 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'.
|
43
|
+
#
|
44
|
+
# Stack.sync({'pagination_token': '<btlsomething>'}) // For fetching the next batch of entries using pagination token
|
45
|
+
#
|
46
|
+
# Stack.sync({'sync_token': '<btlsomething>'}) // For performing subsequent sync after initial sync
|
47
|
+
#
|
48
|
+
# @param params [Hash] params is an object that supports ‘locale’, ‘start_date’, ‘content_type_uid’, and ‘type’ queries.
|
49
|
+
def sync(params)
|
50
|
+
sync_result = API.get_sync_items(params)
|
51
|
+
SyncResult.new(sync_result)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def get_default_region_hosts(region='us')
|
56
|
+
case region
|
57
|
+
when "us"
|
58
|
+
host = "https://cdn.contentstack.io"
|
59
|
+
when "eu"
|
60
|
+
host = "https://eu-cdn.contentstack.com"
|
61
|
+
end
|
62
|
+
host
|
63
|
+
end
|
28
64
|
end
|
29
65
|
end
|