n8n/packages/nodes-base/nodes/Oura/GenericFunctions.ts
Michael Kret 91d7e16c81
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
2022-08-17 17:50:24 +02:00

49 lines
1 KiB
TypeScript

import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
IHookFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';
import { IDataObject, NodeApiError, NodeOperationError } from 'n8n-workflow';
export async function ouraApiRequest(
this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
method: string,
resource: string,
body: IDataObject = {},
qs: IDataObject = {},
uri?: string,
option: IDataObject = {},
) {
const credentials = await this.getCredentials('ouraApi');
let options: OptionsWithUri = {
headers: {
Authorization: `Bearer ${credentials.accessToken}`,
},
method,
qs,
body,
uri: uri || `https://api.ouraring.com/v1${resource}`,
json: true,
};
if (!Object.keys(body).length) {
delete options.body;
}
if (!Object.keys(qs).length) {
delete options.qs;
}
options = Object.assign({}, options, option);
try {
return await this.helpers.request!(options);
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
}