Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions components/neetokb/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LIMIT = 100;
60 changes: 57 additions & 3 deletions components/neetokb/neetokb.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,65 @@
import { axios } from "@pipedream/platform";
import { LIMIT } from "./common/constants.mjs";

export default {
type: "app",
app: "neetokb",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_apiUrl() {
return `https://${this.$auth.organization_name}.neetokb.com/api/v1`;
},
_getHeaders() {
return {
"Content-Type": "application/json",
"X-Api-Key": `${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: `${this._apiUrl()}/${path}`,
headers: this._getHeaders(),
...opts,
});
},
listArticles(args = {}) {
return this._makeRequest({
path: "articles",
...args,
});
},
async *paginate({
fn, params = {}, maxResults = null, ...opts
}) {
let hasMore = false;
let count = 0;
let page = 0;

do {
params.page_number = ++page;
params.page_size = LIMIT;
const {
articles,
pagination: {
total_pages: tPages, current_page_number: cPage,
},
} = await fn({
params,
...opts,
});
for (const d of articles) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = cPage < tPages;

} while (hasMore);
},
},
};
5 changes: 4 additions & 1 deletion components/neetokb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/neetokb",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream neetoKB Components",
"main": "neetokb.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import neetokb from "../../neetokb.app.mjs";
import sampleEmit from "./test-event.mjs";

export default {
key: "neetokb-new-action",
name: "New Published Article",
description: "Emit new event when a new article is published. [See the documentation](https://neetokb-apis.mintlify.app/api-reference/articles/list-articles).",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
neetokb,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getPublishedIds() {
return this.db.get("publishedIds") || [];
},
_setPublishedIds(publishedIds) {
this.db.set("publishedIds", publishedIds);
},
async emitEvent(maxResults = false) {
const publishedIds = this._getPublishedIds();
const response = this.neetokb.paginate({
fn: this.neetokb.listArticles,
params: {
status: "published",
},
});

const responseArray = [];
for await (const item of response) {
responseArray.push(item);
}

let newArticles = responseArray.filter((article) => !publishedIds.includes(article.id));

if (maxResults && newArticles.length > maxResults) {
newArticles = newArticles.slice(0, maxResults);
}

for (const article of newArticles.reverse()) {
const ts = new Date();
this.$emit(article, {
id: `${article.id}-${ts}`,
summary: `New Published Article: ${article.title}`,
ts,
});
}
this._setPublishedIds(responseArray.map((article) => article.id));
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
sampleEmit,
};
12 changes: 12 additions & 0 deletions components/neetokb/sources/new-published-article/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
"id": "0c8d8101-62cb-4227-9dd0-953fbf88e74d",
"slug": "article-title",
"title": "Article Title",
"state": "published",
"unique_views_count": 0,
"is_archived": false,
"category": {
"id": "ea665eb3-23a1-4cbd-9dff-0a585d6c8c53",
"name": "Getting Started"
}
}
Loading