2014-02-05 12:40:30 +04:00
|
|
|
var _ = require('lodash'),
|
2013-11-03 21:13:19 +04:00
|
|
|
url = require('url'),
|
|
|
|
ApiRouteBase = '/ghost/api/v0.1/',
|
|
|
|
host = 'localhost',
|
|
|
|
port = '2369';
|
2013-11-07 13:34:18 +04:00
|
|
|
schema = "http://",
|
|
|
|
expectedProperties = {
|
|
|
|
posts: ['posts', 'page', 'limit', 'pages', 'total'],
|
|
|
|
post: ['id', 'uuid', 'title', 'slug', 'markdown', 'html', 'meta_title', 'meta_description',
|
2014-01-03 19:50:03 +04:00
|
|
|
'featured', 'image', 'status', 'language', 'author_id', 'created_at', 'created_by', 'updated_at',
|
2014-02-25 00:28:18 +04:00
|
|
|
'updated_by', 'published_at', 'published_by', 'page', 'author', 'tags', 'fields'],
|
2013-12-16 14:16:06 +04:00
|
|
|
// TODO: remove databaseVersion, dbHash
|
2014-01-03 19:50:03 +04:00
|
|
|
settings: ['databaseVersion', 'dbHash', 'title', 'description', 'email', 'logo', 'cover', 'defaultLang',
|
2014-01-21 12:45:27 +04:00
|
|
|
"permalinks", 'postsPerPage', 'forceI18n', 'activeTheme', 'activeApps', 'installedApps',
|
2014-02-23 16:32:35 +04:00
|
|
|
'availableThemes', 'availableApps', 'nextUpdateCheck', 'displayUpdateNotification'],
|
2013-11-07 13:34:18 +04:00
|
|
|
tag: ['id', 'uuid', 'name', 'slug', 'description', 'parent_id',
|
|
|
|
'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 21:51:01 +04:00
|
|
|
'created_at', 'updated_at'],
|
|
|
|
notification: ['type', 'message', 'status', 'id']
|
2013-11-07 13:34:18 +04:00
|
|
|
};
|
|
|
|
|
2014-04-07 17:50:18 +04:00
|
|
|
function getApiQuery (route) {
|
|
|
|
return url.resolve(ApiRouteBase, route);
|
|
|
|
}
|
2013-11-03 21:13:19 +04:00
|
|
|
|
|
|
|
function getApiURL (route) {
|
|
|
|
var baseURL = url.resolve(schema + host + ':' + port, ApiRouteBase);
|
|
|
|
return url.resolve(baseURL, route);
|
2013-10-08 05:39:33 +04:00
|
|
|
}
|
2013-11-03 21:13:19 +04:00
|
|
|
function getSigninURL () {
|
|
|
|
return url.resolve(schema + host + ':' + port, 'ghost/signin/');
|
2013-10-08 05:39:33 +04:00
|
|
|
}
|
2013-11-24 18:29:36 +04:00
|
|
|
function getAdminURL () {
|
|
|
|
return url.resolve(schema + host + ':' + port, 'ghost/');
|
|
|
|
}
|
2013-10-08 05:39:33 +04:00
|
|
|
|
2013-11-03 21:13:19 +04:00
|
|
|
// make sure the API only returns expected properties only
|
2013-11-07 13:34:18 +04: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) {
|
|
|
|
jsonResponse.should.have.property(properties[i]);
|
2013-10-08 05:39:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-07 13:34:18 +04:00
|
|
|
module.exports = {
|
|
|
|
getApiURL: getApiURL,
|
2014-04-07 17:50:18 +04:00
|
|
|
getApiQuery: getApiQuery,
|
2013-11-07 13:34:18 +04:00
|
|
|
getSigninURL: getSigninURL,
|
2013-11-24 18:29:36 +04:00
|
|
|
getAdminURL: getAdminURL,
|
2013-11-07 13:34:18 +04:00
|
|
|
checkResponse: checkResponse,
|
|
|
|
checkResponseValue: checkResponseValue,
|
|
|
|
};
|