Skip to content

Commit efce573

Browse files
committed
Tested components
1 parent ca54ba8 commit efce573

File tree

12 files changed

+456
-4
lines changed

12 files changed

+456
-4
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../cincopa.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "cincopa-add-assets-to-gallery",
6+
name: "Add Assets to Gallery",
7+
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)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
fid: {
13+
propDefinition: [
14+
app,
15+
"fid",
16+
],
17+
},
18+
rid: {
19+
propDefinition: [
20+
app,
21+
"rid",
22+
],
23+
},
24+
insertPosition: {
25+
type: "string",
26+
label: "Insert Position",
27+
description: "Add the assets at the top or the bottom of the gallery. Options: top or bottom (default is `bottom`)",
28+
optional: true,
29+
options: [
30+
"top",
31+
"bottom",
32+
],
33+
},
34+
},
35+
methods: {
36+
addAssetToGallery(args = {}) {
37+
return this.app._makeRequest({
38+
path: "/gallery.add_item.json",
39+
...args,
40+
});
41+
},
42+
},
43+
async run({ $ }) {
44+
const {
45+
addAssetToGallery,
46+
fid,
47+
rid,
48+
insertPosition,
49+
} = this;
50+
51+
const response = await addAssetToGallery({
52+
$,
53+
params: {
54+
fid,
55+
rid: utils.parseArray(rid).join(","),
56+
insert_position: insertPosition,
57+
},
58+
});
59+
60+
$.export("$summary", "Successfully added assets to gallery");
61+
return response;
62+
},
63+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import app from "../../cincopa.app.mjs";
2+
3+
export default {
4+
key: "cincopa-create-gallery",
5+
name: "Create Gallery",
6+
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)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
type: "string",
13+
label: "Name",
14+
description: "Name of the gallery",
15+
},
16+
description: {
17+
type: "string",
18+
label: "Description",
19+
description: "Description of the gallery",
20+
optional: true,
21+
},
22+
template: {
23+
type: "string",
24+
label: "Template",
25+
description: "Set the gallery skin to this template",
26+
optional: true,
27+
},
28+
},
29+
methods: {
30+
createGallery(args = {}) {
31+
return this.app._makeRequest({
32+
path: "/gallery.create.json",
33+
...args,
34+
});
35+
},
36+
},
37+
async run({ $ }) {
38+
const {
39+
createGallery,
40+
name,
41+
description,
42+
template,
43+
} = this;
44+
45+
const response = await createGallery({
46+
$,
47+
params: {
48+
name,
49+
description,
50+
template,
51+
},
52+
});
53+
54+
$.export("$summary", `Successfully created gallery with FID \`${response.fid}\``);
55+
return response;
56+
},
57+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import app from "../../cincopa.app.mjs";
2+
3+
export default {
4+
key: "cincopa-upload-asset-from-url",
5+
name: "Upload Asset From URL",
6+
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)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
input: {
12+
type: "string",
13+
label: "Input URL",
14+
description: "Input URL for the source asset to upload",
15+
},
16+
fid: {
17+
propDefinition: [
18+
app,
19+
"fid",
20+
],
21+
},
22+
type: {
23+
type: "string",
24+
label: "Type",
25+
description: "Type of the attached asset",
26+
optional: true,
27+
},
28+
},
29+
methods: {
30+
uploadAssetFromUrl(args = {}) {
31+
return this.app._makeRequest({
32+
path: "/asset.upload_from_url.json",
33+
...args,
34+
});
35+
},
36+
},
37+
async run({ $ }) {
38+
const {
39+
uploadAssetFromUrl,
40+
input,
41+
fid,
42+
type,
43+
} = this;
44+
45+
const response = await uploadAssetFromUrl({
46+
$,
47+
params: {
48+
input,
49+
fid,
50+
type,
51+
},
52+
});
53+
54+
$.export("$summary", `Successfully uploaded asset from URL with status ID \`${response.status_id}\``);
55+
return response;
56+
},
57+
};

components/cincopa/cincopa.app.mjs

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,82 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "cincopa",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
fid: {
9+
type: "string",
10+
label: "Gallery FID",
11+
description: "Gallery FID to add the assets",
12+
async options({ page }) {
13+
const { galleries } = await this.listGalleries({
14+
params: {
15+
page: page + 1,
16+
},
17+
});
18+
return galleries.map(({
19+
fid: value, name: label,
20+
}) => ({
21+
value,
22+
label,
23+
}));
24+
},
25+
},
26+
rid: {
27+
type: "string[]",
28+
label: "Asset RIDs",
29+
description: "List of RIDs (assets id) to be added",
30+
optional: true,
31+
useQuery: true,
32+
async options({
33+
query: search, page,
34+
}) {
35+
const { items } = await this.listAssets({
36+
params: {
37+
search,
38+
page: page + 1,
39+
},
40+
});
41+
return items.map(({
42+
rid: value, filename: label,
43+
}) => ({
44+
value,
45+
label,
46+
}));
47+
},
48+
},
49+
},
550
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
51+
getUrl(path) {
52+
return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`;
53+
},
54+
getAuthParams(params) {
55+
return {
56+
...params,
57+
api_token: this.$auth.api_token,
58+
};
59+
},
60+
_makeRequest({
61+
$ = this, path, params, ...args
62+
} = {}) {
63+
return axios($, {
64+
...args,
65+
url: this.getUrl(path),
66+
params: this.getAuthParams(params),
67+
});
68+
},
69+
listGalleries(args = {}) {
70+
return this._makeRequest({
71+
path: "/gallery.list.json",
72+
...args,
73+
});
74+
},
75+
listAssets(args = {}) {
76+
return this._makeRequest({
77+
path: "/asset.list.json",
78+
...args,
79+
});
980
},
1081
},
1182
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const BASE_URL = "https://api.cincopa.com";
2+
const VERSION_PATH = "/v2";
3+
const SECURITY_KEY = "securityKey";
4+
const DEFAULT_MAX = 600;
5+
6+
export default {
7+
BASE_URL,
8+
VERSION_PATH,
9+
SECURITY_KEY,
10+
DEFAULT_MAX,
11+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
3+
function parseArray(value) {
4+
try {
5+
if (!value) {
6+
return [];
7+
}
8+
9+
if (Array.isArray(value)) {
10+
return value;
11+
}
12+
13+
const parsedValue = JSON.parse(value);
14+
15+
if (!Array.isArray(parsedValue)) {
16+
throw new Error("Not an array");
17+
}
18+
19+
return parsedValue;
20+
21+
} catch (e) {
22+
throw new ConfigurationError("Make sure the custom expression contains a valid array object");
23+
}
24+
}
25+
26+
export default {
27+
parseArray,
28+
};

components/cincopa/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@pipedream/cincopa",
3+
"version": "0.0.1",
4+
"description": "Pipedream Cincopa Components",
5+
"main": "cincopa.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"cincopa"
9+
],
10+
"homepage": "https://pipedream.com/apps/cincopa",
11+
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12+
"dependencies": {
13+
"@pipedream/platform": "^1.6.5",
14+
"uuid": "^8.3.2"
15+
},
16+
"publishConfig": {
17+
"access": "public"
18+
}
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import common from "../common/webhook.mjs";
2+
import events from "../common/events.mjs";
3+
4+
export default {
5+
...common,
6+
key: "cincopa-asset-uploaded-instant",
7+
name: "New Asset Uploaded (Instant)",
8+
description: "Emit new event when a new asset is uploaded. [See the documentation](https://www.cincopa.com/media-platform/api-documentation-v2#webhook.set)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getEvents() {
15+
return events.ASSET_UPLOADED;
16+
},
17+
generateMeta(resource) {
18+
return {
19+
id: resource.id,
20+
summary: `New Asset: ${resource.filename}`,
21+
ts: Date.parse(resource.modified),
22+
};
23+
},
24+
},
25+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default {
2+
GALLERY_ALL: "gallery.*",
3+
GALLERY_CREATED: "gallery.created",
4+
GALLERY_UPDATED: "gallery.updated",
5+
GALLERY_DELETED: "gallery.deleted",
6+
GALLERY_CLAIM: "gallery.claim",
7+
GALLERY_SYNC: "gallery.sync",
8+
GALLERY_SYNCED: "gallery.synced",
9+
ASSET_ALL: "asset.*",
10+
ASSET_UPLOADED: "asset.uploaded",
11+
ASSET_SYNCED: "asset.synced",
12+
ACCOUNT_ALL: "account.*",
13+
ANALYTICS_ALL: "analytics.*",
14+
LEADS_ALL: "leads.*",
15+
};

0 commit comments

Comments
 (0)