-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - tinyurl #15456
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
Merged
Merged
New Components - tinyurl #15456
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
components/tinyurl/actions/create-shortened-link/create-shortened-link.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import { parseObject } from "../../common/utils.mjs"; | ||
import tinyurl from "../../tinyurl.app.mjs"; | ||
|
||
export default { | ||
key: "tinyurl-create-shortened-link", | ||
name: "Create Shortened Link", | ||
description: "Creates a new shortened link. [See the documentation]()", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
tinyurl, | ||
url: { | ||
propDefinition: [ | ||
tinyurl, | ||
"url", | ||
], | ||
}, | ||
domain: { | ||
propDefinition: [ | ||
tinyurl, | ||
"domain", | ||
], | ||
optional: true, | ||
}, | ||
alias: { | ||
propDefinition: [ | ||
tinyurl, | ||
"alias", | ||
], | ||
optional: true, | ||
}, | ||
tags: { | ||
propDefinition: [ | ||
tinyurl, | ||
"tags", | ||
], | ||
optional: true, | ||
}, | ||
expiresAt: { | ||
propDefinition: [ | ||
tinyurl, | ||
"expiresAt", | ||
], | ||
optional: true, | ||
}, | ||
description: { | ||
type: "string", | ||
label: "Description", | ||
description: "The alias description", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
try { | ||
const response = await this.tinyurl.createTinyURL({ | ||
$, | ||
data: { | ||
url: this.url, | ||
domain: this.domain, | ||
alias: this.alias, | ||
tags: parseObject(this.tags)?.join(","), | ||
expires_at: this.expiresAt, | ||
description: this.description, | ||
}, | ||
}); | ||
$.export("$summary", `Created TinyURL: ${response.data.tiny_url}`); | ||
return response; | ||
} catch ({ response }) { | ||
throw new ConfigurationError(response?.data?.errors[0]); | ||
} | ||
}, | ||
}; | ||
|
67 changes: 67 additions & 0 deletions
67
components/tinyurl/actions/retrieve-link-analytics/retrieve-link-analytics.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import tinyurl from "../../tinyurl.app.mjs"; | ||
|
||
export default { | ||
key: "tinyurl-retrieve-link-analytics", | ||
name: "Retrieve Link Analytics", | ||
description: "Retrieves analytics for a specific TinyURL link, including total clicks, geographic breakdowns, and device types. [See the documentation]()", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
tinyurl, | ||
alert: { | ||
Check warning on line 12 in components/tinyurl/actions/retrieve-link-analytics/retrieve-link-analytics.mjs
|
||
type: "alert", | ||
alertType: "info", | ||
content: "This action is only allowed for paid accounts.", | ||
}, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
domain: { | ||
propDefinition: [ | ||
tinyurl, | ||
"domain", | ||
], | ||
}, | ||
urls: { | ||
propDefinition: [ | ||
tinyurl, | ||
"urls", | ||
({ domain }) => ({ | ||
domain, | ||
}), | ||
], | ||
}, | ||
from: { | ||
type: "string", | ||
label: "From", | ||
description: "The start datetime of analitics report", | ||
}, | ||
to: { | ||
type: "string", | ||
label: "To", | ||
description: "The end datetime of analitics report. Default is now", | ||
optional: true, | ||
}, | ||
tag: { | ||
type: "string", | ||
label: "Tag", | ||
description: "Tag to get analytics for", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
try { | ||
const analytics = await this.tinyurl.retrieveAnalytics({ | ||
$, | ||
params: { | ||
from: this.from, | ||
to: this.to, | ||
alias: this.urls, | ||
tag: this.tag, | ||
}, | ||
}); | ||
$.export("$summary", `Retrieved analytics for link ${this.urls}`); | ||
return analytics; | ||
} catch ({ response }) { | ||
throw new ConfigurationError(response?.data?.errors[0]); | ||
} | ||
}, | ||
}; |
86 changes: 86 additions & 0 deletions
86
components/tinyurl/actions/update-link-metadata/update-link-metadata.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import { parseObject } from "../../common/utils.mjs"; | ||
import tinyurl from "../../tinyurl.app.mjs"; | ||
|
||
export default { | ||
key: "tinyurl-update-link-metadata", | ||
name: "Update Link Metadata", | ||
description: "Updates the metadata of an existing TinyURL. [See the documentation]()", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
tinyurl, | ||
domain: { | ||
propDefinition: [ | ||
tinyurl, | ||
"domain", | ||
], | ||
}, | ||
urls: { | ||
propDefinition: [ | ||
tinyurl, | ||
"urls", | ||
({ domain }) => ({ | ||
domain, | ||
}), | ||
], | ||
}, | ||
newDomain: { | ||
type: "string", | ||
label: "New Domain", | ||
description: "The new domain you would like to switch to", | ||
optional: true, | ||
}, | ||
newAlias: { | ||
type: "string", | ||
label: "New Alias", | ||
description: "The new alias you would like to switch to", | ||
optional: true, | ||
}, | ||
newStats: { | ||
type: "boolean", | ||
label: "New Stats", | ||
description: "Turns on/off the collection of click analytics", | ||
optional: true, | ||
}, | ||
newTags: { | ||
type: "string[]", | ||
label: "New Tags", | ||
description: "Tags you would like this TinyURL to have. Overwrites the existing tags. **Paid accounts only**", | ||
optional: true, | ||
}, | ||
newExpiresAt: { | ||
type: "string", | ||
label: "New Expires At", | ||
description: "TinyURL expiration in ISO8601 format. If not set so TinyURL never expires, **Paid accounts only**", | ||
optional: true, | ||
}, | ||
newDescription: { | ||
type: "string", | ||
label: "New Description", | ||
description: "The new description", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
try { | ||
const response = await this.tinyurl.updateTinyURLMetadata({ | ||
$, | ||
data: { | ||
domain: this.domain, | ||
alias: this.urls, | ||
new_domain: this.newDomain, | ||
new_alias: this.newAlias, | ||
new_stats: this.newStats, | ||
new_tags: parseObject(this.newTags), | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new_expires_at: this.newExpiresAt, | ||
new_description: this.newDescription, | ||
}, | ||
}); | ||
$.export("$summary", `Updated TinyURL metadata for link: ${response.data.tiny_url}`); | ||
return response; | ||
} catch ({ response }) { | ||
throw new ConfigurationError(response?.data?.errors[0]); | ||
} | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@pipedream/tinyurl", | ||
"version": "0.1.0", | ||
"description": "Pipedream TinyURL Components", | ||
"main": "tinyurl.app.mjs", | ||
"keywords": [ | ||
"pipedream", | ||
"tinyurl" | ||
], | ||
"homepage": "https://pipedream.com/apps/tinyurl", | ||
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
components/tinyurl/sources/new-link-created/new-link-created.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
import tinyurl from "../../tinyurl.app.mjs"; | ||
|
||
export default { | ||
key: "tinyurl-new-link-created", | ||
name: "New Shortened URL Created", | ||
description: "Emit new event when a new shortened URL is created.", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
tinyurl, | ||
db: "$.service.db", | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
_getLastDate() { | ||
return this.db.get("lastDate") || 0; | ||
}, | ||
_setLastDate(lastDate) { | ||
this.db.set("lastDate", lastDate); | ||
}, | ||
async emitEvent(maxResults = false) { | ||
const lastDate = this._getLastDate(); | ||
|
||
const { data } = await this.tinyurl.listURLs({ | ||
type: "available", | ||
params: { | ||
from: lastDate, | ||
}, | ||
}); | ||
|
||
if (data.length) { | ||
if (maxResults && (data.length > maxResults)) { | ||
data.length = maxResults; | ||
} | ||
this._setLastDate(data[0].created_at); | ||
} | ||
|
||
for (const item of data.reverse()) { | ||
this.$emit(item, { | ||
id: item.alias, | ||
summary: `New TinyURL: ${item.tiny_url}`, | ||
ts: Date.parse(item.created_at), | ||
}); | ||
} | ||
}, | ||
}, | ||
hooks: { | ||
async deploy() { | ||
await this.emitEvent(25); | ||
}, | ||
}, | ||
async run() { | ||
await this.emitEvent(); | ||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.