Skip to content

Commit 281b9df

Browse files
authored
New Components - drimify (#16885)
* drimify init * [Components] drimify #13257 Sources - New Application Data * pnpm update
1 parent a035f4d commit 281b9df

File tree

5 files changed

+193
-6
lines changed

5 files changed

+193
-6
lines changed

components/drimify/drimify.app.mjs

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,78 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "drimify",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
applicationId: {
8+
type: "string[]",
9+
label: "Application ID",
10+
description: "A list of application's IDs",
11+
async options() {
12+
const data = await this.listApps();
13+
14+
return data.map(({
15+
id: value, title: label,
16+
}) => ({
17+
label,
18+
value,
19+
}));
20+
},
21+
},
22+
},
523
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
24+
_baseUrl() {
25+
return "https://endpoint.drimify.com/api";
26+
},
27+
_headers() {
28+
return {
29+
"X-AUTH-TOKEN": `${this.$auth.api_key}`,
30+
};
31+
},
32+
_makeRequest({
33+
$ = this, path, ...opts
34+
}) {
35+
return axios($, {
36+
url: this._baseUrl() + path,
37+
headers: this._headers(),
38+
...opts,
39+
});
40+
},
41+
listApps() {
42+
return this._makeRequest({
43+
path: "/apps",
44+
});
45+
},
46+
listAppDataCollections(opts = {}) {
47+
return this._makeRequest({
48+
path: "/app_data_collections",
49+
...opts,
50+
});
51+
},
52+
async *paginate({
53+
fn, params = {}, maxResults = null, ...opts
54+
}) {
55+
let hasMore = false;
56+
let count = 0;
57+
let page = 0;
58+
59+
do {
60+
params.page = ++page;
61+
const data = await fn({
62+
params,
63+
...opts,
64+
});
65+
for (const d of data) {
66+
yield d;
67+
68+
if (maxResults && ++count === maxResults) {
69+
return count;
70+
}
71+
}
72+
73+
hasMore = data.length;
74+
75+
} while (hasMore);
976
},
1077
},
1178
};

components/drimify/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/drimify",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Drimify Components",
55
"main": "drimify.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
1518
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import drimify from "../../drimify.app.mjs";
3+
4+
export default {
5+
key: "drimify-new-application-data",
6+
name: "New Application Data Collected",
7+
description: "Emit new event when application data has been collected. [See the documentation](https://endpoint.drimify.com/api/docs?ui=re_doc#tag/AppDataCollection/operation/api_app_data_collections_get_collection)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
drimify,
13+
db: "$.service.db",
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
18+
},
19+
},
20+
applicationId: {
21+
propDefinition: [
22+
drimify,
23+
"applicationId",
24+
],
25+
},
26+
},
27+
methods: {
28+
_getLastDate() {
29+
return this.db.get("lastDate") || "1970-01-01T00:00:00";
30+
},
31+
_setLastDate(lastDate) {
32+
this.db.set("lastDate", lastDate);
33+
},
34+
async emitEvent(maxResults = false) {
35+
const lastDate = this._getLastDate();
36+
37+
const response = this.drimify.paginate({
38+
fn: this.drimify.listAppDataCollections,
39+
});
40+
41+
let responseArray = [];
42+
for await (const item of response) {
43+
if (Date.parse(item.date) <= Date.parse(lastDate)) break;
44+
responseArray.push(item);
45+
}
46+
47+
if (responseArray.length) {
48+
if (maxResults && (responseArray.length > maxResults)) {
49+
responseArray.length = maxResults;
50+
}
51+
this._setLastDate(responseArray[0].date);
52+
}
53+
54+
for (const item of responseArray.reverse()) {
55+
this.$emit(item, {
56+
id: item.idunic || item.id,
57+
summary: `New Data Collected with ID: ${item.id}`,
58+
ts: Date.parse(item.date),
59+
});
60+
}
61+
},
62+
},
63+
hooks: {
64+
async deploy() {
65+
await this.emitEvent(25);
66+
},
67+
},
68+
async run() {
69+
await this.emitEvent();
70+
},
71+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
export default {
2+
"id": 0,
3+
"idunic": "string",
4+
"gender": "string",
5+
"username": "string",
6+
"firstName": "string",
7+
"lastName": "string",
8+
"email": "string",
9+
"dob": "2019-08-24T14:15:22Z",
10+
"address": "string",
11+
"cp": "string",
12+
"town": "string",
13+
"country": "string",
14+
"phoneNumber": "string",
15+
"companyName": "string",
16+
"website": "http://example.com",
17+
"optinNewsletter": "string",
18+
"customText": "string",
19+
"customFormat": "string",
20+
"profil": "string",
21+
"profilUid": "string",
22+
"score": 0,
23+
"prizeUid": "string",
24+
"prizeTitle": "string",
25+
"prizeRef": "string",
26+
"code": "string",
27+
"date": "2019-08-24T14:15:22Z",
28+
"publisherid": "string",
29+
"sessionId": "string",
30+
"ip": "string",
31+
"countryCode": "string",
32+
"selectValue": "string",
33+
"selectValue2": "string",
34+
"customCheckbox": "string",
35+
"timeTaken": 0,
36+
"referral": "direct",
37+
"dateWithTimezone": "2019-08-24T14:15:22Z",
38+
"locale": "string",
39+
"updatedAt": "2019-08-24T14:15:22Z",
40+
"connectionCountry": "string",
41+
"updatedAtTimestamp": 0
42+
}

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)