Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 0 additions & 3 deletions components/geckoboard/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import app from "../../geckoboard.app.mjs";

export default {
key: "geckoboard-append-to-dataset",
name: "Append to Dataset",
description: "Append data to the specified dataset. [See the documentation](https://developer.geckoboard.com/?#append-data-to-a-dataset)",
version: "0.0.1",
type: "action",
props: {
app,
datasetId: {
propDefinition: [
app,
"datasetId",
],
reloadProps: true,
},
},

async additionalProps(existingProps) {
const datasetId = this.datasetId?.value || this.datasetId;
const datasets = await this.app.getDatasets();

const dataset = datasets.data.find((d) => d.id === datasetId);
if (!dataset) return existingProps;

const props = {};
for (const [
key,
field,
] of Object.entries(dataset.fields)) {
props[key] = {
type: "string",
label: field.name,
optional: field.optional,
};
}

return props;
},

async run({ $ }) {
const data = {};

for (const key of Object.keys(this)) {
if (![
"app",
"datasetId",
].includes(key)) {
let value = this[key];

if (!isNaN(value)) {
value = parseFloat(value);
}

data[key] = value;
}
}
Comment on lines +45 to +58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve property iteration and value conversion

The current approach of iterating over all properties of this could include methods or internal properties that shouldn't be part of the data payload. Additionally, the automatic conversion of any numeric string to float might not be appropriate for all cases.

Consider a more targeted approach:

  async run({ $ }) {
    const data = {};
+   
+   // Get dynamic field definitions
+   const props = await this.additionalProps({});
+   const fieldKeys = Object.keys(props);

-   for (const key of Object.keys(this)) {
-     if (!["app", "datasetId"].includes(key)) {
-       let value = this[key];
-
-       if (!isNaN(value)) {
-         value = parseFloat(value);
-       }
-
-       data[key] = value;
-     }
-   }
+   // Only process fields from the dataset schema
+   for (const key of fieldKeys) {
+     if (this[key] === undefined) continue;
+     
+     let value = this[key];
+     
+     // Convert numeric strings to numbers when appropriate
+     if (typeof value === 'string' && !isNaN(value) && value.trim() !== '') {
+       value = parseFloat(value);
+     }
+     
+     data[key] = value;
+   }

This approach only processes fields that were explicitly defined by the dataset schema and provides more robust number conversion.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for (const key of Object.keys(this)) {
if (![
"app",
"datasetId",
].includes(key)) {
let value = this[key];
if (!isNaN(value)) {
value = parseFloat(value);
}
data[key] = value;
}
}
async run({ $ }) {
const data = {};
// Get dynamic field definitions
const props = await this.additionalProps({});
const fieldKeys = Object.keys(props);
// Only process fields from the dataset schema
for (const key of fieldKeys) {
if (this[key] === undefined) continue;
let value = this[key];
// Convert numeric strings to numbers when appropriate
if (typeof value === 'string' && !isNaN(value) && value.trim() !== '') {
value = parseFloat(value);
}
data[key] = value;
}
// ...rest of the function
}


const response = await this.app.appendToDataset({
$,
datasetId: this.datasetId,
data: {
data: [
data,
],
},
});

$.export("$summary", "Successfully appended data to dataset");
return response;
},

};
35 changes: 35 additions & 0 deletions components/geckoboard/actions/create-dataset/create-dataset.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import app from "../../geckoboard.app.mjs";

export default {
key: "geckoboard-create-dataset",
name: "Create Dataset",
description: "Create a new dataset. [See the documentation](https://developer.geckoboard.com/?#find-or-create-a-new-dataset)",
version: "0.0.1",
type: "action",
props: {
app,
fields: {
propDefinition: [
app,
"fields",
],
},
id: {
propDefinition: [
app,
"id",
],
},
},
async run({ $ }) {
const response = await this.app.createDataset({
$,
id: this.id,
data: {
fields: JSON.parse(this.fields),
},
});
$.export("$summary", "Successfully created dataset");
return response;
},
Comment on lines +24 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for JSON parsing

The current implementation uses JSON.parse(this.fields) without any error handling. If the user provides invalid JSON, this will throw an uncaught exception.

Consider adding a try/catch block to handle potential JSON parsing errors:

  async run({ $ }) {
+   let parsedFields;
+   try {
+     parsedFields = JSON.parse(this.fields);
+   } catch (error) {
+     throw new Error(`Invalid JSON format for fields: ${error.message}`);
+   }
+   
    const response = await this.app.createDataset({
      $,
      id: this.id,
      data: {
-       fields: JSON.parse(this.fields),
+       fields: parsedFields,
      },
    });
    $.export("$summary", "Successfully created dataset");
    return response;
  },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async run({ $ }) {
const response = await this.app.createDataset({
$,
id: this.id,
data: {
fields: JSON.parse(this.fields),
},
});
$.export("$summary", "Successfully created dataset");
return response;
},
async run({ $ }) {
let parsedFields;
try {
parsedFields = JSON.parse(this.fields);
} catch (error) {
throw new Error(`Invalid JSON format for fields: ${error.message}`);
}
const response = await this.app.createDataset({
$,
id: this.id,
data: {
fields: parsedFields,
},
});
$.export("$summary", "Successfully created dataset");
return response;
},

};
26 changes: 26 additions & 0 deletions components/geckoboard/actions/delete-dataset/delete-dataset.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import app from "../../geckoboard.app.mjs";

export default {
key: "geckoboard-delete-dataset",
name: "Delete Dataset",
description: "Delete the specified dataset. [See the documentation](https://developer.geckoboard.com/?#delete-a-dataset)",
version: "0.0.1",
type: "action",
props: {
app,
datasetId: {
propDefinition: [
app,
"datasetId",
],
},
},
async run({ $ }) {
const response = await this.app.deleteDataset({
$,
datasetId: this.datasetId,
});
$.export("$summary", "Successfully deleted dataset");
return response;
},
};
13 changes: 0 additions & 13 deletions components/geckoboard/app/geckoboard.app.ts

This file was deleted.

85 changes: 85 additions & 0 deletions components/geckoboard/geckoboard.app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "geckoboard",
propDefinitions: {
fields: {
type: "string",
label: "Fields",
description: "JSON containing the fields of the dataset, i.e.: `{ \"amount\": { \"type\": \"number\", \"name\": \"Amount\", \"optional\": false }, \"timestamp\": { \"type\": \"datetime\", \"name\": \"Date\" } }. See [documentation](https://developer.geckoboard.com/#plan-your-schema)`",
},
id: {
type: "string",
label: "ID",
description: "The ID of the dataset that will be created",
},
datasetId: {
type: "string",
label: "Dataset Id",
description: "The ID of the dataset",
async options() {
const response = await this.getDatasets();
const datasets = response.data;
return datasets.map(({ id }) => ({
value: id,
}));
},
Comment on lines +21 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling to the datasetId options function.

The async options() function for datasetId does not include error handling. If the API call fails, it could lead to an uncaught exception.

 async options() {
-  const response = await this.getDatasets();
-  const datasets = response.data;
-  return datasets.map(({ id }) => ({
-    value: id,
-  }));
+  try {
+    const response = await this.getDatasets();
+    const datasets = response.data;
+    return datasets.map(({ id }) => ({
+      value: id,
+      label: id,
+    }));
+  } catch (error) {
+    console.error("Error fetching datasets:", error);
+    return [];
+  }
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async options() {
const response = await this.getDatasets();
const datasets = response.data;
return datasets.map(({ id }) => ({
value: id,
}));
},
async options() {
try {
const response = await this.getDatasets();
const datasets = response.data;
return datasets.map(({ id }) => ({
value: id,
label: id,
}));
} catch (error) {
console.error("Error fetching datasets:", error);
return [];
}
},

},
},
methods: {
_baseUrl() {
return "https://api.geckoboard.com";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
auth,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
auth: {
username: `${this.$auth.api_key}`,
password: "",
...auth,
},
});
},
async appendToDataset({
datasetId, ...args
}) {
return this._makeRequest({
path: `/datasets/${datasetId}/data`,
method: "post",
...args,
});
},
async createDataset({
id, ...args
}) {
return this._makeRequest({
path: `/datasets/${id}`,
method: "put",
...args,
});
},
async deleteDataset({
datasetId, ...args
}) {
return this._makeRequest({
path: `/datasets/${datasetId}`,
method: "delete",
...args,
});
},
async getDatasets(args = {}) {
return this._makeRequest({
path: "/datasets",
...args,
});
},
},
};
8 changes: 5 additions & 3 deletions components/geckoboard/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "@pipedream/geckoboard",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream Geckoboard Components",
"main": "dist/app/geckoboard.app.mjs",
"main": "geckoboard.app.mjs",
"keywords": [
"pipedream",
"geckoboard"
],
"files": ["dist"],
"homepage": "https://pipedream.com/apps/geckoboard",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

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

Loading