Skip to content

Commit

Permalink
docs: expanded the usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Jul 16, 2020
1 parent 4347ee5 commit e5cb269
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# aw-client-js

Client library for [ActivityWatch](http://activitywatch.net) in JavaScript.
Client library for [ActivityWatch](http://activitywatch.net) in TypeScript/JavaScript.

[![Build Status](https://github.com/ActivityWatch/aw-client-js/workflows/Build/badge.svg)](https://github.com/ActivityWatch/aw-client-js/actions)
[![Known Vulnerabilities](https://snyk.io/test/github/ActivityWatch/aw-client-js/badge.svg)](https://snyk.io/test/github/ActivityWatch/aw-client-js)
Expand All @@ -13,10 +13,28 @@ npm install aw-client

## Usage

The library uses Promises for almost everything, so either use `.then()` or the (recommended) async/aways syntax.

The example below is written with `.then()` to make it easy to run in the node REPL.

```javascript
const { AWClient } = require('aw-client');
const client = new AWClient('test-client')

// Get server info
client.getInfo().then(console.log);

// List buckets
client.getBuckets().then(console.log);

// Create bucket
const bucketId = "test";
client.createBucket(bucketId, "bucket-type", "your-hostname");

const client = new AWClient(myClientName)
// Send a heartbeat
const nowStr = (new Date()).toISOString();
const heartbeat = {timestamp: nowStr, duration: 0, data: { label: "just testing!" }};
client.heartbeat(bucketId, 5, heartbeat);
```

## Contribute
Expand Down

0 comments on commit e5cb269

Please sign in to comment.