Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Components] cincopa #11820

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import app from "../../cincopa.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "cincopa-add-assets-to-gallery",
name: "Add Assets to Gallery",
description: "Adds an asset or a list of assets to an existing gallery. [See the documentation](https://www.cincopa.com/media-platform/api-documentation-v2#gallery.add_item)",
version: "0.0.1",
type: "action",
props: {
app,
fid: {
propDefinition: [
app,
"fid",
],
},
rid: {
propDefinition: [
app,
"rid",
],
},
insertPosition: {
type: "string",
label: "Insert Position",
description: "Add the assets at the top or the bottom of the gallery. Options: top or bottom (default is `bottom`)",
optional: true,
options: [
"top",
"bottom",
],
},
},
methods: {
addAssetToGallery(args = {}) {
return this.app._makeRequest({
path: "/gallery.add_item.json",
...args,
});
},
},
async run({ $ }) {
const {
addAssetToGallery,
fid,
rid,
insertPosition,
} = this;

const response = await addAssetToGallery({
$,
params: {
fid,
rid: utils.parseArray(rid).join(","),
insert_position: insertPosition,
},
});

$.export("$summary", "Successfully added assets to gallery");
return response;
},
};
57 changes: 57 additions & 0 deletions components/cincopa/actions/create-gallery/create-gallery.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import app from "../../cincopa.app.mjs";

export default {
key: "cincopa-create-gallery",
name: "Create Gallery",
description: "Creates a new gallery, returning the new gallery FID (unique ID). [See the documentation](https://www.cincopa.com/media-platform/api-documentation-v2#gallery.create)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
type: "string",
label: "Name",
description: "Name of the gallery",
},
description: {
type: "string",
label: "Description",
description: "Description of the gallery",
optional: true,
},
template: {
type: "string",
label: "Template",
description: "Set the gallery skin to this template",
optional: true,
},
},
methods: {
createGallery(args = {}) {
return this.app._makeRequest({
path: "/gallery.create.json",
...args,
});
},
},
async run({ $ }) {
const {
createGallery,
name,
description,
template,
} = this;

const response = await createGallery({
$,
params: {
name,
description,
template,
},
});

$.export("$summary", `Successfully created gallery with FID \`${response.fid}\``);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import app from "../../cincopa.app.mjs";

export default {
key: "cincopa-upload-asset-from-url",
name: "Upload Asset From URL",
description: "Upload an asset from an input URL to a Cincopa gallery. [See the documentation](https://www.cincopa.com/media-platform/api-documentation-v2#asset_upload_from_url)",
version: "0.0.1",
type: "action",
props: {
app,
input: {
type: "string",
label: "Input URL",
description: "Input URL for the source asset to upload",
},
fid: {
propDefinition: [
app,
"fid",
],
},
type: {
type: "string",
label: "Type",
description: "Type of the attached asset",
optional: true,
},
},
methods: {
uploadAssetFromUrl(args = {}) {
return this.app._makeRequest({
path: "/asset.upload_from_url.json",
...args,
});
},
},
async run({ $ }) {
const {
uploadAssetFromUrl,
input,
fid,
type,
} = this;

const response = await uploadAssetFromUrl({
$,
params: {
input,
fid,
type,
},
});

$.export("$summary", `Successfully uploaded asset from URL with status ID \`${response.status_id}\``);
return response;
},
};
79 changes: 75 additions & 4 deletions components/cincopa/cincopa.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,82 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "cincopa",
propDefinitions: {},
propDefinitions: {
fid: {
type: "string",
label: "Gallery FID",
description: "Gallery FID to add the assets",
async options({ page }) {
const { galleries } = await this.listGalleries({
params: {
page: page + 1,
},
});
return galleries.map(({
fid: value, name: label,
}) => ({
value,
label,
}));
},
},
rid: {
type: "string[]",
label: "Asset RIDs",
description: "List of RIDs (assets id) to be added",
optional: true,
useQuery: true,
async options({
query: search, page,
}) {
const { items } = await this.listAssets({
params: {
search,
page: page + 1,
},
});
return items.map(({
rid: value, filename: label,
}) => ({
value,
label,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
getUrl(path) {
return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`;
},
getAuthParams(params) {
return {
...params,
api_token: this.$auth.api_token,
};
},
_makeRequest({
$ = this, path, params, ...args
} = {}) {
return axios($, {
...args,
url: this.getUrl(path),
params: this.getAuthParams(params),
});
},
listGalleries(args = {}) {
return this._makeRequest({
path: "/gallery.list.json",
...args,
});
},
listAssets(args = {}) {
return this._makeRequest({
path: "/asset.list.json",
...args,
});
},
},
};
11 changes: 11 additions & 0 deletions components/cincopa/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const BASE_URL = "https://api.cincopa.com";
const VERSION_PATH = "/v2";
const SECURITY_KEY = "securityKey";
const DEFAULT_MAX = 600;

export default {
BASE_URL,
VERSION_PATH,
SECURITY_KEY,
DEFAULT_MAX,
};
28 changes: 28 additions & 0 deletions components/cincopa/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ConfigurationError } from "@pipedream/platform";

function parseArray(value) {
try {
if (!value) {
return [];
}

if (Array.isArray(value)) {
return value;
}

const parsedValue = JSON.parse(value);

if (!Array.isArray(parsedValue)) {
throw new Error("Not an array");
}

return parsedValue;

} catch (e) {
throw new ConfigurationError("Make sure the custom expression contains a valid array object");
}
}

export default {
parseArray,
};
19 changes: 19 additions & 0 deletions components/cincopa/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@pipedream/cincopa",
"version": "0.0.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"version": "0.0.1",
"version": "0.1.0",

"description": "Pipedream Cincopa Components",
"main": "cincopa.app.mjs",
"keywords": [
"pipedream",
"cincopa"
],
"homepage": "https://pipedream.com/apps/cincopa",
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"dependencies": {
"@pipedream/platform": "^1.6.5",
"uuid": "^8.3.2"
},
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import common from "../common/webhook.mjs";
import events from "../common/events.mjs";

export default {
...common,
key: "cincopa-asset-uploaded-instant",
name: "New Asset Uploaded (Instant)",
description: "Emit new event when a new asset is uploaded. [See the documentation](https://www.cincopa.com/media-platform/api-documentation-v2#webhook.set)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getEvents() {
return events.ASSET_UPLOADED;
},
generateMeta(resource) {
return {
id: resource.id,
summary: `New Asset: ${resource.filename}`,
ts: Date.parse(resource.modified),
};
},
},
};
15 changes: 15 additions & 0 deletions components/cincopa/sources/common/events.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
GALLERY_ALL: "gallery.*",
GALLERY_CREATED: "gallery.created",
GALLERY_UPDATED: "gallery.updated",
GALLERY_DELETED: "gallery.deleted",
GALLERY_CLAIM: "gallery.claim",
GALLERY_SYNC: "gallery.sync",
GALLERY_SYNCED: "gallery.synced",
ASSET_ALL: "asset.*",
ASSET_UPLOADED: "asset.uploaded",
ASSET_SYNCED: "asset.synced",
ACCOUNT_ALL: "account.*",
ANALYTICS_ALL: "analytics.*",
LEADS_ALL: "leads.*",
};
Loading
Loading