contentful
Advanced tools
Comparing version 1.0.0 to 1.1.0
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
## v1.1.0 - 2015-03-24 | ||
### Added | ||
- Add support for the sync endpoint | ||
## v1.0.0 - 2015-03-24 | ||
### Changed | ||
- Replace `questor` with `axios` |
52
index.js
@@ -93,2 +93,31 @@ 'use strict'; | ||
return nodeify(this._request(''), callback); | ||
}, | ||
_pagedSync: function (sync) { | ||
var self = this; | ||
return this._request('/sync', sync.query) | ||
.then(function (data) { | ||
sync.append(data); | ||
if(!sync.done){ | ||
return self._pagedSync(sync); | ||
} else { | ||
return { | ||
items: sync.items, | ||
nextSyncToken: sync.nextSyncToken | ||
}; | ||
} | ||
}); | ||
}, | ||
sync: function (object, callback) { | ||
if (!object || (!object.initial && !object.nextSyncToken)) { | ||
throw new Error('Please provide either the initial flag or a nextSyncToken for syncing'); | ||
} | ||
var query = Query.parse(object); | ||
var deferred = this._pagedSync(new Sync(query)) | ||
.then(function (response) { | ||
response.items = SearchResult.parse(response); | ||
return response; | ||
}); | ||
return nodeify(deferred, callback); | ||
} | ||
@@ -222,2 +251,25 @@ }); | ||
var Sync = redefine.Class({ | ||
constructor: function Sync(query) { | ||
this.query = query; | ||
this.items = []; | ||
this.done = false; | ||
}, | ||
append: function (data) { | ||
this.items = this.items.concat(data.items); | ||
if(data.nextPageUrl){ | ||
var nextPageUrl = data.nextPageUrl.split('?'); | ||
this.query = _.omit(this.query, 'initial', 'sync_token'); | ||
this.query.sync_token = querystring.parse(nextPageUrl[1]).sync_token; | ||
} else if(data.nextSyncUrl){ | ||
var nextSyncUrl = data.nextSyncUrl.split('?'); | ||
this.nextSyncToken = querystring.parse(nextSyncUrl[1]).sync_token; | ||
this.done = true; | ||
} | ||
} | ||
}); | ||
exports.createClient = function(options) { | ||
@@ -224,0 +276,0 @@ return new Client(options || {}); |
{ | ||
"name": "contentful", | ||
"description": "Client for Contentful's Content Delivery API", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"homepage": "https://www.contentful.com/developers/documentation/content-delivery-api/", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -74,2 +74,15 @@ # contentful.js | ||
}); | ||
var syncToken; | ||
// Get all data in a space | ||
client.sync({initial: true}) | ||
.then(function(data){ | ||
syncToken = data.nextSyncToken; | ||
}); | ||
// Get all data since the last sync | ||
client.sync({nextSyncToken: syncToken}) | ||
.then(function(data){ | ||
syncToken = data.nextSyncToken; | ||
}); | ||
``` | ||
@@ -88,10 +101,6 @@ | ||
* .entries() = get entries of current space | ||
* ... | ||
* .sync() = get all the data in a space | ||
### not supported | ||
* Sync | ||
## License | ||
MIT |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
328150
30
4588
105