Skip to content

Commit 55f169d

Browse files
João Netonetoax
João Neto
authored andcommitted
docs: Update README
1 parent 65ac70c commit 55f169d

File tree

1 file changed

+75
-58
lines changed

1 file changed

+75
-58
lines changed

README.md

+75-58
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# knot-cloud-sdk-js
2+
23
[![npm version](https://badge.fury.io/js/%40cesarbr%2Fknot-cloud-sdk-js.svg)](https://badge.fury.io/js/%40cesarbr%2Fknot-cloud-sdk-js)
34

45
The `knot-cloud-sdk-js` is a client side library for Node.js and browser that aims to help developers to create solutions with the [KNoT Cloud](https://www.knot.cloud/).
56

67
This library exports the following SDKs:
78

8-
- <strong>[WebSocket SDK](https://github.com/CESARBR/knot-cloud-websocket) - [![npm version](https://badge.fury.io/js/%40cesarbr%2Fknot-cloud-websocket.svg)](https://badge.fury.io/js/%40cesarbr%2Fknot-cloud-websocket):</strong> to connect with WebSocket protocol adapter and operate on devices.
9+
- <strong>[AMQP SDK](https://github.com/CESARBR/knot-cloud-sdk-js-amqp) - [![npm version](https://badge.fury.io/js/%40cesarbr%2Fknot-cloud-sdk-js-amqp.svg)](https://badge.fury.io/js/%40cesarbr%2Fknot-cloud-sdk-js-amqp):</strong> to perform operations on things through the AMQP protocol.
910

1011
- <strong>[Authenticator SDK](https://github.com/CESARBR/knot-cloud-sdk-js-authenticator) - [![npm version](https://badge.fury.io/js/%40cesarbr%2Fknot-cloud-sdk-js-authenticator.svg)](https://badge.fury.io/js/%40cesarbr%2Fknot-cloud-sdk-js-authenticator):</strong> to perform user management tasks such as authentication and password recovery.
1112

1213
- <strong>[Storage SDK](https://github.com/CESARBR/knot-cloud-sdk-js-storage) - [![npm version](https://badge.fury.io/js/%40cesarbr%2Fknot-cloud-sdk-js-storage.svg)](https://badge.fury.io/js/%40cesarbr%2Fknot-cloud-sdk-js-storage):</strong> to operate on data sent by devices.
1314

14-
1515
# Quickstart
1616

1717
## Install
@@ -20,82 +20,84 @@ This library exports the following SDKs:
2020
npm install --save @cesarbr/knot-cloud-sdk-js
2121
```
2222

23-
## Example: Register Device
23+
## AMQP SDK: Creating a new thing
2424

2525
```javascript
26-
const { Client } = require('@cesarbr/knot-cloud-sdk-js');
27-
28-
const client = new Client({
29-
protocol: 'wss',
30-
hostname: 'ws.knot.cloud',
31-
port: 443,
32-
pathname: '/',
33-
id: '78159106-41ca-4022-95e8-2511695ce64c',
34-
token: 'd5265dbc4576a88f8654a8fc2c4d46a6d7b85574',
35-
});
26+
const { Client } = require("@cesarbr/knot-cloud-sdk-js");
27+
28+
const config = {
29+
amqp: {
30+
hostname: "broker.knot.cloud",
31+
port: 5672,
32+
username: "knot",
33+
password: "knot",
34+
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", // this is not a valid token!
35+
},
36+
http: {
37+
hostname: "api.knot.cloud", // API Gateway address
38+
port: 80,
39+
protocol: "http",
40+
},
41+
};
42+
43+
const thing = {
44+
id: "abcdef1234567890",
45+
name: "my-thing",
46+
};
47+
48+
const main = async () => {
49+
try {
50+
await client.connect();
51+
await client.register(thing.id, thing.name);
52+
console.log("thing successfully created");
53+
await client.close();
54+
} catch (err) {
55+
console.error(err);
56+
}
57+
};
3658

37-
client.on('ready', () => {
38-
client.register({
39-
id: '6e5a681b2ae7be40',
40-
type: 'knot:thing',
41-
name: 'Door Lock',
42-
});
43-
});
44-
client.on('registered', (thing) => {
45-
console.log('Registered', thing);
46-
client.close();
47-
});
48-
client.connect();
59+
main();
4960
```
5061

51-
## Example: List Device Data
62+
## Authenticator: Creating a new user
5263

5364
```javascript
54-
const { Storage } = require('@cesarbr/knot-cloud-sdk-js');
65+
const { Authenticator } = require("@cesarbr/knot-cloud-sdk-js");
5566

56-
const client = new Storage({
57-
protocol: 'https',
58-
hostname: 'data.knot.cloud',
59-
id: 'b1a1bd58-c3ef-4cb5-82cd-3a2e0b38dd21',
60-
token: '3185a6c9d64915f6b468ee8043df4af5f08e1933',
67+
const client = new Authenticator({
68+
protocol: "https",
69+
hostname: "api.knot.cloud",
6170
});
6271

6372
async function main() {
64-
console.log(await client.listData())
73+
try {
74+
await client.createUser("user@provider.com", "123qwe!@#QWE");
75+
} catch (err) {
76+
if (err.response) {
77+
console.error(err.response.data.message);
78+
return;
79+
}
80+
console.error(err);
81+
}
6582
}
66-
main();
6783

68-
// [{
69-
// from: '188824f0-28c4-475b-ab36-2505402bebcb',
70-
// payload: {
71-
// sensorId: 2,
72-
// value: 234,
73-
// },
74-
// timestamp: '2019-03-18T12:48:05.569Z',
75-
// },
76-
// {
77-
// from: '188824f0-28c4-475b-ab36-2505402bebcb',
78-
// payload: {
79-
// sensorId: 1,
80-
// value: true,
81-
// },
82-
// timestamp: '2019-03-18T14:42:03.192Z',
83-
// }]
84+
main();
8485
```
8586

86-
## Example:
87+
## Storage: Receiving user's data
8788

8889
```javascript
89-
const { Authenticator } = require('@cesarbr/knot-cloud-sdk-js');
90+
const { Storage } = require("@cesarbr/knot-cloud-sdk-js");
9091

91-
const client = new Authenticator({
92-
protocol: 'https',
93-
hostname: 'auth.knot.cloud',
92+
const client = new Storage({
93+
protocol: "https",
94+
hostname: "data.knot.cloud",
95+
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", // this is not a valid token!
9496
});
9597

9698
async function main() {
9799
try {
98-
console.log(await client.createUser('user@provider.com', '123qwe!@#QWE'));
100+
console.log(await client.listData());
99101
} catch (err) {
100102
if (err.response) {
101103
console.error(err.response.data.message);
@@ -104,8 +106,23 @@ async function main() {
104106
console.error(err);
105107
}
106108
}
109+
107110
main();
108111

109-
// { id: '863ad780-efd9-4158-b24a-026de3f1dffb'
110-
// token: '40ad864d503488eda9b629825876d46cb1356bdf' }
112+
// [{
113+
// from: '188824f0-28c4-475b-ab36-2505402bebcb',
114+
// payload: {
115+
// sensorId: 2,
116+
// value: 234,
117+
// },
118+
// timestamp: '2019-03-18T12:48:05.569Z',
119+
// },
120+
// {
121+
// from: '188824f0-28c4-475b-ab36-2505402bebcb',
122+
// payload: {
123+
// sensorId: 1,
124+
// value: true,
125+
// },
126+
// timestamp: '2019-03-18T14:42:03.192Z',
127+
// }]
111128
```

0 commit comments

Comments
 (0)