first implementation
This commit is contained in:
66
src/js/api/Client.js
Normal file
66
src/js/api/Client.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import axios from 'axios'
|
||||
|
||||
class Client {
|
||||
constructor() {
|
||||
// this.warningPresent = false
|
||||
this.client = axios.create({responseType: 'json', headers: {'x-client-version': this.clientVersion()}})
|
||||
// this.client.interceptors.response.use(this.forceUpdateInterceptor)
|
||||
}
|
||||
|
||||
// csrfToken() {
|
||||
// return document.getElementsByName('csrf-token')[0].getAttribute('content')
|
||||
// }
|
||||
|
||||
clientVersion() {
|
||||
return "1.0.0"
|
||||
// FIXME: on server sync with real version numbers return chrome.runtime.getManifest().version
|
||||
}
|
||||
|
||||
// clientVersionMajor() {
|
||||
// const [major] = this.clientVersion().split('.')
|
||||
// return parseInt(major)
|
||||
// }
|
||||
|
||||
// forceUpdateInterceptor = (response) => {
|
||||
// const [serverMajor] = response.headers['x-moco-version'].split('.')
|
||||
|
||||
// // if (parseInt(serverMajor) > this.clientVersionMajor() && !this.warningPresent) {
|
||||
// // this.warningPresent = true
|
||||
// // }
|
||||
|
||||
// if (response.headers['x-moco-version'] != this.clientVersion())
|
||||
// window.updateRequired = true
|
||||
|
||||
// return response
|
||||
// }
|
||||
|
||||
get(url, config = {}) {
|
||||
return this.client.get(url, config)
|
||||
}
|
||||
|
||||
post(url, data) {
|
||||
return this.client.post(url, data, {
|
||||
// headers: {'x-csrf-token': this.csrfToken()}
|
||||
})
|
||||
}
|
||||
|
||||
put(url, data) {
|
||||
return this.client.put(url, data, {
|
||||
// headers: { 'x-csrf-token': this.csrfToken() }
|
||||
})
|
||||
}
|
||||
|
||||
patch(url, data) {
|
||||
return this.client.patch(url, data, {
|
||||
// headers: { 'x-csrf-token': this.csrfToken() }
|
||||
})
|
||||
}
|
||||
|
||||
delete(url) {
|
||||
return this.client.delete(url, {
|
||||
// headers: { 'x-csrf-token': this.csrfToken() }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default new Client()
|
||||
5
src/js/api/projects.js
Normal file
5
src/js/api/projects.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import client from './Client'
|
||||
|
||||
export function getProjects(subdomain, apiKey) {
|
||||
return client.post(`https://${subdomain}.mocoapp.com/api/browser_extensions/session`, { api_key: apiKey })
|
||||
}
|
||||
5
src/js/api/session.js
Normal file
5
src/js/api/session.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import client from './Client'
|
||||
|
||||
export function login(subdomain, apiKey) {
|
||||
return client.post(`https://${subdomain}.mocoapp.com/api/browser_extensions/session`, { api_key: apiKey })
|
||||
}
|
||||
Reference in New Issue
Block a user