From c490d4bc84b9985464a7d4067f136fc1383aa89a Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Wed, 1 Jan 2020 10:58:27 -0500 Subject: [PATCH] done --- .../nodes/Wordpress/GenericFunctions.ts | 23 ++ .../nodes/Wordpress/PostDescription.ts | 197 +++++++++--------- .../nodes/Wordpress/Wordpress.node.ts | 29 +++ 3 files changed, 154 insertions(+), 95 deletions(-) diff --git a/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts b/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts index 46560b0bc2..7148eed754 100644 --- a/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts @@ -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 { // 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 { diff --git a/packages/nodes-base/nodes/Wordpress/PostDescription.ts b/packages/nodes-base/nodes/Wordpress/PostDescription.ts index b07840fd80..f914972d6e 100644 --- a/packages/nodes-base/nodes/Wordpress/PostDescription.ts +++ b/packages/nodes-base/nodes/Wordpress/PostDescription.ts @@ -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 */ diff --git a/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts b/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts index 0c31f57724..7f85df0092 100644 --- a/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts +++ b/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts @@ -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 { + 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 { const credentials = this.getCredentials('flowApi');