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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
864 B
TypeScript
Raw Normal View History

import type {
IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions,
IHttpRequestMethods,
IHttpRequestOptions,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
2020-10-21 14:30:07 -07:00
export async function pushoverApiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions,
method: IHttpRequestMethods,
path: string,
body: any = {},
qs: IDataObject = {},
_option = {},
): Promise<any> {
const options: IHttpRequestOptions = {
headers: {
'Content-Type': 'multipart/form-data',
},
2020-10-21 14:30:07 -07:00
method,
body,
2020-10-21 14:30:07 -07:00
qs,
url: `https://api.pushover.net/1${path}`,
2020-10-21 14:30:07 -07:00
json: true,
};
2020-10-21 14:30:07 -07:00
try {
if (Object.keys(body as IDataObject).length === 0) {
2020-10-21 14:30:07 -07:00
delete options.body;
}
return await this.helpers.requestWithAuthentication.call(this, 'pushoverApi', options);
2020-10-21 14:30:07 -07:00
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
2020-10-21 14:30:07 -07:00
}
}