Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated readme with content and example #28

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all 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
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);
}
```
Loading