diff --git a/src/README.md b/src/README.md index cac0135..a0514c4 100644 --- a/src/README.md +++ b/src/README.md @@ -1,6 +1,6 @@ ## databox@2.1.1 -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 @@ -8,39 +8,64 @@ Environment * 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: "", + 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: "", + value: 123, + date: "", + unit: "", // Optional + attributes: [{ key: "", value: "" }], // Optional + }, + ], +}; -_published:_ +const api = new DefaultApi(config); -``` -npm install databox@2.1.1 --save -``` - -_unPublished (not recommended):_ - -``` -npm install PATH_TO_GENERATED_PACKAGE --save +try { + api + .dataPostRaw(dataPostRequest) + .then((response: ApiResponse) => response.raw.json()) + .then((responseBody) => { + console.log("Response data", responseBody); + }); +} catch (error) { + console.log("Error: ", error); +} ```