contentful-management
Advanced tools
Comparing version 0.0.3 to 0.0.4
305
index.js
'use strict'; | ||
var _ = require('underscore-contrib'); | ||
var Promise = require('pacta').Promise; | ||
var questor = require('questor'); | ||
@@ -65,11 +64,15 @@ var redefine = require('redefine'); | ||
var parseResponseBody = options.ignoreResponseBody ? function() {} : parseJSONBody; | ||
return questor(uri, options).then(function(response) { | ||
if (options.ignoreResponseBody) { | ||
return; | ||
} | ||
var promise = new Promise(); | ||
var request = questor(uri, options); | ||
request.onRejected(function(reason) { | ||
if (reason instanceof Error) return reason; | ||
return JSON.parse(response.body); | ||
}, function(reason) { | ||
if (reason instanceof Error) { | ||
throw reason; | ||
} | ||
// 1. Parse proper error here | ||
// 2. If json parsing fails, create new Error(plaintext) | ||
var apiError = parseJSONBody(reason); | ||
var apiError = JSON.parse(reason.body); | ||
var message = apiError.sys.id; | ||
@@ -79,19 +82,11 @@ if (apiError.details) { | ||
} | ||
return new Error(message); | ||
}).map(_.bound(promise, 'reject')); | ||
request.map(parseResponseBody).map(_.bound(promise, 'resolve')); | ||
return promise; | ||
throw new Error(message); | ||
}); | ||
}, | ||
createSpace: function(space) { | ||
var promise = new Promise(); | ||
var request = this.request('/spaces', { | ||
return this.request('/spaces', { | ||
method: 'POST', | ||
body: JSON.stringify(space) | ||
}); | ||
request | ||
.map(_.partial(Space.parse, this)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Space.parse, this)); | ||
}, | ||
@@ -101,26 +96,13 @@ | ||
var id = getId(identifiable); | ||
var promise = new Promise(); | ||
var request = this.request('/spaces/' + id); | ||
request | ||
.map(_.partial(Space.parse, this)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
return this.request('/spaces/' + id).then(_.partial(Space.parse, this)); | ||
}, | ||
getSpaces: function() { | ||
var promise = new Promise(); | ||
var request = this.request('/spaces'); | ||
request | ||
.map(_.partial(SearchResult.parse, this)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
return this.request('/spaces').then(_.partial(SearchResult.parse, this)); | ||
}, | ||
updateSpace: function(space) { | ||
var promise = new Promise(); | ||
var id = getId(space); | ||
var version = getVersion(space); | ||
var request = this.request('/spaces/' + id, { | ||
return this.request('/spaces/' + id, { | ||
method: 'PUT', | ||
@@ -131,8 +113,3 @@ headers: { | ||
body: JSON.stringify(getData(space)) | ||
}); | ||
request | ||
.map(_.partial(Space.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Space.parse, this.client)); | ||
}, | ||
@@ -142,10 +119,6 @@ | ||
var id = getId(identifiable); | ||
var promise = new Promise(); | ||
var request = this.request('/spaces/' + id, { | ||
return this.request('/spaces/' + id, { | ||
method: 'DELETE', | ||
ignoreResponseBody: true | ||
}); | ||
request.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
} | ||
@@ -168,23 +141,12 @@ }); | ||
createContentType: function(contentType) { | ||
var promise = new Promise(); | ||
// TODO: Allow creation by ID | ||
var request = this.client.request('/spaces/' + this.sys.id + '/content_types', { | ||
return this.client.request('/spaces/' + this.sys.id + '/content_types', { | ||
method: 'POST', | ||
body: JSON.stringify(contentType) | ||
}); | ||
request | ||
.map(_.partial(ContentType.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(ContentType.parse, this.client)); | ||
}, | ||
getContentType: function(id) { | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + this.sys.id + '/content_types/' + id); | ||
request | ||
.map(_.partial(ContentType.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
return this.client.request('/spaces/' + this.sys.id + '/content_types/' + id) | ||
.then(_.partial(ContentType.parse, this.client)); | ||
}, | ||
@@ -194,8 +156,4 @@ | ||
var query = Query.parse(object); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + this.sys.id + '/content_types', {query: query}); | ||
request.map(_.partial(SearchResult.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
return this.client.request('/spaces/' + this.sys.id + '/content_types', {query: query}) | ||
.then(_.partial(SearchResult.parse, this.client)); | ||
}, | ||
@@ -207,4 +165,3 @@ | ||
var version = getVersion(contentType); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/content_types/' + id, { | ||
return this.client.request('/spaces/' + spaceId + '/content_types/' + id, { | ||
method: 'PUT', | ||
@@ -215,8 +172,3 @@ headers: { | ||
body: JSON.stringify(getData(contentType)) | ||
}); | ||
request | ||
.map(_.partial(ContentType.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(ContentType.parse, this.client)); | ||
}, | ||
@@ -227,10 +179,6 @@ | ||
var id = getId(contentType); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/content_types/' + id, { | ||
return this.client.request('/spaces/' + spaceId + '/content_types/' + id, { | ||
method: 'DELETE', | ||
ignoreResponseBody: true | ||
}); | ||
request.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}, | ||
@@ -242,4 +190,3 @@ | ||
var version = publishVersion || getVersion(contentType); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/content_types/' + id + '/published', { | ||
return this.client.request('/spaces/' + spaceId + '/content_types/' + id + '/published', { | ||
method: 'PUT', | ||
@@ -249,8 +196,3 @@ headers: { | ||
} | ||
}); | ||
request | ||
.map(_.partial(ContentType.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(ContentType.parse, this.client)); | ||
}, | ||
@@ -261,11 +203,5 @@ | ||
var id = getId(contentType); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/content_types/' + id + '/published', { | ||
return this.client.request('/spaces/' + spaceId + '/content_types/' + id + '/published', { | ||
method: 'DELETE' | ||
}); | ||
request | ||
.map(_.partial(ContentType.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(ContentType.parse, this.client)); | ||
}, | ||
@@ -280,5 +216,4 @@ | ||
var contentTypeId = getId(contentType); | ||
var promise = new Promise(); | ||
// TODO: Allow creation by ID | ||
var request = this.client.request('/spaces/' + spaceId + '/entries', { | ||
return this.client.request('/spaces/' + spaceId + '/entries', { | ||
method: 'POST', | ||
@@ -289,18 +224,8 @@ headers: { | ||
body: JSON.stringify(getData(entry)) | ||
}); | ||
request | ||
.map(_.partial(Entry.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Entry.parse, this.client)); | ||
}, | ||
getEntry: function(id) { | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + this.sys.id + '/entries/' + id); | ||
request | ||
.map(_.partial(Entry.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
return this.client.request('/spaces/' + this.sys.id + '/entries/' + id) | ||
.then(_.partial(Entry.parse, this.client)); | ||
}, | ||
@@ -310,8 +235,4 @@ | ||
var query = Query.parse(object); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + this.sys.id + '/entries', {query: query}); | ||
request.map(_.partial(SearchResult.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
return this.client.request('/spaces/' + this.sys.id + '/entries', {query: query}) | ||
.then(_.partial(SearchResult.parse, this.client)); | ||
}, | ||
@@ -323,4 +244,3 @@ | ||
var version = getVersion(entry); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/entries/' + id, { | ||
return this.client.request('/spaces/' + spaceId + '/entries/' + id, { | ||
method: 'PUT', | ||
@@ -331,8 +251,3 @@ headers: { | ||
body: JSON.stringify(getData(entry)) | ||
}); | ||
request | ||
.map(_.partial(Entry.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Entry.parse, this.client)); | ||
}, | ||
@@ -344,4 +259,3 @@ | ||
var version = publishVersion || getVersion(entry); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/entries/' + id + '/published', { | ||
return this.client.request('/spaces/' + spaceId + '/entries/' + id + '/published', { | ||
method: 'PUT', | ||
@@ -351,8 +265,3 @@ headers: { | ||
} | ||
}); | ||
request | ||
.map(_.partial(Entry.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Entry.parse, this.client)); | ||
}, | ||
@@ -363,11 +272,5 @@ | ||
var id = getId(entry); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/entries/' + id + '/published', { | ||
return this.client.request('/spaces/' + spaceId + '/entries/' + id + '/published', { | ||
method: 'DELETE' | ||
}); | ||
request | ||
.map(_.partial(Entry.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Entry.parse, this.client)); | ||
}, | ||
@@ -378,10 +281,6 @@ | ||
var id = getId(identifiable); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/entries/' + id, { | ||
return this.client.request('/spaces/' + spaceId + '/entries/' + id, { | ||
method: 'DELETE', | ||
ignoreResponseBody: true | ||
}); | ||
request.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}, | ||
@@ -392,11 +291,5 @@ | ||
var id = getId(entry); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/entries/' + id + '/archived', { | ||
return this.client.request('/spaces/' + spaceId + '/entries/' + id + '/archived', { | ||
method: 'PUT' | ||
}); | ||
request | ||
.map(_.partial(Entry.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Entry.parse, this.client)); | ||
}, | ||
@@ -407,11 +300,5 @@ | ||
var id = getId(entry); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/entries/' + id + '/archived', { | ||
return this.client.request('/spaces/' + spaceId + '/entries/' + id + '/archived', { | ||
method: 'DELETE' | ||
}); | ||
request | ||
.map(_.partial(Entry.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Entry.parse, this.client)); | ||
}, | ||
@@ -424,13 +311,7 @@ | ||
createAsset: function(asset) { | ||
var promise = new Promise(); | ||
// TODO: Allow creation by ID | ||
var request = this.client.request('/spaces/' + this.sys.id + '/assets', { | ||
return this.client.request('/spaces/' + this.sys.id + '/assets', { | ||
method: 'POST', | ||
body: JSON.stringify(asset) | ||
}); | ||
request | ||
.map(_.partial(Asset.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Asset.parse, this.client)); | ||
}, | ||
@@ -440,9 +321,4 @@ | ||
var id = getId(identifiable); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + this.sys.id + '/assets/' + id); | ||
request | ||
.map(_.partial(Asset.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
return this.client.request('/spaces/' + this.sys.id + '/assets/' + id) | ||
.then(_.partial(Asset.parse, this.client)); | ||
}, | ||
@@ -452,8 +328,4 @@ | ||
var query = Query.parse(object); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + this.sys.id + '/assets', {query: query}); | ||
request.map(_.partial(SearchResult.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
return this.client.request('/spaces/' + this.sys.id + '/assets', {query: query}) | ||
.then(_.partial(SearchResult.parse, this.client)); | ||
}, | ||
@@ -465,4 +337,3 @@ | ||
var version = getVersion(asset); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/assets/' + id, { | ||
return this.client.request('/spaces/' + spaceId + '/assets/' + id, { | ||
method: 'PUT', | ||
@@ -473,8 +344,3 @@ headers: { | ||
body: JSON.stringify(getData(asset)) | ||
}); | ||
request | ||
.map(_.partial(Asset.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Asset.parse, this.client)); | ||
}, | ||
@@ -486,4 +352,3 @@ | ||
var version = processVersion || getVersion(asset); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/assets/' + id + '/files/' + fileId + '/process', { | ||
return this.client.request('/spaces/' + spaceId + '/assets/' + id + '/files/' + fileId + '/process', { | ||
method: 'PUT', | ||
@@ -495,6 +360,2 @@ headers: { | ||
}); | ||
request | ||
.map(_.bind(promise.resolve, promise, this)); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}, | ||
@@ -506,4 +367,3 @@ | ||
var version = publishVersion || getVersion(asset); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/assets/' + id + '/published', { | ||
return this.client.request('/spaces/' + spaceId + '/assets/' + id + '/published', { | ||
method: 'PUT', | ||
@@ -513,8 +373,3 @@ headers: { | ||
} | ||
}); | ||
request | ||
.map(_.partial(Asset.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Asset.parse, this.client)); | ||
}, | ||
@@ -525,11 +380,5 @@ | ||
var id = getId(asset); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/assets/' + id + '/published', { | ||
return this.client.request('/spaces/' + spaceId + '/assets/' + id + '/published', { | ||
method: 'DELETE' | ||
}); | ||
request | ||
.map(_.partial(Asset.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Asset.parse, this.client)); | ||
}, | ||
@@ -540,10 +389,6 @@ | ||
var id = getId(identifiable); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/assets/' + id, { | ||
return this.client.request('/spaces/' + spaceId + '/assets/' + id, { | ||
method: 'DELETE', | ||
ignoreResponseBody: true | ||
}); | ||
request.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}, | ||
@@ -554,11 +399,5 @@ | ||
var id = getId(asset); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/assets/' + id + '/archived', { | ||
return this.client.request('/spaces/' + spaceId + '/assets/' + id + '/archived', { | ||
method: 'PUT' | ||
}); | ||
request | ||
.map(_.partial(Asset.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Asset.parse, this.client)); | ||
}, | ||
@@ -569,11 +408,5 @@ | ||
var id = getId(asset); | ||
var promise = new Promise(); | ||
var request = this.client.request('/spaces/' + spaceId + '/assets/' + id + '/archived', { | ||
return this.client.request('/spaces/' + spaceId + '/assets/' + id + '/archived', { | ||
method: 'DELETE' | ||
}); | ||
request | ||
.map(_.partial(Entry.parse, this.client)) | ||
.map(_.bound(promise, 'resolve')); | ||
request.onRejected(_.bound(promise, 'reject')); | ||
return promise; | ||
}).then(_.partial(Entry.parse, this.client)); | ||
} | ||
@@ -748,6 +581,2 @@ }); | ||
function parseJSONBody(response) { | ||
return JSON.parse(response.responseText); | ||
} | ||
function stringifyArrayValues(object) { | ||
@@ -754,0 +583,0 @@ return _.reduce(object, function(object, value, key) { |
{ | ||
"name": "contentful-management", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Client for Contentful's Content Management API", | ||
@@ -17,6 +17,6 @@ "homepage": "https://www.contentful.com/developers/documentation/content-management-api/", | ||
"dependencies": { | ||
"pacta": "0.2.0", | ||
"questor": "0.0.3", | ||
"redefine": "0.2.0", | ||
"underscore-contrib": "0.1.4" | ||
"q": "~0.9.7", | ||
"questor": "1.0.0-alpha", | ||
"redefine": "~0.2.0", | ||
"underscore-contrib": "~0.1.4" | ||
}, | ||
@@ -23,0 +23,0 @@ "devDependencies": { |
'use strict'; | ||
var _ = require('underscore-contrib'); | ||
var contentful = require('..'); | ||
var Promise = require('pacta').Promise; | ||
var q = require('q'); | ||
@@ -16,5 +15,3 @@ exports.client = contentful.createClient({ | ||
if (!ms) { ms = 5000; } | ||
var promise = new Promise(); | ||
setTimeout(_.bound(promise, 'resolve'), ms); | ||
return promise; | ||
return q.delay(ms); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11
29890
903
+ Addedq@~0.9.7
+ Addedbluebird@0.9.0-0(transitive)
+ Addedq@0.9.7(transitive)
+ Addedquestor@1.0.0-alpha(transitive)
+ Addedredefine@0.2.1(transitive)
- Removedpacta@0.2.0
- Removedpacta@0.2.0(transitive)
- Removedquestor@0.0.3(transitive)
- Removedredefine@0.2.0(transitive)
- Removedwru@0.3.0(transitive)
Updatedquestor@1.0.0-alpha
Updatedredefine@~0.2.0
Updatedunderscore-contrib@~0.1.4