Skip to content

Commit

Permalink
Merge pull request #31 from databox/example-push-data
Browse files Browse the repository at this point in the history
Added example implementation
  • Loading branch information
bwiz authored Aug 29, 2024
2 parents 0f28e0d + f2ef67d commit a2f8ece
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/pushData/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules/*
/dist/*
/package-lock.json
19 changes: 19 additions & 0 deletions examples/pushData/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "push-data",
"version": "1.0.0",
"description": "",
"main": "dist/app.js",
"scripts": {
"start": "node dist/app.js",
"build": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"databox": "^2.1.2"
},
"devDependencies": {
"typescript": "^5.5.4"
}
}
39 changes: 39 additions & 0 deletions examples/pushData/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
ApiResponse,
Configuration,
DataPostRequest,
DefaultApi,
} from "databox";

const config: Configuration = new Configuration({
basePath: "https://push.databox.com",
username: "<Your_Databox_API_Token>",
headers: {
Accept: "application/vnd.databox.v2+json",
},
});

const dataPostRequest: DataPostRequest = {
pushData: [
{
key: "<Metric_name>",
value: 123,
date: "<Date_in_ISO8601>",
unit: "<Unit>",
attributes: [{ key: "<Dimension_name>", value: "<Dimension_value>" }],
},
],
};

const api = new DefaultApi(config);

try {
api
.dataPostRaw(dataPostRequest)
.then((response: ApiResponse<void>) => response.raw.json())
.then((responseBody) => {
console.log("Response data", responseBody);
});
} catch (error) {
console.log("Error: ", error);
}
12 changes: 12 additions & 0 deletions examples/pushData/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}

0 comments on commit a2f8ece

Please sign in to comment.