Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
75 changes: 71 additions & 4 deletions components/drimify/drimify.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,78 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "drimify",
propDefinitions: {},
propDefinitions: {
applicationId: {
type: "string[]",
label: "Application ID",
description: "A list of application's IDs",
async options() {
const data = await this.listApps();

return data.map(({
id: value, title: label,
}) => ({
label,
value,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://endpoint.drimify.com/api";
},
_headers() {
return {
"X-AUTH-TOKEN": `${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
listApps() {
return this._makeRequest({
path: "/apps",
});
},
listAppDataCollections(opts = {}) {
return this._makeRequest({
path: "/app_data_collections",
...opts,
});
},
async *paginate({
fn, params = {}, maxResults = null, ...opts
}) {
let hasMore = false;
let count = 0;
let page = 0;

do {
params.page = ++page;
const data = await fn({
params,
...opts,
});
for (const d of data) {
yield d;

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

hasMore = data.length;

} while (hasMore);
},
},
};
5 changes: 4 additions & 1 deletion components/drimify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/drimify",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Drimify Components",
"main": "drimify.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import drimify from "../../drimify.app.mjs";

export default {
key: "drimify-new-application-data",
name: "New Application Data Collected",
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)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
drimify,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
applicationId: {
propDefinition: [
drimify,
"applicationId",
],
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate") || "1970-01-01T00:00:00";
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
async emitEvent(maxResults = false) {
const lastDate = this._getLastDate();

const response = this.drimify.paginate({
fn: this.drimify.listAppDataCollections,
});

let responseArray = [];
for await (const item of response) {
if (Date.parse(item.date) <= Date.parse(lastDate)) break;
responseArray.push(item);
}

if (responseArray.length) {
if (maxResults && (responseArray.length > maxResults)) {
responseArray.length = maxResults;
}
this._setLastDate(responseArray[0].date);
}

for (const item of responseArray.reverse()) {
this.$emit(item, {
id: item.idunic || item.id,
summary: `New Data Collected with ID: ${item.id}`,
ts: Date.parse(item.date),
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
};
42 changes: 42 additions & 0 deletions components/drimify/sources/new-application-data/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export default {
"id": 0,
"idunic": "string",
"gender": "string",
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"dob": "2019-08-24T14:15:22Z",
"address": "string",
"cp": "string",
"town": "string",
"country": "string",
"phoneNumber": "string",
"companyName": "string",
"website": "http://example.com",
"optinNewsletter": "string",
"customText": "string",
"customFormat": "string",
"profil": "string",
"profilUid": "string",
"score": 0,
"prizeUid": "string",
"prizeTitle": "string",
"prizeRef": "string",
"code": "string",
"date": "2019-08-24T14:15:22Z",
"publisherid": "string",
"sessionId": "string",
"ip": "string",
"countryCode": "string",
"selectValue": "string",
"selectValue2": "string",
"customCheckbox": "string",
"timeTaken": 0,
"referral": "direct",
"dateWithTimezone": "2019-08-24T14:15:22Z",
"locale": "string",
"updatedAt": "2019-08-24T14:15:22Z",
"connectionCountry": "string",
"updatedAtTimestamp": 0
}
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading