Skip to content

Commit

Permalink
Merge pull request #28 from databox/readme-example
Browse files Browse the repository at this point in the history
Updated readme with content and example
  • Loading branch information
bwiz authored Aug 26, 2024
2 parents bd951b5 + d1384e2 commit 65ebc73
Showing 1 changed file with 45 additions and 20 deletions.
65 changes: 45 additions & 20 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,71 @@
## [email protected]

This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The generated Node module can be used in the following environments:
This package is designed to consume the Databox Push API functionality via TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The package is compatible with the following environments:

Environment
* Node.js
* Webpack
* Browserify

Language level
* ES5 - you must have a Promises/A+ library installed
* ES5 - You must have a Promises/A+ library installed
* ES6

Module system
* CommonJS
* ES6 module system

It can be used in both TypeScript and JavaScript. In TypeScript, the definition will be automatically resolved via `package.json`. ([Reference](https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html))
The package can be used with both TypeScript and JavaScript. In TypeScript, the definitions will be automatically resolved via `package.json`. ([Reference](https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html)).

### Building
### Installing

To build and compile the typescript sources to javascript use:
```
npm install
npm run build
npm install databox --save
```

### Publishing
### Prerequisites
In use the Databox Push API functionality, please refer to [Databox Developers Page](https://developers.databox.com/), specifically the **Quick Guide** section, where you will learn how to create a **Databox Push API token** which is required for pushing your data.

First build the package then run `npm publish`
### Example
The basic example of pushing data to Databox is provided below:
```TypeScript
import {
ApiResponse,
Configuration,
DataPostRequest,
DefaultApi,
} from "databox";

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

navigate to the folder of your consuming project and run one of the following commands.
const dataPostRequest: DataPostRequest = {
pushData: [
{
key: "<Metric_name>",
value: 123,
date: "<Date_in_ISO8601>",
unit: "<Unit>", // Optional
attributes: [{ key: "<Dimension_name>", value: "<Dimension_value>" }], // Optional
},
],
};

_published:_
const api = new DefaultApi(config);

```
npm install [email protected] --save
```

_unPublished (not recommended):_

```
npm install PATH_TO_GENERATED_PACKAGE --save
try {
api
.dataPostRaw(dataPostRequest)
.then((response: ApiResponse<void>) => response.raw.json())
.then((responseBody) => {
console.log("Response data", responseBody);
});
} catch (error) {
console.log("Error: ", error);
}
```

0 comments on commit 65ebc73

Please sign in to comment.