2014-02-05 00:40:30 -08:00
|
|
|
var _ = require('lodash'),
|
2013-11-03 18:13:19 +01:00
|
|
|
url = require('url'),
|
|
|
|
ApiRouteBase = '/ghost/api/v0.1/',
|
|
|
|
host = 'localhost',
|
|
|
|
port = '2369';
|
2013-11-07 10:34:18 +01:00
|
|
|
schema = "http://",
|
|
|
|
expectedProperties = {
|
2014-04-19 17:03:20 +02:00
|
|
|
posts: ['posts', 'meta'],
|
|
|
|
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
|
2013-11-07 10:34:18 +01:00
|
|
|
post: ['id', 'uuid', 'title', 'slug', 'markdown', 'html', 'meta_title', 'meta_description',
|
2014-04-21 18:08:11 -07:00
|
|
|
'featured', 'image', 'status', 'language', 'created_at', 'created_by', 'updated_at',
|
2014-02-24 20:28:18 +00:00
|
|
|
'updated_by', 'published_at', 'published_by', 'page', 'author', 'tags', 'fields'],
|
2014-04-27 18:28:50 -05:00
|
|
|
settings: ['settings'],
|
|
|
|
setting: ['id','uuid','key','value','type','created_at','created_by','updated_at','updated_by'],
|
2014-04-22 23:46:53 -07:00
|
|
|
tag: ['id', 'uuid', 'name', 'slug', 'description', 'parent',
|
2013-11-07 10:34:18 +01:00
|
|
|
'meta_title', 'meta_description', 'created_at', 'created_by', 'updated_at', 'updated_by'],
|
|
|
|
user: ['id', 'uuid', 'name', 'slug', 'email', 'image', 'cover', 'bio', 'website',
|
|
|
|
'location', 'accessibility', 'status', 'language', 'meta_title', 'meta_description',
|
2014-02-26 18:51:01 +01:00
|
|
|
'created_at', 'updated_at'],
|
|
|
|
notification: ['type', 'message', 'status', 'id']
|
2013-11-07 10:34:18 +01:00
|
|
|
};
|
|
|
|
|
2014-04-07 21:50:18 +08:00
|
|
|
function getApiQuery (route) {
|
|
|
|
return url.resolve(ApiRouteBase, route);
|
|
|
|
}
|
2013-11-03 18:13:19 +01:00
|
|
|
|
|
|
|
function getApiURL (route) {
|
|
|
|
var baseURL = url.resolve(schema + host + ':' + port, ApiRouteBase);
|
|
|
|
return url.resolve(baseURL, route);
|
2013-10-07 20:39:33 -05:00
|
|
|
}
|
2013-11-03 18:13:19 +01:00
|
|
|
function getSigninURL () {
|
|
|
|
return url.resolve(schema + host + ':' + port, 'ghost/signin/');
|
2013-10-07 20:39:33 -05:00
|
|
|
}
|
2013-11-24 15:29:36 +01:00
|
|
|
function getAdminURL () {
|
|
|
|
return url.resolve(schema + host + ':' + port, 'ghost/');
|
|
|
|
}
|
2013-10-07 20:39:33 -05:00
|
|
|
|
2013-11-03 18:13:19 +01:00
|
|
|
// make sure the API only returns expected properties only
|
2013-11-07 10:34:18 +01:00
|
|
|
function checkResponse (jsonResponse, objectType) {
|
|
|
|
checkResponseValue(jsonResponse, expectedProperties[objectType]);
|
|
|
|
}
|
|
|
|
function checkResponseValue (jsonResponse, properties) {
|
|
|
|
Object.keys(jsonResponse).length.should.eql(properties.length);
|
|
|
|
for(var i=0; i<properties.length; i = i + 1) {
|
2014-04-27 18:28:50 -05:00
|
|
|
// For some reason, settings response objects do not have the 'hasOwnProperty' method
|
|
|
|
if (Object.prototype.hasOwnProperty.call(jsonResponse, properties[i])) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-07 10:34:18 +01:00
|
|
|
jsonResponse.should.have.property(properties[i]);
|
2013-10-07 20:39:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-07 10:34:18 +01:00
|
|
|
module.exports = {
|
|
|
|
getApiURL: getApiURL,
|
2014-04-07 21:50:18 +08:00
|
|
|
getApiQuery: getApiQuery,
|
2013-11-07 10:34:18 +01:00
|
|
|
getSigninURL: getSigninURL,
|
2013-11-24 15:29:36 +01:00
|
|
|
getAdminURL: getAdminURL,
|
2013-11-07 10:34:18 +01:00
|
|
|
checkResponse: checkResponse,
|
|
|
|
checkResponseValue: checkResponseValue,
|
|
|
|
};
|