n8n/packages/nodes-base/nodes/Segment/GenericFunctions.ts

40 lines
857 B
TypeScript
Raw Normal View History

2020-01-23 09:27:28 -08:00
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
IHookFunctions,
ILoadOptionsFunctions,
IWebhookFunctions,
} from 'n8n-core';
import { IDataObject } from 'n8n-workflow';
2020-01-23 09:27:28 -08:00
export async function segmentApiRequest(
this:
| IHookFunctions
| IExecuteFunctions
| IExecuteSingleFunctions
| ILoadOptionsFunctions
| IWebhookFunctions,
method: string,
resource: string,
body: any = {},
qs: IDataObject = {},
uri?: string,
_option: IDataObject = {},
): Promise<any> {
2020-01-23 09:27:28 -08:00
const options: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
},
method,
qs,
body,
uri: uri || `https://api.segment.io/v1${resource}`,
2020-10-22 06:46:03 -07:00
json: true,
2020-01-23 09:27:28 -08:00
};
if (!Object.keys(body).length) {
delete options.body;
}
return this.helpers.requestWithAuthentication.call(this, 'segmentApi', options);
2020-01-23 09:27:28 -08:00
}