Skip to content

Commit 961e5bb

Browse files
committed
Added actions
1 parent ce0224b commit 961e5bb

File tree

8 files changed

+230
-20
lines changed

8 files changed

+230
-20
lines changed

components/geckoboard/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import app from "../../geckoboard.app.mjs";
2+
3+
export default {
4+
key: "geckoboard-append-to-dataset",
5+
name: "Append to Dataset",
6+
description: "Append data to the specified dataset. [See the documentation](https://developer.geckoboard.com/?#append-data-to-a-dataset)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
datasetId: {
12+
propDefinition: [
13+
app,
14+
"datasetId",
15+
],
16+
reloadProps: true,
17+
},
18+
},
19+
20+
async additionalProps(existingProps) {
21+
const datasetId = this.datasetId?.value || this.datasetId;
22+
const datasets = await this.app.getDatasets();
23+
24+
const dataset = datasets.data.find((d) => d.id === datasetId);
25+
if (!dataset) return existingProps;
26+
27+
const props = {};
28+
for (const [
29+
key,
30+
field,
31+
] of Object.entries(dataset.fields)) {
32+
props[key] = {
33+
type: "string",
34+
label: field.name,
35+
optional: field.optional,
36+
};
37+
}
38+
39+
return props;
40+
},
41+
42+
async run({ $ }) {
43+
const data = {};
44+
45+
for (const key of Object.keys(this)) {
46+
if (![
47+
"app",
48+
"datasetId",
49+
].includes(key)) {
50+
let value = this[key];
51+
52+
if (!isNaN(value)) {
53+
value = parseFloat(value);
54+
}
55+
56+
data[key] = value;
57+
}
58+
}
59+
60+
const response = await this.app.appendToDataset({
61+
$,
62+
datasetId: this.datasetId,
63+
data: {
64+
data: [
65+
data,
66+
],
67+
},
68+
});
69+
70+
$.export("$summary", "Successfully appended data to dataset");
71+
return response;
72+
},
73+
74+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import app from "../../geckoboard.app.mjs";
2+
3+
export default {
4+
key: "geckoboard-create-dataset",
5+
name: "Create Dataset",
6+
description: "Create a new dataset. [See the documentation](https://developer.geckoboard.com/?#find-or-create-a-new-dataset)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
fields: {
12+
propDefinition: [
13+
app,
14+
"fields",
15+
],
16+
},
17+
id: {
18+
propDefinition: [
19+
app,
20+
"id",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.app.createDataset({
26+
$,
27+
id: this.id,
28+
data: {
29+
fields: JSON.parse(this.fields),
30+
},
31+
});
32+
$.export("$summary", "Successfully created dataset");
33+
return response;
34+
},
35+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import app from "../../geckoboard.app.mjs";
2+
3+
export default {
4+
key: "geckoboard-delete-dataset",
5+
name: "Delete Dataset",
6+
description: "Delete the specified dataset. [See the documentation](https://developer.geckoboard.com/?#delete-a-dataset)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
datasetId: {
12+
propDefinition: [
13+
app,
14+
"datasetId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.app.deleteDataset({
20+
$,
21+
datasetId: this.datasetId,
22+
});
23+
$.export("$summary", "Successfully deleted dataset");
24+
return response;
25+
},
26+
};

components/geckoboard/app/geckoboard.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "geckoboard",
6+
propDefinitions: {
7+
fields: {
8+
type: "string",
9+
label: "fields",
10+
description: "JSON containing the fields of the dataset, i.e.: `{ \"amount\": { \"type\": \"number\", \"name\": \"Amount\", \"optional\": false }, \"timestamp\": { \"type\": \"datetime\", \"name\": \"Date\" } }`",
11+
},
12+
id: {
13+
type: "string",
14+
label: "ID",
15+
description: "The ID of the dataset that will be created",
16+
},
17+
datasetId: {
18+
type: "string",
19+
label: "Dataset Id",
20+
description: "The ID of the dataset",
21+
async options() {
22+
const response = await this.getDatasets();
23+
const datasets = response.data;
24+
return datasets.map(({ id }) => ({
25+
value: id,
26+
}));
27+
},
28+
},
29+
},
30+
methods: {
31+
_baseUrl() {
32+
return "https://api.geckoboard.com";
33+
},
34+
async _makeRequest(opts = {}) {
35+
const {
36+
$ = this,
37+
path,
38+
auth,
39+
...otherOpts
40+
} = opts;
41+
return axios($, {
42+
...otherOpts,
43+
url: this._baseUrl() + path,
44+
auth: {
45+
username: `${this.$auth.api_key}`,
46+
password: "",
47+
...auth,
48+
},
49+
});
50+
},
51+
async appendToDataset({
52+
datasetId, ...args
53+
}) {
54+
return this._makeRequest({
55+
path: `/datasets/${datasetId}/data`,
56+
method: "post",
57+
...args,
58+
});
59+
},
60+
async createDataset({
61+
id, ...args
62+
}) {
63+
return this._makeRequest({
64+
path: `/datasets/${id}`,
65+
method: "put",
66+
...args,
67+
});
68+
},
69+
async deleteDataset({
70+
datasetId, ...args
71+
}) {
72+
return this._makeRequest({
73+
path: `/datasets/${datasetId}`,
74+
method: "delete",
75+
...args,
76+
});
77+
},
78+
async getDatasets(args = {}) {
79+
return this._makeRequest({
80+
path: "/datasets",
81+
...args,
82+
});
83+
},
84+
},
85+
};

components/geckoboard/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/geckoboard",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Geckoboard Components",
5-
"main": "dist/app/geckoboard.app.mjs",
5+
"main": "geckoboard.app.mjs",
66
"keywords": [
77
"pipedream",
88
"geckoboard"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/geckoboard",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1517
}
1618
}

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)