diff --git a/components/geckoboard/.gitignore b/components/geckoboard/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/geckoboard/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/geckoboard/actions/append-to-dataset/append-to-dataset.mjs b/components/geckoboard/actions/append-to-dataset/append-to-dataset.mjs new file mode 100644 index 0000000000000..4a3037546330a --- /dev/null +++ b/components/geckoboard/actions/append-to-dataset/append-to-dataset.mjs @@ -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; + } + } + + const response = await this.app.appendToDataset({ + $, + datasetId: this.datasetId, + data: { + data: [ + data, + ], + }, + }); + + $.export("$summary", "Successfully appended data to dataset"); + return response; + }, + +}; diff --git a/components/geckoboard/actions/create-dataset/create-dataset.mjs b/components/geckoboard/actions/create-dataset/create-dataset.mjs new file mode 100644 index 0000000000000..2e68b589d0d23 --- /dev/null +++ b/components/geckoboard/actions/create-dataset/create-dataset.mjs @@ -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; + }, +}; diff --git a/components/geckoboard/actions/delete-dataset/delete-dataset.mjs b/components/geckoboard/actions/delete-dataset/delete-dataset.mjs new file mode 100644 index 0000000000000..77f27d10940a2 --- /dev/null +++ b/components/geckoboard/actions/delete-dataset/delete-dataset.mjs @@ -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; + }, +}; diff --git a/components/geckoboard/app/geckoboard.app.ts b/components/geckoboard/app/geckoboard.app.ts deleted file mode 100644 index e4c4031dc7546..0000000000000 --- a/components/geckoboard/app/geckoboard.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "geckoboard", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); \ No newline at end of file diff --git a/components/geckoboard/geckoboard.app.mjs b/components/geckoboard/geckoboard.app.mjs new file mode 100644 index 0000000000000..ddae380b9e26a --- /dev/null +++ b/components/geckoboard/geckoboard.app.mjs @@ -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, + })); + }, + }, + }, + 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, + }); + }, + }, +}; diff --git a/components/geckoboard/package.json b/components/geckoboard/package.json index a8de231b5a305..eba5d152beaa9 100644 --- a/components/geckoboard/package.json +++ b/components/geckoboard/package.json @@ -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 (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f67f299b96ab7..60743de2be36d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4878,7 +4878,11 @@ importers: specifier: ^1.11.7 version: 1.11.13 - components/geckoboard: {} + components/geckoboard: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/gem: dependencies: