Skip to content

Commit

Permalink
New Components - l2s (#14115)
Browse files Browse the repository at this point in the history
* l2s init

* [Components] l2s #14107
Actions
 - Create Shortened URL

* pnpm update
  • Loading branch information
luancazarine authored Oct 1, 2024
1 parent c6bcdf0 commit bfbec2e
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 7 deletions.
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;
};
29 changes: 25 additions & 4 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"
}
}
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

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

0 comments on commit bfbec2e

Please sign in to comment.