Improvements

This commit is contained in:
ricardo 2021-03-01 20:27:50 -05:00
parent c3dfa97f5a
commit 29aed35661
7 changed files with 59 additions and 61 deletions

View file

@ -3,12 +3,12 @@ import {
NodePropertyTypes,
} from 'n8n-workflow';
export class InstagramBasicDisplayOAuth2Api implements ICredentialType {
name = 'instagramBasicDisplayOAuth2Api';
export class InstagramOAuth2Api implements ICredentialType {
name = 'instagramOAuth2Api';
extends = [
'oAuth2Api',
];
displayName = 'Instagram Basic Display OAuth2 API';
displayName = 'Instagram OAuth2 API';
properties = [
{
displayName: 'Authorization URL',

View file

@ -39,7 +39,7 @@ export async function instagramBasicDisplayApiRequest(
try {
//@ts-ignore
return await this.helpers.requestOAuth2.call(this, 'instagramBasicDisplayOAuth2Api', options, { tokenType: 'Bearer' });
return await this.helpers.requestOAuth2.call(this, 'instagramOAuth2Api', options, { tokenType: 'Bearer' });
} catch (error) {
if (error?.error?.error?.message) {
throw new Error(`Instagram error response [${error.statusCode}]: ${error?.error?.error?.message}`);
@ -64,7 +64,7 @@ export async function instagramBasicDisplayApiRequestAllItems(
const type = this.getNodeParameter('type', 0) as 'userMedia' | 'albumMedia' | 'fieldsAndEdges';
const returnAll = this.getNodeParameter('returnAll', 0, false) as boolean;
const limit = this.getNodeParameter('limit', 0) as number;
const limit = this.getNodeParameter('limit', 0, 0) as number;
do {
responseData = await instagramBasicDisplayApiRequest.call(this, method, endpoint, qs, body);

View file

@ -24,24 +24,24 @@ import {
mediaOperations,
} from './MediaDescription';
export class InstagramBasicDisplay implements INodeType {
export class Instagram implements INodeType {
description: INodeTypeDescription = {
displayName: 'Instagram Basic Display',
name: 'instagramBasicDisplay',
displayName: 'Instagram',
name: 'instagram',
icon: 'file:instagram.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume the Instagram Basic Display API',
defaults: {
name: 'Instagram Basic Display',
name: 'Instagram',
color: '#833ab4',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'instagramBasicDisplayOAuth2Api',
name: 'instagramOAuth2Api',
required: true,
},
],
@ -63,10 +63,10 @@ export class InstagramBasicDisplay implements INodeType {
default: 'user',
description: 'Resource to consume',
},
...userOperations,
...userFields,
...mediaOperations,
...mediaFields,
...userOperations,
...userFields,
...mediaOperations,
...mediaFields,
],
};
@ -83,9 +83,9 @@ export class InstagramBasicDisplay implements INodeType {
if (resource === 'user') {
// *********************************************************************
// user
// *********************************************************************
// *********************************************************************
// user
// *********************************************************************
if (operation === 'get') {
@ -107,9 +107,22 @@ export class InstagramBasicDisplay implements INodeType {
} else if (resource === 'media') {
// *********************************************************************
// media
// *********************************************************************
// *********************************************************************
// media
// *********************************************************************
if (operation === 'get') {
// ----------------------------------
// media: get
// ----------------------------------
const mediaId = this.getNodeParameter('mediaId', i);
const qs: IDataObject = {
fields: 'caption,id,media_type,media_url,permalink,thumbnail_url,timestamp,username',
};
responseData = await instagramBasicDisplayApiRequestAllItems.call(this, 'GET', `/${mediaId}`, qs);
}
if (operation === 'getAll') {
@ -129,16 +142,9 @@ export class InstagramBasicDisplay implements INodeType {
} else if (type === 'albumMedia') {
const albumId = this.getNodeParameter('albumId', i);
responseData = await instagramBasicDisplayApiRequestAllItems.call(this, 'GET', `/${albumId}/children`);
} else if (type === 'fieldsAndEdges') {
const mediaId = this.getNodeParameter('mediaId', i);
const qs: IDataObject = {
fields: 'caption,id,media_type,media_url,permalink,thumbnail_url,timestamp,username',
};
responseData = await instagramBasicDisplayApiRequestAllItems.call(this, 'GET', `/${mediaId}`, qs);
responseData = await instagramBasicDisplayApiRequestAllItems.call(this, 'GET', `/${mediaId}/children`);
}
}
}
@ -154,7 +160,6 @@ export class InstagramBasicDisplay implements INodeType {
Array.isArray(responseData)
? returnData.push(...responseData)
: returnData.push(responseData);
}
return [this.helpers.returnJsonArray(returnData)];

View file

@ -26,6 +26,26 @@ export const mediaOperations = [
] as INodeProperties[];
export const mediaFields = [
// ----------------------------------
// media:get
// ----------------------------------
{
displayName: 'Media ID',
name: 'mediaId',
type: 'string',
default: '',
placeholder: '17998581729291220',
displayOptions: {
show: {
resource: [
'media',
],
operation: [
'get',
],
},
},
},
// ----------------------------------
// media: getAll
// ----------------------------------
@ -57,11 +77,6 @@ export const mediaFields = [
value: 'albumMedia',
description: 'All images and videos in an album.',
},
{
name: 'Fields & Edges',
value: 'fieldsAndEdges',
description: 'All fields and edges of an image, video or album.',
},
],
},
{
@ -86,12 +101,11 @@ export const mediaFields = [
},
},
{
displayName: 'Album ID',
name: 'albumId',
displayName: 'Media ID',
name: 'mediaId',
type: 'string',
default: '',
placeholder: '17998581729291220',
description: 'ID of album whose media to return.',
displayOptions: {
show: {
resource: [
@ -106,27 +120,6 @@ export const mediaFields = [
},
},
},
{
displayName: 'Media ID',
name: 'mediaId',
type: 'string',
default: '',
placeholder: '17998581729291220',
description: 'ID of media whose fields and edges to return.',
displayOptions: {
show: {
resource: [
'media',
],
operation: [
'getAll',
],
type: [
'fieldsAndEdges',
],
},
},
},
{
displayName: 'Return All',
name: 'returnAll',

View file

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -120,7 +120,7 @@
"dist/credentials/HunterApi.credentials.js",
"dist/credentials/IterableApi.credentials.js",
"dist/credentials/Imap.credentials.js",
"dist/credentials/InstagramBasicDisplayOAuth2Api.credentials.js",
"dist/credentials/InstagramOAuth2Api.credentials.js",
"dist/credentials/IntercomApi.credentials.js",
"dist/credentials/InvoiceNinjaApi.credentials.js",
"dist/credentials/JiraSoftwareCloudApi.credentials.js",
@ -374,7 +374,7 @@
"dist/nodes/HumanticAI/HumanticAi.node.js",
"dist/nodes/Hunter/Hunter.node.js",
"dist/nodes/If.node.js",
"dist/nodes/InstagramBasicDisplay/InstagramBasicDisplay.node.js",
"dist/nodes/Instagram/Instagram.node.js",
"dist/nodes/Iterable/Iterable.node.js",
"dist/nodes/Intercom/Intercom.node.js",
"dist/nodes/Interval.node.js",