-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,71 @@ | ||
## [email protected] | ||
## Databox | ||
|
||
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); | ||
} | ||
``` |