-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michelangelo Partipilo
committed
Feb 6, 2018
1 parent
f7a578a
commit 805b3eb
Showing
5 changed files
with
52 additions
and
104 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,3 @@ | ||
{ | ||
"env": { | ||
"browser": false, | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": false | ||
}, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-const-assign": "warn", | ||
"no-this-before-super": "warn", | ||
"no-undef": "warn", | ||
"no-unreachable": "warn", | ||
"no-unused-vars": "warn", | ||
"constructor-super": "warn", | ||
"valid-typeof": "warn" | ||
} | ||
"extends": "standard" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,93 @@ | ||
const qs = require(`query-string`); | ||
const fetch = require(`node-fetch`); | ||
const qs = require(`query-string`) | ||
const fetch = require('isomorphic-fetch') | ||
|
||
const defaultOptions = { | ||
mode: "cors", | ||
cache: "default" | ||
mode: 'cors', | ||
cache: 'default' | ||
} | ||
|
||
class Cockpit { | ||
constructor({ host, accessToken }) { | ||
this.host = host; | ||
this.accessToken = accessToken; | ||
constructor ({ host, accessToken }) { | ||
this.host = host | ||
this.accessToken = accessToken | ||
this.queryParams = { | ||
token: this.accessToken | ||
}; | ||
} | ||
} | ||
|
||
async fetchData(apiPath, options) { | ||
// @param {string} apiPath | ||
// @param {object} options | ||
async fetchData (apiPath, options) { | ||
const requestInit = { | ||
...options, | ||
...defaultOptions | ||
}; | ||
} | ||
|
||
const hostWithToken = `${this.host}${apiPath}?${qs.stringify(this.queryParams)}`; | ||
const hostWithToken = `${this.host}${apiPath}?${qs.stringify(this.queryParams)}` | ||
|
||
const response = await fetch(hostWithToken, requestInit); | ||
const json = await response.json(); | ||
const response = await fetch(hostWithToken, requestInit) | ||
const json = await response.json() | ||
|
||
return json; | ||
return json | ||
} | ||
|
||
// @param {string} apiPath | ||
async fetchDataText(apiPath, options, additionalOptions) { | ||
async fetchDataText (apiPath, options, additionalOptions) { | ||
const requestInit = { | ||
...options, | ||
...defaultOptions | ||
}; | ||
} | ||
|
||
const hostWithToken = `${this.host}${apiPath}?${qs.stringify(this.queryParams)}&${qs.stringify(additionalOptions)}`; | ||
const hostWithToken = `${this.host}${apiPath}?${qs.stringify(this.queryParams)}&${qs.stringify(additionalOptions)}` | ||
|
||
console.log(hostWithToken); | ||
|
||
const response = await fetch(hostWithToken, requestInit); | ||
const result = await response.text(); | ||
const response = await fetch(hostWithToken, requestInit) | ||
const result = await response.text() | ||
|
||
return result; | ||
return result | ||
} | ||
|
||
// @param {string} collection | ||
async collectionSchema(collection) { | ||
return this.fetchData(`/api/collections/collection/${collection}`, { method: "GET" }); | ||
async collectionSchema (collection) { | ||
return this.fetchData(`/api/collections/collection/${collection}`, { method: 'GET' }) | ||
} | ||
|
||
// @param {string} collection | ||
async collectionEntries(collection) { | ||
return this.fetchData(`/api/collections/get/${collection}`, { method: "GET" }); | ||
async collectionEntries (collection) { | ||
return this.fetchData(`/api/collections/get/${collection}`, { method: 'GET' }) | ||
} | ||
|
||
// @param {string} collection | ||
// @param {Request} options | ||
async collectionEntriesFiltered(collection, options) { | ||
async collectionEntriesFiltered (collection, options) { | ||
return this.fetchData(`/api/collections/get/${collection}`, { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(options) | ||
}); | ||
}) | ||
} | ||
|
||
// @param {string} region | ||
async regionRenderedTemplate(region) { | ||
return this.fetchData(`/api/regions/get/${region}`, { method: "GET" }); | ||
async regionRenderedTemplate (region) { | ||
return this.fetchData(`/api/regions/get/${region}`, { method: 'GET' }) | ||
} | ||
|
||
// @param {string} region | ||
async regionFormData(region) { | ||
return this.fetchData(`/api/regions/data/${region}`, { method: "GET" }); | ||
async regionFormData (region) { | ||
return this.fetchData(`/api/regions/data/${region}`, { method: 'GET' }) | ||
} | ||
|
||
async assets() { | ||
return this.fetchData(`/api/cockpit/assets`, { method: "GET" }); | ||
async assets () { | ||
return this.fetchData(`/api/cockpit/assets`, { method: 'GET' }) | ||
} | ||
|
||
async image(assetId, {width, height}) { | ||
return this.fetchDataText(`/api/cockpit/image`, { method: "GET" }, { | ||
async image (assetId, {width, height}) { | ||
return this.fetchDataText(`/api/cockpit/image`, { method: 'GET' }, { | ||
src: assetId, | ||
w: width, | ||
h: height, | ||
d: 1 | ||
}); | ||
}) | ||
} | ||
} | ||
|
||
exports.Cockpit = Cockpit; | ||
exports.Cockpit = Cockpit |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters