2015-11-11 07:33:19 +03:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function generateQueryString(object) {
|
2015-12-10 17:46:58 +03:00
|
|
|
var queries = [],
|
2015-11-11 07:33:19 +03:00
|
|
|
i;
|
|
|
|
|
|
|
|
if (!object) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i in object) {
|
|
|
|
if (object.hasOwnProperty(i) && (!!object[i] || object[i] === false)) {
|
2015-12-10 17:46:58 +03:00
|
|
|
queries.push(i + '=' + encodeURIComponent(object[i]));
|
2015-11-11 07:33:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 17:46:58 +03:00
|
|
|
if (queries.length) {
|
|
|
|
return '?' + queries.join('&');
|
|
|
|
}
|
|
|
|
return '';
|
2015-11-11 07:33:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var url = {
|
2015-12-10 17:46:58 +03:00
|
|
|
config: {},
|
2015-11-11 07:33:19 +03:00
|
|
|
|
|
|
|
api: function () {
|
|
|
|
var args = Array.prototype.slice.call(arguments),
|
2015-12-10 17:46:58 +03:00
|
|
|
url = (this.config.useOrigin) ? this.config.origin + this.config.url : this.config.url,
|
2015-11-11 07:33:19 +03:00
|
|
|
queryOptions;
|
|
|
|
|
|
|
|
if (args.length && typeof args[args.length - 1] === 'object') {
|
|
|
|
queryOptions = args.pop();
|
|
|
|
} else {
|
|
|
|
queryOptions = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
queryOptions.client_id = this.config.clientId;
|
|
|
|
queryOptions.client_secret = this.config.clientSecret;
|
|
|
|
|
|
|
|
if (args.length) {
|
|
|
|
args.forEach(function (el) {
|
|
|
|
url += el.replace(/^\/|\/$/g, '') + '/';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return url + generateQueryString(queryOptions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
window.ghost = window.ghost || {};
|
2015-12-10 17:46:58 +03:00
|
|
|
url.config = window.ghost.config || {};
|
2015-11-11 07:33:19 +03:00
|
|
|
window.ghost.url = url;
|
|
|
|
}
|
2015-12-10 17:46:58 +03:00
|
|
|
|
2015-11-11 07:33:19 +03:00
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = url;
|
|
|
|
}
|
|
|
|
})();
|