Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
27 changes: 27 additions & 0 deletions components/asters/actions/list-labels/list-labels.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import asters from "../../asters.app.mjs";

export default {
key: "asters-list-labels",
name: "List Labels",
description: "Retrieve the list of all labels of a specific workspace. [See the documentation](https://docs.asters.ai/api/endpoints/labels)",
type: "action",
version: "0.0.1",
props: {
asters,
workspaceId: {
propDefinition: [
asters,
"workspaceId",
],
},
},
async run({ $ }) {
const { data } = await this.asters.listLabels({
workspaceId: this.workspaceId,
});
$.export("$summary", `Successfully retrieved ${data.length} label${data.length === 1
? ""
: "s"}`);
return data;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import asters from "../../asters.app.mjs";

export default {
key: "asters-list-posts-analytics",
name: "List Posts Analytics",
description: "Retrieve the list of posts' analytics of a social account. [See the documentation](https://docs.asters.ai/api/endpoints/analytics)",
type: "action",
version: "0.0.1",
props: {
asters,
workspaceId: {
propDefinition: [
asters,
"workspaceId",
],
},
socialAccountId: {
propDefinition: [
asters,
"socialAccountId",
(c) => ({
workspaceId: c.workspaceId,
}),
],
},
fromDate: {
propDefinition: [
asters,
"fromDate",
],
},
toDate: {
propDefinition: [
asters,
"toDate",
],
},
},
async run({ $ }) {
const posts = await this.asters.getPaginatedResources({
fn: this.asters.listPostAnalytics,
args: {
data: {
socialAccountId: this.socialAccountId,
filters: {
date: {
from: this.fromDate,
to: this.toDate,
},
},
},
},
});
$.export("$summary", `Successfully retrieved ${posts.length} post${posts.length === 1
? ""
: "s"}`);
return posts;
},
};
59 changes: 59 additions & 0 deletions components/asters/actions/list-posts/list-posts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import asters from "../../asters.app.mjs";

export default {
key: "asters-list-posts",
name: "List Posts",
description: "Retrieve a list of posts of a social profile. [See the documentation](https://docs.asters.ai/api/endpoints/posts)",
type: "action",
version: "0.0.1",
props: {
asters,
workspaceId: {
propDefinition: [
asters,
"workspaceId",
],
},
socialAccountId: {
propDefinition: [
asters,
"socialAccountId",
(c) => ({
workspaceId: c.workspaceId,
}),
],
},
fromDate: {
propDefinition: [
asters,
"fromDate",
],
},
toDate: {
propDefinition: [
asters,
"toDate",
],
},
},
async run({ $ }) {
const posts = await this.asters.getPaginatedResources({
fn: this.asters.listPosts,
args: {
data: {
socialAccountId: this.socialAccountId,
filters: {
date: {
from: this.fromDate,
to: this.toDate,
},
},
},
},
});
$.export("$summary", `Successfully retrieved ${posts.length} post${posts.length === 1
? ""
: "s"}`);
return posts;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import asters from "../../asters.app.mjs";

export default {
key: "asters-list-social-accounts",
name: "List Social Accounts",
description: "Retrieve the list of all social accounts of a specific workspace. [See the documentation](https://docs.asters.ai/api/endpoints/social-accounts)",
type: "action",
version: "0.0.1",
props: {
asters,
workspaceId: {
propDefinition: [
asters,
"workspaceId",
],
},
},
async run({ $ }) {
const { data } = await this.asters.listSocialAccounts({
workspaceId: this.workspaceId,
});
$.export("$summary", `Successfully retrieved ${data.length} social account${data.length === 1
? ""
: "s"}`);
return data;
},
};
128 changes: 124 additions & 4 deletions components/asters/asters.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,131 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "asters",
propDefinitions: {},
propDefinitions: {
workspaceId: {
type: "string",
label: "Workspace ID",
description: "The ID of a workspace",
async options() {
const { data: { workspaces = [] } } = await this.listWorkspaces();
return workspaces.map((workspace) => ({
label: workspace.name,
value: workspace._id,
}));
},
},
socialAccountId: {
type: "string",
label: "Social Account ID",
description: "The ID of a social account",
async options({ workspaceId }) {
const { data = [] } = await this.listSocialAccounts({
workspaceId,
});
return data.map((account) => ({
label: account.name,
value: account.account_id,
}));
},
},
fromDate: {
type: "string",
label: "From Date",
description: "The date to start the search from (YYYY-MM-DD)",
},
toDate: {
type: "string",
label: "To Date",
description: "The date to end the search (YYYY-MM-DD)",
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.asters.ai/api/external/v1.0";
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
"x-api-key": `${this.$auth.api_key}`,
},
...opts,
});
},
listWorkspaces(opts = {}) {
return this._makeRequest({
path: "/workspaces",
...opts,
});
},
listSocialAccounts({
workspaceId, ...opts
}) {
return this._makeRequest({
path: `/workspaces/${workspaceId}/socialAccounts`,
...opts,
});
},
listLabels({
workspaceId, ...opts
}) {
return this._makeRequest({
path: `/workspaces/${workspaceId}/labels`,
...opts,
});
},
listPosts(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/data/posts",
...opts,
});
},
listPostAnalytics(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/analytics/posts",
...opts,
});
},
async *paginate({
fn, args, max,
}) {
args = {
...args,
data: {
...args?.data,
page: 1,
},
};
let hasMore, count = 0;
do {
const {
data, pagination,
} = await fn(args);
if (!data?.length) {
return;
}
for (const item of data) {
yield item;
if (max && ++count >= max) {
return;
}
}
hasMore = pagination?.totalPages > args.data.page;
args.data.page++;
} while (hasMore);
},
async getPaginatedResources(opts) {
const results = [];
for await (const item of this.paginate(opts)) {
results.push(item);
}
return results;
},
},
};
7 changes: 5 additions & 2 deletions components/asters/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/asters",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Asters Components",
"main": "asters.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
41 changes: 41 additions & 0 deletions components/asters/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import asters from "../../asters.app.mjs";
import {
DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError,
} from "@pipedream/platform";

export default {
props: {
asters,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
getResourceFn() {
throw new ConfigurationError("getResourceFn must be implemented");
},
getArgs() {
throw new ConfigurationError("getArgs must be implemented");
},
generateMeta() {
throw new ConfigurationError("generateMeta must be implemented");
},
processResource() {
throw new ConfigurationError("processResource must be implemented");
},
},
async run() {
const resources = await this.asters.getPaginatedResources({
fn: this.getResourceFn(),
args: this.getArgs(),
});

for (const resource of resources) {
await this.processResource(resource);
}
},
};
Loading
Loading