|
|
|
@ -11,8 +11,8 @@ export const CONTENT_TYPE_FORM = "x-www-form-urlencoded";
|
|
|
|
|
//** API URLS **//
|
|
|
|
|
export const API_GET_PAGES = "/api/v1/page/published";
|
|
|
|
|
export const API_GET_FEATURED = "/api/v1/page/featured";
|
|
|
|
|
export const API_GET_MENU = "/api/v1/page/menu";
|
|
|
|
|
export const API_GET_PAGE = "/api/v1/page/single";
|
|
|
|
|
export const API_GET_MENU = "/api/v1/page/menu";
|
|
|
|
|
export const API_GET_TAGS = "/api/v1/page/tags";
|
|
|
|
|
|
|
|
|
|
//** API TASKS **//
|
|
|
|
@ -20,15 +20,12 @@ export const TASK_GET_CONTENT = "retrieveContent";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fipamo Content API
|
|
|
|
|
* class for retrieving page data from install
|
|
|
|
|
*/
|
|
|
|
|
export default class FipamoAPI {
|
|
|
|
|
//--------------------------
|
|
|
|
|
// constructor
|
|
|
|
|
//--------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @constructor
|
|
|
|
|
* @param {string} baseURL - url of site
|
|
|
|
|
* @param {string} baseURL - url of site; uses local when empty
|
|
|
|
|
* @param {string} key - user api key
|
|
|
|
|
*/
|
|
|
|
|
constructor(baseURL = null, key = null) {
|
|
|
|
@ -41,32 +38,29 @@ export default class FipamoAPI {
|
|
|
|
|
// methods
|
|
|
|
|
//--------------------------
|
|
|
|
|
|
|
|
|
|
getPages(key) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
this.baseURL
|
|
|
|
|
? this.baseURL + API_GET_PAGES + "?key=" + key
|
|
|
|
|
: API_GET_PAGES,
|
|
|
|
|
TASK_GET_CONTENT,
|
|
|
|
|
REQUEST_TYPE_GET
|
|
|
|
|
)
|
|
|
|
|
.then((result) => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
/**
|
|
|
|
|
* Method for retrieving page data
|
|
|
|
|
* @param {string} type - type of pages being retrieved; defaults to published
|
|
|
|
|
*/
|
|
|
|
|
pages(type = null) {
|
|
|
|
|
//set url based on request type
|
|
|
|
|
let requestURL = "";
|
|
|
|
|
switch (type) {
|
|
|
|
|
default:
|
|
|
|
|
case "published":
|
|
|
|
|
requestURL = API_GET_PAGES + "?key=" + this.key;
|
|
|
|
|
break;
|
|
|
|
|
case "featured":
|
|
|
|
|
requestURL = API_GET_FEATURED + "?key=" + this.key;
|
|
|
|
|
break;
|
|
|
|
|
case "menu":
|
|
|
|
|
requestURL = API_GET_MENU + "?key=" + this.key;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getFeatured(key) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
this.baseURL
|
|
|
|
|
? this.baseURL + API_GET_FEATURED + "?key=" + key
|
|
|
|
|
: API_GET_FEATURED,
|
|
|
|
|
TASK_GET_CONTENT,
|
|
|
|
|
REQUEST_TYPE_GET
|
|
|
|
|
this.baseURL ? this.baseURL + requestURL : requestURL,
|
|
|
|
|
TASK_GET_CONTENT
|
|
|
|
|
)
|
|
|
|
|
.then((result) => {
|
|
|
|
|
resolve(result);
|
|
|
|
@ -76,13 +70,16 @@ export default class FipamoAPI {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getMenu(key) {
|
|
|
|
|
/**
|
|
|
|
|
* Method for retrieving single page
|
|
|
|
|
* @param {string} id - uuid of desired page
|
|
|
|
|
*/
|
|
|
|
|
page(id) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
this.baseURL
|
|
|
|
|
? this.baseURL + API_GET_MENU + "?key=" + key
|
|
|
|
|
: API_GET_MENU,
|
|
|
|
|
? this.baseURL + API_GET_PAGE + "/" + id + "?key=" + this.key
|
|
|
|
|
: API_GET_PAGE + "/" + id + "?key=" + this.key,
|
|
|
|
|
TASK_GET_CONTENT,
|
|
|
|
|
REQUEST_TYPE_GET
|
|
|
|
|
)
|
|
|
|
@ -95,12 +92,15 @@ export default class FipamoAPI {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getTags(key) {
|
|
|
|
|
/**
|
|
|
|
|
* Method for retrieving all tags used by pages
|
|
|
|
|
*/
|
|
|
|
|
tags() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
this.baseURL
|
|
|
|
|
? this.baseURL + API_GET_TAGS + "?key=" + key
|
|
|
|
|
: API_GET_TAGS,
|
|
|
|
|
? this.baseURL + API_GET_TAGS + "?key=" + this.key
|
|
|
|
|
: API_GET_TAGS + "?key=" + this.key,
|
|
|
|
|
TASK_GET_CONTENT,
|
|
|
|
|
REQUEST_TYPE_GET
|
|
|
|
|
)
|
|
|
|
@ -113,24 +113,6 @@ export default class FipamoAPI {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPage(id, key) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
//API_GET_PAGE + "/" + id + "?key=" + key,
|
|
|
|
|
this.baseURL
|
|
|
|
|
? this.baseURL + API_GET_PAGE + "/" + id + "?key=" + key
|
|
|
|
|
: API_GET_PAGE,
|
|
|
|
|
TASK_GET_CONTENT,
|
|
|
|
|
REQUEST_TYPE_GET
|
|
|
|
|
)
|
|
|
|
|
.then((result) => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//--------------------------
|
|
|
|
|
// private
|
|
|
|
|
//--------------------------
|
|
|
|
@ -162,12 +144,6 @@ export default class FipamoAPI {
|
|
|
|
|
"Content-type",
|
|
|
|
|
"application/" + contentType
|
|
|
|
|
);
|
|
|
|
|
/**
|
|
|
|
|
request.setRequestHeader(
|
|
|
|
|
"Access-Control-Allow-Origin",
|
|
|
|
|
self.baseURL
|
|
|
|
|
);
|
|
|
|
|
**/
|
|
|
|
|
request.send(JSON.stringify(requestData));
|
|
|
|
|
break;
|
|
|
|
|
case CONTENT_TYPE_FORM:
|
|
|
|
|