Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Michelangelo Partipilo committed Feb 6, 2018
1 parent f7a578a commit 805b3eb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 104 deletions.
20 changes: 0 additions & 20 deletions .codeclimate.yml

This file was deleted.

22 changes: 1 addition & 21 deletions .eslintrc.json
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"
}
80 changes: 40 additions & 40 deletions index.js
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
22 changes: 0 additions & 22 deletions jsconfig.json

This file was deleted.

12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
},
"homepage": "https://github.com/mpartipilo/cockpit-api-client#readme",
"dependencies": {
"node-fetch": "^1.7.3",
"isomorphic-fetch": "^2.2.1",
"query-string": "^5.0.1"
},
"devDependencies": {
"eslint": "^4.17.0",
"eslint-config-prettier": "^2.6.0",
"eslint-config-standard": "^11.0.0-beta.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-node": "^6.0.0",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1",
"prettier": "^1.7.4"
}
}

0 comments on commit 805b3eb

Please sign in to comment.