2022-08-01 13:47:55 -07:00
|
|
|
import { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
|
|
|
|
2022-11-08 06:28:21 -08:00
|
|
|
import { IDataObject, IHookFunctions, IWebhookFunctions } from 'n8n-workflow';
|
2022-08-01 13:47:55 -07:00
|
|
|
|
|
|
|
import { beeminderApiRequest, beeminderApiRequestAllItems } from './GenericFunctions';
|
|
|
|
|
|
|
|
export async function createDatapoint(
|
|
|
|
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
|
|
|
|
data: IDataObject,
|
|
|
|
) {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('beeminderApi');
|
2021-01-12 03:40:49 -08:00
|
|
|
|
|
|
|
const endpoint = `/users/${credentials.user}/goals/${data.goalName}/datapoints.json`;
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
return beeminderApiRequest.call(this, 'POST', endpoint, data);
|
2021-01-12 03:40:49 -08:00
|
|
|
}
|
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
export async function getAllDatapoints(
|
|
|
|
this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions,
|
|
|
|
data: IDataObject,
|
|
|
|
) {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('beeminderApi');
|
2021-01-12 03:40:49 -08:00
|
|
|
|
|
|
|
const endpoint = `/users/${credentials.user}/goals/${data.goalName}/datapoints.json`;
|
|
|
|
|
|
|
|
if (data.count !== undefined) {
|
|
|
|
return beeminderApiRequest.call(this, 'GET', endpoint, {}, data);
|
|
|
|
}
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
return beeminderApiRequestAllItems.call(this, 'GET', endpoint, {}, data);
|
2021-01-12 03:40:49 -08:00
|
|
|
}
|
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
export async function updateDatapoint(
|
|
|
|
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
|
|
|
|
data: IDataObject,
|
|
|
|
) {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('beeminderApi');
|
2021-01-12 03:40:49 -08:00
|
|
|
|
|
|
|
const endpoint = `/users/${credentials.user}/goals/${data.goalName}/datapoints/${data.datapointId}.json`;
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
return beeminderApiRequest.call(this, 'PUT', endpoint, data);
|
2021-01-12 03:40:49 -08:00
|
|
|
}
|
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
export async function deleteDatapoint(
|
|
|
|
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
|
|
|
|
data: IDataObject,
|
|
|
|
) {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('beeminderApi');
|
2021-01-12 03:40:49 -08:00
|
|
|
|
|
|
|
const endpoint = `/users/${credentials.user}/goals/${data.goalName}/datapoints/${data.datapointId}.json`;
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
return beeminderApiRequest.call(this, 'DELETE', endpoint);
|
2021-01-12 03:40:49 -08:00
|
|
|
}
|