2020-05-02 18:00:17 +02:00
|
|
|
import { createApiRequest, formatUrl } from '../utils'
|
2018-04-29 18:23:46 +02:00
|
|
|
|
2018-06-07 14:45:43 +02:00
|
|
|
export default class FitTrackeeApi {
|
2019-01-18 19:34:38 +01:00
|
|
|
static getData(target, data = {}) {
|
2020-05-02 18:00:17 +02:00
|
|
|
const url = formatUrl(target, data)
|
2018-05-28 12:35:17 +02:00
|
|
|
const params = {
|
|
|
|
url: url,
|
2018-04-29 18:23:46 +02:00
|
|
|
method: 'GET',
|
2018-05-28 12:35:17 +02:00
|
|
|
type: 'application/json',
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(params)
|
2018-04-29 18:23:46 +02:00
|
|
|
}
|
2018-04-30 20:08:18 +02:00
|
|
|
|
2018-04-30 21:38:09 +02:00
|
|
|
static addData(target, data) {
|
2018-05-28 12:35:17 +02:00
|
|
|
const params = {
|
2019-01-18 19:34:38 +01:00
|
|
|
url: target,
|
2018-04-30 21:38:09 +02:00
|
|
|
method: 'POST',
|
2018-05-28 12:35:17 +02:00
|
|
|
body: data,
|
|
|
|
type: 'application/json',
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(params)
|
2018-04-30 21:38:09 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 12:51:23 +02:00
|
|
|
static addDataWithFile(target, data) {
|
|
|
|
const params = {
|
2019-01-18 19:34:38 +01:00
|
|
|
url: target,
|
2018-06-12 12:51:23 +02:00
|
|
|
method: 'POST',
|
|
|
|
body: data,
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(params)
|
2018-06-12 12:51:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static postData(target, data) {
|
|
|
|
const params = {
|
2019-08-28 15:35:22 +02:00
|
|
|
url: `${target}${data.id ? `/${data.id}` : ''}`,
|
2018-06-12 12:51:23 +02:00
|
|
|
method: 'POST',
|
|
|
|
body: data,
|
|
|
|
type: 'application/json',
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(params)
|
2018-06-12 12:51:23 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 20:08:18 +02:00
|
|
|
static updateData(target, data) {
|
2018-05-28 12:35:17 +02:00
|
|
|
const params = {
|
2020-05-01 12:12:48 +02:00
|
|
|
url: `${target}${
|
|
|
|
data.id ? `/${data.id}` : data.username ? `/${data.username}` : ''
|
|
|
|
}`,
|
2018-04-30 20:08:18 +02:00
|
|
|
method: 'PATCH',
|
2018-05-28 12:35:17 +02:00
|
|
|
body: data,
|
|
|
|
type: 'application/json',
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(params)
|
2018-04-30 20:08:18 +02:00
|
|
|
}
|
2018-04-30 21:38:09 +02:00
|
|
|
|
|
|
|
static deleteData(target, id) {
|
2018-05-28 12:35:17 +02:00
|
|
|
const params = {
|
2019-01-18 19:34:38 +01:00
|
|
|
url: `${target}/${id}`,
|
2018-04-30 21:38:09 +02:00
|
|
|
method: 'DELETE',
|
2018-05-28 12:35:17 +02:00
|
|
|
type: 'application/json',
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(params)
|
2018-04-30 21:38:09 +02:00
|
|
|
}
|
2018-04-29 18:23:46 +02:00
|
|
|
}
|