1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-10-08 10:39:01 +03:00
This commit is contained in:
Ricardo Espinoza 2020-01-01 10:58:27 -05:00
parent a6403fcc81
commit c490d4bc84
3 changed files with 154 additions and 95 deletions

View File

@ -40,6 +40,29 @@ export async function wordpressApiRequest(this: IExecuteFunctions | IExecuteSing
}
}
export async function intercomApiRequestAllItems(this: IExecuteFunctions, propertyName: string, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = [];
let responseData;
query.per_page = 10;
query.page = 1;
let uri: string | undefined;
do {
responseData = await wordpressApiRequest.call(this, method, endpoint, body, query, uri);
uri = responseData.pages.next;
} while (
responseData.pages !== undefined &&
responseData.pages.next !== undefined &&
responseData.pages.next !== null
);
return returnData;
}
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
let result;
try {

View File

@ -31,39 +31,22 @@ export const postFields = [
/* -------------------------------------------------------------------------- */
{
displayName: 'ID',
name: 'id',
displayName: 'Title',
name: 'title',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: [
'user',
'post',
],
operation: [
'create',
]
},
},
description: 'The unique identifier of the customer',
},
{
displayName: 'JSON Parameters',
name: 'jsonParameters',
type: 'boolean',
default: false,
description: '',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'create',
]
},
}
description: 'The title for the post',
},
{
displayName: 'Additional Fields',
@ -74,7 +57,7 @@ export const postFields = [
displayOptions: {
show: {
resource: [
'user',
'post',
],
operation: [
'create',
@ -83,84 +66,108 @@ export const postFields = [
},
options: [
{
displayName: 'Email',
name: 'email',
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
description: 'The table to create the row in.',
description: 'The content for the post',
},
{
displayName: 'Slug',
name: 'slug',
type: 'string',
default: '',
description: 'An alphanumeric identifier for the object unique to its type.',
},
{
displayName: 'Password',
name: 'password',
type: 'string',
default: '',
description: 'A password to protect access to the content and excerpt.',
},
{
displayName: 'Status',
name: 'status',
type: 'options',
options: [
{
name: 'Publish',
value: 'publish'
},
{
name: 'Future',
value: 'future'
},
{
name: 'Draft',
value: 'draft'
},
{
name: 'Pending',
value: 'pending'
},
{
name: 'Private',
value: 'private'
},
],
default: '',
description: 'A named status for the post.',
},
{
displayName: 'Content Status',
name: 'contentStatus',
type: 'options',
options: [
{
name: 'Open',
value: 'open'
},
{
name: 'Close',
value: 'closed'
},
],
default: '',
description: 'Whether or not comments are open on the post.',
},
{
displayName: 'Ping Status',
name: 'pingStatus',
type: 'options',
options: [
{
name: 'Open',
value: 'open'
},
{
name: 'Close',
value: 'closed'
},
],
default: '',
description: 'Whether or not comments are open on the post.',
},
{
displayName: 'Sticky',
name: 'sticky',
type: 'boolean',
default: '',
description: 'Whether or not the object should be treated as sticky.',
},
{
displayName: 'Categories',
name: 'categories',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getCategories',
},
default: [],
description: 'The terms assigned to the object in the category taxonomy.',
},
]
},
{
displayName: 'Data',
name: 'dataAttributesUi',
placeholder: 'Add Data',
description: 'key value pairs that represent the custom user properties you want to update',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'create',
],
jsonParameters: [
false,
],
},
},
options: [
{
name: 'dataAttributesValues',
displayName: 'Data',
values: [
{
displayName: 'Key',
name: 'key',
type: 'string',
default: '',
description: 'Name of the property to set.',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the property to set.',
},
]
},
],
},
{
displayName: 'Data',
name: 'dataAttributesJson',
type: 'json',
default: '',
required: false,
typeOptions: {
alwaysOpenEditWindow: true,
},
description: 'key value pairs that represent the custom user properties you want to update',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'create',
],
jsonParameters: [
true,
],
},
},
},
/* -------------------------------------------------------------------------- */
/* user:alias */

View File

@ -6,6 +6,8 @@ import {
INodeTypeDescription,
INodeExecutionData,
INodeType,
ILoadOptionsFunctions,
INodePropertyOptions,
} from 'n8n-workflow';
import {
wordpressApiRequest,
@ -56,6 +58,33 @@ export class Wordpress implements INodeType {
],
};
methods = {
loadOptions: {
// Get all the available categories to display them to user so that he can
// select them easily
async getCategories(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
let categories;
try {
categories = await wordpressApiRequest.call(this, 'GET', '/categories', {});
} catch (err) {
throw new Error(`Mandrill Error: ${err}`);
}
for (const category of categories) {
const categoryName = category.name;
const categoryId = category.id;
returnData.push({
name: categoryName,
value: categoryId,
});
}
return returnData;
}
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const credentials = this.getCredentials('flowApi');