Skip to content

Commit 18487c3

Browse files
Added SyncApi feature
1 parent 487aa0a commit 18487c3

26 files changed

+181
-156
lines changed

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const config = {
22
protocol: "https",
3-
host: "dev-cdn.contentstack.io",
3+
host: "stag-cdn.contentstack.io",
44
port: 443,
55
version: "v3",
66
urls: {

dist/native-script/contentstack.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,14 @@ function sendRequest(queryObject) {
387387
}
388388
});
389389
return resolve(spreadResult(entries));
390-
} else {
391-
if (syncstack) {
392-
return resolve(syncstack);
393-
}
390+
}
394391

395-
if (!tojson) entries = resultWrapper(entries);
396-
return resolve(spreadResult(entries));
392+
if (Object.keys(syncstack).length) {
393+
return resolve(syncstack);
397394
}
395+
396+
if (!tojson) entries = resultWrapper(entries);
397+
return resolve(spreadResult(entries));
398398
} catch (e) {
399399
return reject({
400400
message: e.message
@@ -567,12 +567,12 @@ var Stack = function () {
567567
this.config = _config2.default;
568568
this.cachePolicy = _index2.default.policies.IGNORE_CACHE;
569569
this.provider = _index2.default.providers('localstorage');
570+
//this.sync_cdn_api_key = stack_arguments[0].sync_cdn_api_key;
570571

571572
for (var _len = arguments.length, stack_arguments = Array(_len), _key = 0; _key < _len; _key++) {
572573
stack_arguments[_key] = arguments[_key];
573574
}
574575

575-
this.web_ui_api_key = stack_arguments[0].web_ui_api_key;
576576
switch (stack_arguments.length) {
577577
case 1:
578578
if (_typeof(stack_arguments[0]) === "object" && typeof stack_arguments[0].api_key === "string" && typeof stack_arguments[0].access_token === "string" && typeof stack_arguments[0].environment === "string") {
@@ -854,19 +854,28 @@ var Stack = function () {
854854

855855
/**
856856
* @method sync
857-
* @description sync get all the sync data.
858-
* @example Stack.sync({'init': 'true'})
857+
* @description 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 iOS SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack JavaScript SDK.
858+
* @param {object} params - params is an object which Supports locale, start_date, content_type_id queries.
859+
* @example
860+
* Stack.sync({'init': true}) // For initializing sync
861+
* @example
862+
* Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
863+
* @example
864+
* Stack.sync({'init': 'true', 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
865+
* @example
866+
* Stack.sync({'init': 'true', 'content_type_id': 'session'}) //For initializing sync with entries of a specific content type
867+
* @example
868+
* Stack.sync({'pagination_token': '<btlsomething>'}) // For fetching the next batch of entries using pagination token
869+
* @example
870+
* Stack.sync({'sync_token': '<btlsomething>'}) // For performing subsequent sync after initial sync
859871
* @returns {object}
860-
* @ignore
861872
*/
862873

863874
}, {
864875
key: 'sync',
865876
value: function sync(params) {
866877
this._query = {};
867-
this["params"] = params;
868-
this._query['web_ui_api_key'] = this.web_ui_api_key;
869-
this._query = Object.assign(this._query, this.params);
878+
this._query = Object.assign(this._query, params);
870879
this.requestParams = {
871880
method: 'POST',
872881
headers: this.headers,
@@ -983,7 +992,6 @@ function Request(options) {
983992
method: 'GET',
984993
headers: headers
985994
}).then(function (response) {
986-
987995
if (response.ok && response.status === 200) {
988996
var data = response.json();
989997
resolve(data);
@@ -1962,7 +1970,7 @@ Object.defineProperty(exports, "__esModule", {
19621970
});
19631971
var config = {
19641972
protocol: "https",
1965-
host: "dev-new-api.contentstack.io",
1973+
host: "stag-cdn.contentstack.io",
19661974
port: 443,
19671975
version: "v3",
19681976
urls: {

dist/node/contentstack.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,14 @@ function sendRequest(queryObject) {
393393
}
394394
});
395395
return resolve(spreadResult(entries));
396-
} else {
397-
if (syncstack) {
398-
return resolve(syncstack);
399-
}
396+
}
400397

401-
if (!tojson) entries = resultWrapper(entries);
402-
return resolve(spreadResult(entries));
398+
if (Object.keys(syncstack).length) {
399+
return resolve(syncstack);
403400
}
401+
402+
if (!tojson) entries = resultWrapper(entries);
403+
return resolve(spreadResult(entries));
404404
} catch (e) {
405405
return reject({
406406
message: e.message
@@ -865,29 +865,28 @@ var Stack = function () {
865865

866866
/**
867867
* @method sync
868-
* @description sync get all the sync data.
869-
* @param {object} params - params is an object with different parameters.
868+
* @description 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 iOS SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack JavaScript SDK.
869+
* @param {object} params - params is an object which Supports locale, start_date, content_type_id queries.
870+
* @example
871+
* Stack.sync({'init': true}) // For initializing sync
870872
* @example
871-
* Stack.sync({'init': 'true'})
873+
* Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
872874
* @example
873-
* Stack.sync({'init': 'true', 'locale': 'en-us'})
875+
* Stack.sync({'init': 'true', 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
874876
* @example
875-
* Stack.sync({'init': 'true', 'start_date': '2018-09-12'})
877+
* Stack.sync({'init': 'true', 'content_type_id': 'session'}) //For initializing sync with entries of a specific content type
876878
* @example
877-
* Stack.sync({'pagination_token': 'btlsomething'})
879+
* Stack.sync({'pagination_token': '<btlsomething>'}) // For fetching the next batch of entries using pagination token
878880
* @example
879-
* Stack.sync({'sync_token': 'btlsomething'})
881+
* Stack.sync({'sync_token': '<btlsomething>'}) // For performing subsequent sync after initial sync
880882
* @returns {object}
881-
* @ignore
882883
*/
883884

884885
}, {
885886
key: 'sync',
886887
value: function sync(params) {
887888
this._query = {};
888-
this["params"] = params;
889-
//this._query['sync_cdn_api_key'] = this.sync_cdn_api_key;
890-
this._query = Object.assign(this._query, this.params);
889+
this._query = Object.assign(this._query, params);
891890
this.requestParams = {
892891
method: 'POST',
893892
headers: this.headers,
@@ -1407,7 +1406,6 @@ function Request(options) {
14071406
method: 'GET',
14081407
headers: headers
14091408
}).then(function (response) {
1410-
14111409
if (response.ok && response.status === 200) {
14121410
var data = response.json();
14131411
resolve(data);
@@ -2456,7 +2454,7 @@ Object.defineProperty(exports, "__esModule", {
24562454
});
24572455
var config = {
24582456
protocol: "https",
2459-
host: "dev-cdn.contentstack.io",
2457+
host: "stag-cdn.contentstack.io",
24602458
port: 443,
24612459
version: "v3",
24622460
urls: {

dist/react-native/contentstack.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,14 @@ function sendRequest(queryObject) {
387387
}
388388
});
389389
return resolve(spreadResult(entries));
390-
} else {
391-
if (syncstack) {
392-
return resolve(syncstack);
393-
}
390+
}
394391

395-
if (!tojson) entries = resultWrapper(entries);
396-
return resolve(spreadResult(entries));
392+
if (Object.keys(syncstack).length) {
393+
return resolve(syncstack);
397394
}
395+
396+
if (!tojson) entries = resultWrapper(entries);
397+
return resolve(spreadResult(entries));
398398
} catch (e) {
399399
return reject({
400400
message: e.message
@@ -567,12 +567,12 @@ var Stack = function () {
567567
this.config = _config2.default;
568568
this.cachePolicy = _index2.default.policies.IGNORE_CACHE;
569569
this.provider = _index2.default.providers('localstorage');
570+
//this.sync_cdn_api_key = stack_arguments[0].sync_cdn_api_key;
570571

571572
for (var _len = arguments.length, stack_arguments = Array(_len), _key = 0; _key < _len; _key++) {
572573
stack_arguments[_key] = arguments[_key];
573574
}
574575

575-
this.web_ui_api_key = stack_arguments[0].web_ui_api_key;
576576
switch (stack_arguments.length) {
577577
case 1:
578578
if (_typeof(stack_arguments[0]) === "object" && typeof stack_arguments[0].api_key === "string" && typeof stack_arguments[0].access_token === "string" && typeof stack_arguments[0].environment === "string") {
@@ -854,19 +854,28 @@ var Stack = function () {
854854

855855
/**
856856
* @method sync
857-
* @description sync get all the sync data.
858-
* @example Stack.sync({'init': 'true'})
857+
* @description 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 iOS SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack JavaScript SDK.
858+
* @param {object} params - params is an object which Supports locale, start_date, content_type_id queries.
859+
* @example
860+
* Stack.sync({'init': true}) // For initializing sync
861+
* @example
862+
* Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
863+
* @example
864+
* Stack.sync({'init': 'true', 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
865+
* @example
866+
* Stack.sync({'init': 'true', 'content_type_id': 'session'}) //For initializing sync with entries of a specific content type
867+
* @example
868+
* Stack.sync({'pagination_token': '<btlsomething>'}) // For fetching the next batch of entries using pagination token
869+
* @example
870+
* Stack.sync({'sync_token': '<btlsomething>'}) // For performing subsequent sync after initial sync
859871
* @returns {object}
860-
* @ignore
861872
*/
862873

863874
}, {
864875
key: 'sync',
865876
value: function sync(params) {
866877
this._query = {};
867-
this["params"] = params;
868-
this._query['web_ui_api_key'] = this.web_ui_api_key;
869-
this._query = Object.assign(this._query, this.params);
878+
this._query = Object.assign(this._query, params);
870879
this.requestParams = {
871880
method: 'POST',
872881
headers: this.headers,
@@ -983,7 +992,6 @@ function Request(options) {
983992
method: 'GET',
984993
headers: headers
985994
}).then(function (response) {
986-
987995
if (response.ok && response.status === 200) {
988996
var data = response.json();
989997
resolve(data);
@@ -1962,7 +1970,7 @@ Object.defineProperty(exports, "__esModule", {
19621970
});
19631971
var config = {
19641972
protocol: "https",
1965-
host: "dev-new-api.contentstack.io",
1973+
host: "stag-cdn.contentstack.io",
19661974
port: 443,
19671975
version: "v3",
19681976
urls: {

dist/web/contentstack.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/node/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
const ContentstackDemo = require('./contentstack-demo.js')
44

5-
const Demo = new ContentstackDemo({ 'api_key': 'blt3095c4e04a3d69e6', 'access_token': 'csb4aacc6e090dfd2e8c1b01cd', 'environment': 'web'})
5+
const Demo = new ContentstackDemo({ 'api_key': '<api_key>', 'access_token': '<Delivery_token>', 'environment': '<Environment>'})
66

77

88
// Demo
9-
// .getEntries('home_reference')
9+
// .getEntries('source')
1010
// .then(function(result) {
1111
// // result object with entry
12-
// console.info("Result2 : ", typeof result)
12+
// console.info("Result2 : ", result)
1313

1414
// //console.info("Result2 : ", JSON.stringify(result))
1515

@@ -22,7 +22,7 @@ const Demo = new ContentstackDemo({ 'api_key': 'blt3095c4e04a3d69e6', 'access_to
2222

2323

2424
//get all the entries
25-
Demo.getSyncApi({"init": "true"})
25+
Demo.getSyncApi({"init": true, "type": "asset_published"})
2626
.then(function(result) {
2727
// result object with entries
2828
console.info("Result: ", result)

js-sdk-reference.zip

685 Bytes
Binary file not shown.

js-sdk-reference/Result.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<!--[if lt IE 9]>
1010
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
1111
<![endif]-->
12+
<link rel="canonical" href="https://www.contentstack.com/docs/platforms/java/api-reference/">
1213
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
1314
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
1415
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">

js-sdk-reference/contentstack.js.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<!--[if lt IE 9]>
1010
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
1111
<![endif]-->
12+
<link rel="canonical" href="https://www.contentstack.com/docs/platforms/java/api-reference/">
1213
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
1314
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
1415
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">

js-sdk-reference/global.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<!--[if lt IE 9]>
1010
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
1111
<![endif]-->
12+
<link rel="canonical" href="https://www.contentstack.com/docs/platforms/java/api-reference/">
1213
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
1314
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
1415
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
@@ -1427,7 +1428,7 @@ <h4 class="name" id="sync"><span class="type-signature"></span>sync<span class="
14271428

14281429

14291430
<div class="description">
1430-
Synchronization API is used to synchronize content from API server in order to keep local copy of content time to time.API allows incremental(changes in Content from timepoint) updates of content time to time instead of getting all content at same time.
1431+
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 iOS SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack JavaScript SDK.
14311432
</div>
14321433

14331434

@@ -1468,7 +1469,7 @@ <h5>Parameters:</h5>
14681469

14691470

14701471

1471-
<td class="description last">params is an object with different parameters.</td>
1472+
<td class="description last">params is an object which Supports locale, start_date, content_type_id queries.</td>
14721473
</tr>
14731474

14741475

@@ -1527,15 +1528,17 @@ <h5>Parameters:</h5>
15271528

15281529
<h5>Examples</h5>
15291530

1530-
<pre class="prettyprint"><code>Stack.sync({'init': 'true'})</code></pre>
1531+
<pre class="prettyprint"><code>Stack.sync({'init': true}) // For initializing sync</code></pre>
15311532

1532-
<pre class="prettyprint"><code>Stack.sync({'init': 'true', 'locale': 'en-us'})</code></pre>
1533+
<pre class="prettyprint"><code>Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale</code></pre>
15331534

1534-
<pre class="prettyprint"><code>Stack.sync({'init': 'true', 'start_date': '2018-09-12'})</code></pre>
1535+
<pre class="prettyprint"><code>Stack.sync({'init': 'true', 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date</code></pre>
15351536

1536-
<pre class="prettyprint"><code>Stack.sync({'pagination_token': 'btlsomething'})</code></pre>
1537+
<pre class="prettyprint"><code>Stack.sync({'init': 'true', 'content_type_id': 'session'}) //For initializing sync with entries of a specific content type</code></pre>
15371538

1538-
<pre class="prettyprint"><code>Stack.sync({'sync_token': 'btlsomething'})</code></pre>
1539+
<pre class="prettyprint"><code>Stack.sync({'pagination_token': '&lt;btlsomething>'}) // For fetching the next batch of entries using pagination token</code></pre>
1540+
1541+
<pre class="prettyprint"><code>Stack.sync({'sync_token': '&lt;btlsomething>'}) // For performing subsequent sync after initial sync</code></pre>
15391542

15401543

15411544

0 commit comments

Comments
 (0)