Skip to content
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
185 changes: 185 additions & 0 deletions components/adrapid/actions/create-banner/create-banner.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import adrapid from "../../adrapid.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "adrapid-create-banner",
name: "Create Banner",
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)",
version: "0.0.1",
type: "action",
props: {
adrapid,
templateId: {
propDefinition: [
adrapid,
"templateId",
],
reloadProps: true,
},
modes: {
type: "string[]",
label: "Modes",
description: "Modes for the resulting banners, previously set on configuration block.",
options: [
"html5",
"amp",
"png",
"jpeg",
"pdf",
"webp",
"video",
"gif",
],
reloadProps: true,
optional: true,
},
overrides: {
type: "object",
label: "Overrides",
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).",
optional: true,
},
sync: {
type: "boolean",
label: "Sync",
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.",
optional: true,
},
editable: {
type: "boolean",
label: "Editable",
description: "Make banner editable, creating a template that is a copy of the banner.",
optional: true,
},
excludeBaseSize: {
type: "boolean",
label: "Exclude Base Size",
description: "Exclude base size from the banner. Only applies to multisize banners.",
optional: true,
},
},
async additionalProps() {
const props = {};
if (this.templateId) {
const { sizes } = await this.adrapid.getTemplate({
templateId: this.templateId,
});
props.sizeIds = {
type: "string[]",
label: "Size Ids",
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.",
reloadProps: true,
optional: true,
options: sizes.map(({
id: value, name: label,
}) => ({
value,
label,
})),
};
}

if (this.modes) {
if (this.modes.includes("html5")) {
props.html5Packed = {
type: "boolean",
label: "HTML5 Packed",
description: "Set banner in a single file with embedded images.",
};
props.html5Flexible = {
type: "boolean",
label: "HTML5 Flexible",
description: "Set a flexible banner that will adapt to his container.",
};
}
if (this.modes.includes("video")) {
props.videoFps = {
type: "integer",
label: "Video FPS",
description: "Frame Per Second of resulting video.",
default: 14,
max: 60,
};
props.videoCrf = {
type: "integer",
label: "Video CRF",
description: "Constant Rate Factor. Less is more quality.",
default: 18,
max: 60,
};
props.videoOffset = {
type: "string",
label: "Audio Offset",
description: "Audio offset. Can be negative number.",
};
props.videoSrc = {
type: "string",
label: "Audio SRC",
description: "URL of the audio file.",
};
}
if (this.modes.includes("gif")) {
props.gifFps = {
type: "boolean",
label: "GIF FPS",
description: "Frame per second of resulting gif.",
};
props.gifFrames = {
type: "integer[]",
label: "GIF Frames",
description: "Select specific seconds in the timeline to be used as frames.",
};
}
}
return props;
},
async run({ $ }) {

const modes = {};

if (this.modes) {
this.modes.forEach((item) => {
modes[item] = true;
});

if (this.modes.includes("html5")) {
modes.html5 = {
packed: this.html5Packed,
flexibe: this.html5Flexible,
};
}
if (this.modes.includes("video")) {
modes.video = {
fps: this.videoFps,
crf: this.videoCrf,
audio: {
offset: parseInt(this.videoOffset),
src: this.videoSrc,
},
};
}
if (this.modes.includes("gif")) {
modes.html5 = {
fps: this.gifFps,
frames: this.gifFrames,
};
}
}

const response = await this.adrapid.createBanner({
$,
data: {
sizeIds: this.sizeIds,
templateId: this.templateId,
modes,
overrides: parseObject(this.overrides),
sync: this.sync,
editable: this.editable,
excludeBaseSize: this.excludeBaseSize,
},
});

$.export("$summary", `Banner created successfully with ID: ${response.id}`);
return response;
},
};
27 changes: 27 additions & 0 deletions components/adrapid/actions/get-banner/get-banner.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import adrapid from "../../adrapid.app.mjs";

export default {
key: "adrapid-get-banner",
name: "Get Banner",
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)",
version: "0.0.1",
type: "action",
props: {
adrapid,
bannerId: {
propDefinition: [
adrapid,
"bannerId",
],
},
},
async run({ $ }) {
const response = await this.adrapid.getBanner({
$,
bannerId: this.bannerId,
});

$.export("$summary", `Successfully retrieved banner: ${response.id}`);
return response;
},
};
125 changes: 120 additions & 5 deletions components/adrapid/adrapid.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,126 @@
import { axios } from "@pipedream/platform";
import { LIMIT } from "./common/constants.mjs";

export default {
type: "app",
app: "adrapid",
propDefinitions: {},
propDefinitions: {
bannerId: {
type: "string",
label: "Banner Id",
description: "The id of the banner.",
async options({ page }) {
const { rows: data } = await this.listBanners({
params: {
limit: LIMIT,
offset: LIMIT * page,
},
});

return data.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
templateId: {
type: "string",
label: "Template Id",
description: "The id of the template to create the banner.",
async options({ page }) {
const { rows: data } = await this.listTemplates({
params: {
limit: LIMIT,
offset: LIMIT * page,
},
});

return data.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.adrapid.com";
},
_headers() {
return {
Authorization: `Bearer ${this.$auth.api_token}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
listBanners(opts = {}) {
return this._makeRequest({
path: "/banners",
...opts,
});
},
listTemplates(opts = {}) {
return this._makeRequest({
path: "/templates",
...opts,
});
},
getTemplate({ templateId }) {
return this._makeRequest({
path: `/templates/${templateId}`,
});
},
getBanner({
bannerId, ...opts
}) {
return this._makeRequest({
path: `/banners/${bannerId}`,
...opts,
});
},
createBanner(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/banners",
...opts,
});
},
async *paginate({
fn, params = {}, maxResults = null, ...opts
}) {
let hasMore = false;
let count = 0;
let page = 0;

do {
params.limit = LIMIT;
params.offset = LIMIT * page++;
const { rows } = await fn({
params,
...opts,
});
for (const d of rows) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = rows.length;

} while (hasMore);
},
},
};
};
1 change: 1 addition & 0 deletions components/adrapid/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LIMIT = 100;
24 changes: 24 additions & 0 deletions components/adrapid/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
7 changes: 5 additions & 2 deletions components/adrapid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/adrapid",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Adrapid Components",
"main": "adrapid.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.1"
}
}
}
Loading
Loading