2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
IDataObject,
|
2021-04-02 09:29:20 -07:00
|
|
|
IExecuteFunctions,
|
|
|
|
IHookFunctions,
|
|
|
|
ILoadOptionsFunctions,
|
2023-03-09 09:13:15 -08:00
|
|
|
JsonObject,
|
2024-11-07 03:53:05 -08:00
|
|
|
IHttpRequestOptions,
|
2024-02-14 07:29:09 -08:00
|
|
|
IHttpRequestMethods,
|
2023-03-09 09:13:15 -08:00
|
|
|
} from 'n8n-workflow';
|
2023-01-27 03:22:44 -08:00
|
|
|
import { NodeApiError } from 'n8n-workflow';
|
2021-04-02 09:29:20 -07:00
|
|
|
|
|
|
|
export async function ouraApiRequest(
|
2023-08-16 06:52:41 -07:00
|
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
2024-02-14 07:29:09 -08:00
|
|
|
method: IHttpRequestMethods,
|
2021-04-02 09:29:20 -07:00
|
|
|
resource: string,
|
|
|
|
body: IDataObject = {},
|
|
|
|
qs: IDataObject = {},
|
|
|
|
uri?: string,
|
|
|
|
option: IDataObject = {},
|
|
|
|
) {
|
2024-11-07 03:53:05 -08:00
|
|
|
let options: IHttpRequestOptions = {
|
2021-04-02 09:29:20 -07:00
|
|
|
method,
|
|
|
|
qs,
|
|
|
|
body,
|
2024-11-07 03:53:05 -08:00
|
|
|
url: uri ?? `https://api.ouraring.com/v2${resource}`,
|
2021-04-02 09:29:20 -07:00
|
|
|
json: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!Object.keys(body).length) {
|
|
|
|
delete options.body;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Object.keys(qs).length) {
|
|
|
|
delete options.qs;
|
|
|
|
}
|
|
|
|
|
|
|
|
options = Object.assign({}, options, option);
|
|
|
|
|
|
|
|
try {
|
2024-11-07 03:53:05 -08:00
|
|
|
return await this.helpers.httpRequestWithAuthentication.call(this, 'ouraApi', options);
|
2021-04-02 09:29:20 -07:00
|
|
|
} catch (error) {
|
2023-02-27 19:39:43 -08:00
|
|
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
2021-04-02 09:29:20 -07:00
|
|
|
}
|
|
|
|
}
|