Skip to content

Commit c73c341

Browse files
authored
New Components - adrapid (#13708)
* adrapid init * [Components] adrapid #13636 Sources - New Banner Ready Actions - Create Banner - Get Banner * pnpm update
1 parent f87cf9f commit c73c341

File tree

9 files changed

+479
-8
lines changed

9 files changed

+479
-8
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
import adrapid from "../../adrapid.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "adrapid-create-banner",
6+
name: "Create Banner",
7+
description: "Generates a new banner using provided data. This action can create different types of banners, such as animated HTML5, image, or video banners. [See the documentation](https://docs.adrapid.com/api/overview)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
adrapid,
12+
templateId: {
13+
propDefinition: [
14+
adrapid,
15+
"templateId",
16+
],
17+
reloadProps: true,
18+
},
19+
modes: {
20+
type: "string[]",
21+
label: "Modes",
22+
description: "Modes for the resulting banners, previously set on configuration block.",
23+
options: [
24+
"html5",
25+
"amp",
26+
"png",
27+
"jpeg",
28+
"pdf",
29+
"webp",
30+
"video",
31+
"gif",
32+
],
33+
reloadProps: true,
34+
optional: true,
35+
},
36+
overrides: {
37+
type: "object",
38+
label: "Overrides",
39+
description: "With this parameter we override the default template content. We use the name of the item we want to override, valid properties are text, url (for external images) and css. [See the documentation](https://docs.adrapid.com/api/overview).",
40+
optional: true,
41+
},
42+
sync: {
43+
type: "boolean",
44+
label: "Sync",
45+
description: "Get banner url in the same response. Delay the response until the banner is ready. Usually in a few seconds with a maxtime of two minutes.",
46+
optional: true,
47+
},
48+
editable: {
49+
type: "boolean",
50+
label: "Editable",
51+
description: "Make banner editable, creating a template that is a copy of the banner.",
52+
optional: true,
53+
},
54+
excludeBaseSize: {
55+
type: "boolean",
56+
label: "Exclude Base Size",
57+
description: "Exclude base size from the banner. Only applies to multisize banners.",
58+
optional: true,
59+
},
60+
},
61+
async additionalProps() {
62+
const props = {};
63+
if (this.templateId) {
64+
const { sizes } = await this.adrapid.getTemplate({
65+
templateId: this.templateId,
66+
});
67+
props.sizeIds = {
68+
type: "string[]",
69+
label: "Size Ids",
70+
description: "The template sizes. To use all of them you can set this parameter to 'all'. If you remove this parameter only the default size of the template will be used.",
71+
reloadProps: true,
72+
optional: true,
73+
options: sizes.map(({
74+
id: value, name: label,
75+
}) => ({
76+
value,
77+
label,
78+
})),
79+
};
80+
}
81+
82+
if (this.modes) {
83+
if (this.modes.includes("html5")) {
84+
props.html5Packed = {
85+
type: "boolean",
86+
label: "HTML5 Packed",
87+
description: "Set banner in a single file with embedded images.",
88+
};
89+
props.html5Flexible = {
90+
type: "boolean",
91+
label: "HTML5 Flexible",
92+
description: "Set a flexible banner that will adapt to his container.",
93+
};
94+
}
95+
if (this.modes.includes("video")) {
96+
props.videoFps = {
97+
type: "integer",
98+
label: "Video FPS",
99+
description: "Frame Per Second of resulting video.",
100+
default: 14,
101+
max: 60,
102+
};
103+
props.videoCrf = {
104+
type: "integer",
105+
label: "Video CRF",
106+
description: "Constant Rate Factor. Less is more quality.",
107+
default: 18,
108+
max: 60,
109+
};
110+
props.videoOffset = {
111+
type: "string",
112+
label: "Audio Offset",
113+
description: "Audio offset. Can be negative number.",
114+
};
115+
props.videoSrc = {
116+
type: "string",
117+
label: "Audio SRC",
118+
description: "URL of the audio file.",
119+
};
120+
}
121+
if (this.modes.includes("gif")) {
122+
props.gifFps = {
123+
type: "boolean",
124+
label: "GIF FPS",
125+
description: "Frame per second of resulting gif.",
126+
};
127+
props.gifFrames = {
128+
type: "integer[]",
129+
label: "GIF Frames",
130+
description: "Select specific seconds in the timeline to be used as frames.",
131+
};
132+
}
133+
}
134+
return props;
135+
},
136+
async run({ $ }) {
137+
138+
const modes = {};
139+
140+
if (this.modes) {
141+
this.modes.forEach((item) => {
142+
modes[item] = true;
143+
});
144+
145+
if (this.modes.includes("html5")) {
146+
modes.html5 = {
147+
packed: this.html5Packed,
148+
flexibe: this.html5Flexible,
149+
};
150+
}
151+
if (this.modes.includes("video")) {
152+
modes.video = {
153+
fps: this.videoFps,
154+
crf: this.videoCrf,
155+
audio: {
156+
offset: parseInt(this.videoOffset),
157+
src: this.videoSrc,
158+
},
159+
};
160+
}
161+
if (this.modes.includes("gif")) {
162+
modes.html5 = {
163+
fps: this.gifFps,
164+
frames: this.gifFrames,
165+
};
166+
}
167+
}
168+
169+
const response = await this.adrapid.createBanner({
170+
$,
171+
data: {
172+
sizeIds: this.sizeIds,
173+
templateId: this.templateId,
174+
modes,
175+
overrides: parseObject(this.overrides),
176+
sync: this.sync,
177+
editable: this.editable,
178+
excludeBaseSize: this.excludeBaseSize,
179+
},
180+
});
181+
182+
$.export("$summary", `Banner created successfully with ID: ${response.id}`);
183+
return response;
184+
},
185+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import adrapid from "../../adrapid.app.mjs";
2+
3+
export default {
4+
key: "adrapid-get-banner",
5+
name: "Get Banner",
6+
description: "Retrieves a specified banner. This action should be used after a 'create-banner' action to ensure that the banner is fully processed and ready for use. [See the documentation](https://docs.adrapid.com/api/overview)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
adrapid,
11+
bannerId: {
12+
propDefinition: [
13+
adrapid,
14+
"bannerId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.adrapid.getBanner({
20+
$,
21+
bannerId: this.bannerId,
22+
});
23+
24+
$.export("$summary", `Successfully retrieved banner: ${response.id}`);
25+
return response;
26+
},
27+
};

components/adrapid/adrapid.app.mjs

Lines changed: 120 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,126 @@
1+
import { axios } from "@pipedream/platform";
2+
import { LIMIT } from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "adrapid",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
bannerId: {
9+
type: "string",
10+
label: "Banner Id",
11+
description: "The id of the banner.",
12+
async options({ page }) {
13+
const { rows: data } = await this.listBanners({
14+
params: {
15+
limit: LIMIT,
16+
offset: LIMIT * page,
17+
},
18+
});
19+
20+
return data.map(({
21+
id: value, name: label,
22+
}) => ({
23+
label,
24+
value,
25+
}));
26+
},
27+
},
28+
templateId: {
29+
type: "string",
30+
label: "Template Id",
31+
description: "The id of the template to create the banner.",
32+
async options({ page }) {
33+
const { rows: data } = await this.listTemplates({
34+
params: {
35+
limit: LIMIT,
36+
offset: LIMIT * page,
37+
},
38+
});
39+
40+
return data.map(({
41+
id: value, name: label,
42+
}) => ({
43+
label,
44+
value,
45+
}));
46+
},
47+
},
48+
},
549
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
50+
_baseUrl() {
51+
return "https://api.adrapid.com";
52+
},
53+
_headers() {
54+
return {
55+
Authorization: `Bearer ${this.$auth.api_token}`,
56+
};
57+
},
58+
_makeRequest({
59+
$ = this, path, ...opts
60+
}) {
61+
return axios($, {
62+
url: this._baseUrl() + path,
63+
headers: this._headers(),
64+
...opts,
65+
});
66+
},
67+
listBanners(opts = {}) {
68+
return this._makeRequest({
69+
path: "/banners",
70+
...opts,
71+
});
72+
},
73+
listTemplates(opts = {}) {
74+
return this._makeRequest({
75+
path: "/templates",
76+
...opts,
77+
});
78+
},
79+
getTemplate({ templateId }) {
80+
return this._makeRequest({
81+
path: `/templates/${templateId}`,
82+
});
83+
},
84+
getBanner({
85+
bannerId, ...opts
86+
}) {
87+
return this._makeRequest({
88+
path: `/banners/${bannerId}`,
89+
...opts,
90+
});
91+
},
92+
createBanner(opts = {}) {
93+
return this._makeRequest({
94+
method: "POST",
95+
path: "/banners",
96+
...opts,
97+
});
98+
},
99+
async *paginate({
100+
fn, params = {}, maxResults = null, ...opts
101+
}) {
102+
let hasMore = false;
103+
let count = 0;
104+
let page = 0;
105+
106+
do {
107+
params.limit = LIMIT;
108+
params.offset = LIMIT * page++;
109+
const { rows } = await fn({
110+
params,
111+
...opts,
112+
});
113+
for (const d of rows) {
114+
yield d;
115+
116+
if (maxResults && ++count === maxResults) {
117+
return count;
118+
}
119+
}
120+
121+
hasMore = rows.length;
122+
123+
} while (hasMore);
9124
},
10125
},
11-
};
126+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const LIMIT = 100;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/adrapid/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/adrapid",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Adrapid Components",
55
"main": "adrapid.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)