Skip to content

Commit 6c920c7

Browse files
committed
tinyurl init
1 parent 666b7c4 commit 6c920c7

File tree

7 files changed

+673
-2
lines changed

7 files changed

+673
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import tinyurl from "../../tinyurl.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "tinyurl-create-shortened-link",
6+
name: "Create Shortened Link",
7+
description: "Creates a new shortened link. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
tinyurl,
12+
destinationUrl: {
13+
propDefinition: [
14+
tinyurl,
15+
"destinationUrl",
16+
],
17+
},
18+
customAlias: {
19+
propDefinition: [
20+
tinyurl,
21+
"customAlias",
22+
],
23+
optional: true,
24+
},
25+
expirationDate: {
26+
propDefinition: [
27+
tinyurl,
28+
"expirationDate",
29+
],
30+
optional: true,
31+
},
32+
tags: {
33+
propDefinition: [
34+
tinyurl,
35+
"tags",
36+
],
37+
optional: true,
38+
},
39+
},
40+
async run({ $ }) {
41+
const response = await this.tinyurl.createTinyURL();
42+
$.export("$summary", `Created TinyURL: ${response.url}`);
43+
return response;
44+
},
45+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import tinyurl from "../../tinyurl.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "tinyurl-retrieve-link-analytics",
6+
name: "Retrieve Link Analytics",
7+
description: "Retrieves analytics for a specific TinyURL link, including total clicks, geographic breakdowns, and device types. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
tinyurl,
12+
analyticsLinkIdOrAlias: {
13+
propDefinition: [
14+
tinyurl,
15+
"analyticsLinkIdOrAlias",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const analytics = await this.tinyurl.retrieveAnalytics();
21+
$.export("$summary", `Retrieved analytics for link ${this.analyticsLinkIdOrAlias}`);
22+
return analytics;
23+
},
24+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import tinyurl from "../../tinyurl.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "tinyurl-update-link-metadata",
6+
name: "Update Link Metadata",
7+
description: "Updates the metadata of an existing TinyURL. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
tinyurl,
12+
linkIdOrAlias: {
13+
propDefinition: [
14+
"tinyurl",
15+
"linkIdOrAlias",
16+
],
17+
},
18+
title: {
19+
propDefinition: [
20+
"tinyurl",
21+
"title",
22+
],
23+
optional: true,
24+
},
25+
updateTags: {
26+
propDefinition: [
27+
"tinyurl",
28+
"updateTags",
29+
],
30+
optional: true,
31+
},
32+
updateExpirationDate: {
33+
propDefinition: [
34+
"tinyurl",
35+
"updateExpirationDate",
36+
],
37+
optional: true,
38+
},
39+
},
40+
async run({ $ }) {
41+
const response = await this.tinyurl.updateTinyURLMetadata();
42+
$.export("$summary", `Updated TinyURL metadata for link: ${this.linkIdOrAlias}`);
43+
return response;
44+
},
45+
};
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { axios } from "@pipedream/platform";
2+
import tinyurl from "../../tinyurl.app.mjs";
3+
4+
export default {
5+
key: "tinyurl-new-link-click-instant",
6+
name: "New TinyURL Clicked",
7+
description: "Emit a new event whenever a monitored TinyURL is clicked. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
tinyurl: {
13+
type: "app",
14+
app: "tinyurl",
15+
},
16+
db: "$.service.db",
17+
timer: {
18+
type: "$.interface.timer",
19+
default: {
20+
intervalSeconds: 60,
21+
},
22+
},
23+
emitLinkClickMonitoredLinks: {
24+
propDefinition: [
25+
"tinyurl",
26+
"emitLinkClickMonitoredLinks",
27+
],
28+
},
29+
emitLinkClickFilterGeography: {
30+
propDefinition: [
31+
"tinyurl",
32+
"emitLinkClickFilterGeography",
33+
],
34+
optional: true,
35+
},
36+
emitLinkClickFilterDeviceType: {
37+
propDefinition: [
38+
"tinyurl",
39+
"emitLinkClickFilterDeviceType",
40+
],
41+
optional: true,
42+
},
43+
},
44+
hooks: {
45+
async deploy() {
46+
// No specific deployment actions required
47+
},
48+
async activate() {
49+
// No specific activation actions required
50+
},
51+
async deactivate() {
52+
// No specific deactivation actions required
53+
},
54+
},
55+
async run() {
56+
const emit = (data) => {
57+
const ts = data.timestamp
58+
? Date.parse(data.timestamp)
59+
: Date.now();
60+
this.$emit(data, {
61+
id: data.id || ts,
62+
summary: `Link clicked: ${data.linkId || "unknown"}`,
63+
ts,
64+
});
65+
};
66+
67+
await this.tinyurl.pollLinkClicks(
68+
{
69+
linksToMonitor: this.emitLinkClickMonitoredLinks,
70+
geographyFilter: this.emitLinkClickFilterGeography,
71+
deviceTypeFilter: this.emitLinkClickFilterDeviceType,
72+
},
73+
emit,
74+
);
75+
},
76+
};
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import {
2+
axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
3+
} from "@pipedream/platform";
4+
import tinyurl from "../../tinyurl.app.mjs";
5+
6+
export default {
7+
key: "tinyurl-new-link-created",
8+
name: "New Shortened URL Created",
9+
description: "Emits an event when a new shortened URL is created. [See the documentation]()",
10+
version: "0.0.{{ts}}",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
tinyurl,
15+
db: "$.service.db",
16+
timer: {
17+
type: "$.interface.timer",
18+
default: {
19+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
20+
},
21+
},
22+
emitNewLinkFilterDomain: {
23+
propDefinition: [
24+
tinyurl,
25+
"emitNewLinkFilterDomain",
26+
],
27+
},
28+
emitNewLinkFilterTag: {
29+
propDefinition: [
30+
tinyurl,
31+
"emitNewLinkFilterTag",
32+
],
33+
},
34+
},
35+
hooks: {
36+
async deploy() {
37+
const lastTs = (await this.db.get("lastTs")) || 0;
38+
const emittedLinks = [];
39+
40+
await this.tinyurl.pollNewLinks(
41+
{
42+
domainFilter: this.emitNewLinkFilterDomain,
43+
tagFilter: this.emitNewLinkFilterTag,
44+
},
45+
(link) => {
46+
const ts = link.created_at
47+
? Date.parse(link.created_at)
48+
: Date.now();
49+
if (ts > lastTs) {
50+
emittedLinks.unshift({
51+
...link,
52+
ts,
53+
});
54+
}
55+
},
56+
);
57+
58+
const recentLinks = emittedLinks.slice(0, 50);
59+
recentLinks.forEach((link) => {
60+
this.$emit(link, {
61+
id: link.id || link.created_at || link.ts,
62+
summary: `New TinyURL: ${link.destination_url}`,
63+
ts: link.ts,
64+
});
65+
});
66+
67+
if (recentLinks.length > 0) {
68+
const latestTs = recentLinks[0].ts;
69+
this.db.set("lastTs", latestTs);
70+
} else {
71+
this.db.set("lastTs", lastTs);
72+
}
73+
},
74+
async activate() {
75+
// No webhook subscription needed for polling source
76+
},
77+
async deactivate() {
78+
// No webhook subscription to remove for polling source
79+
},
80+
},
81+
async run() {
82+
const lastTs = (await this.db.get("lastTs")) || 0;
83+
const newLinks = [];
84+
85+
await this.tinyurl.pollNewLinks(
86+
{
87+
domainFilter: this.emitNewLinkFilterDomain,
88+
tagFilter: this.emitNewLinkFilterTag,
89+
},
90+
(link) => {
91+
const ts = link.created_at
92+
? Date.parse(link.created_at)
93+
: Date.now();
94+
if (ts > lastTs) {
95+
newLinks.push({
96+
...link,
97+
ts,
98+
});
99+
}
100+
},
101+
);
102+
103+
newLinks.sort((a, b) => b.ts - a.ts).slice(0, 50)
104+
.forEach((link) => {
105+
this.$emit(link, {
106+
id: link.id || link.created_at || link.ts,
107+
summary: `New TinyURL: ${link.destination_url}`,
108+
ts: link.ts,
109+
});
110+
});
111+
112+
if (newLinks.length > 0) {
113+
const latestTs = newLinks[0].ts;
114+
this.db.set("lastTs", latestTs);
115+
}
116+
},
117+
};

0 commit comments

Comments
 (0)