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

New Components - l2s #14115

Merged
merged 3 commits into from
Oct 1, 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,89 @@
import { parseObject } from "../../common/utils.mjs";
import l2s from "../../l2s.app.mjs";

export default {
key: "l2s-create-shortened-url",
name: "Create Shortened URL",
description: "Generates a shortened URL utilizing L2S capabilities. [See the documentation](https://docs.l2s.is/)",
version: "0.0.1",
type: "action",
props: {
l2s,
url: {
type: "string",
label: "URL",
description: "The URL to be shortened",
},
customKey: {
type: "string",
label: "Custom Key",
description: "Custom key for the shortened URL",
optional: true,
},
utmSource: {
type: "string",
label: "UTM Source",
description: "UTM source parameter",
optional: true,
},
utmMedium: {
type: "string",
label: "UTM Medium",
description: "UTM medium parameter",
optional: true,
},
utmCampaign: {
type: "string",
label: "UTM Campaign",
description: "UTM campaign parameter",
optional: true,
},
utmTerm: {
type: "string",
label: "UTM Term",
description: "UTM term parameter",
optional: true,
},
utmContent: {
type: "string",
label: "UTM Content",
description: "UTM content parameter",
optional: true,
},
title: {
type: "string",
label: "Title",
description: "Title for the shortened URL",
optional: true,
},
tags: {
type: "string[]",
label: "Tags",
description: "Tags associated with the URL",
optional: true,
},
},
async run({ $ }) {
const {
l2s,
tags,
...data
} = this;

if (tags) {
data.tags = parseObject(tags);
}

const { response: { data: response } } = await l2s.shortenUrl({
$,
data,
});

const shortUrl = `https://l2s.is/${response.key}`;
$.export("$summary", "URL shortened successfully");
return {
short_url: shortUrl,
...response,
};
},
};
24 changes: 24 additions & 0 deletions components/l2s/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;
};
31 changes: 26 additions & 5 deletions components/l2s/l2s.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "l2s",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.l2s.is";
},
_headers() {
return {
Authorization: `Bearer ${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
shortenUrl(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/url",
...opts,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/l2s/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/l2s",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream L2S Components",
"main": "l2s.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"
}
}
}
107 changes: 55 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading