Skip to content

Commit 6e8e5a3

Browse files
authored
Merge pull request #2 from foxriver76/v2
Use API version 2
2 parents e26cd20 + b755720 commit 6e8e5a3

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ A node module for Bring! shopping lists.
1212
## Usage Example
1313

1414
```javascript
15-
const bringaApi = require(`bring-shopping`);
15+
const bringApi = require(`bring-shopping`);
1616

17-
// alternative you can use uuid as attribute, thus you wont need to login
17+
// provide user and email to login
1818
const bring = new bringApi({mail: `example@example.com`, password: `secret`});
1919

20-
// login to get your uuid
20+
// login to get your uuid and Bearer token
2121
await bring.login();
2222

2323
// get all lists and their listUuid
@@ -29,6 +29,9 @@ More important methods are `getItems(listUUID)`, `saveItem(listUuid, itemName, s
2929

3030
## Changelog
3131

32+
### 1.1.0
33+
* (foxriver76) use API version v2
34+
3235
### 1.0.2
3336
* (foxriver76) minor code optimization, nothing functional
3437

lib/bring.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,38 @@ class Bring {
77
constructor(options) {
88
this.mail = options.mail;
99
this.password = options.password;
10-
this.url = options.url || `https://api.getbring.com/rest/`;
10+
this.url = options.url || `https://api.getbring.com/rest/v2/`;
1111
this.uuid = options.uuid || ``;
12+
this.headers = {
13+
'X-BRING-API-KEY': `cof4Nc6D8saplXjE3h3HXqHH8m7VU2i1Gs0g85Sp`,
14+
'X-BRING-CLIENT': `webApp`,
15+
'X-BRING-CLIENT-SOURCE': `webApp`,
16+
'X-BRING-COUNTRY': `DE`
17+
};
1218
} // endConstructor
1319

1420
async login() {
1521
let data;
1622
try {
17-
data = await request(encodeURI(`${this.url}bringlists?email=${this.mail}&password=${this.password}`));
23+
data = await request.post(`${this.url}bringauth`,
24+
{
25+
form: {
26+
email: this.mail,
27+
password: this.password
28+
}
29+
});
1830
} catch (e) {
1931
throw `Cannot Login: ${e}`;
2032
} // endCatch
2133

2234
data = JSON.parse(data);
2335
this.name = data.name;
2436
this.uuid = data.uuid;
25-
this.headers = {
26-
'X-BRING-API-KEY': `cof4Nc6D8saplXjE3h3HXqHH8m7VU2i1Gs0g85Sp`,
27-
'X-BRING-CLIENT': `android`,
28-
'X-BRING-USER-UUID': this.uuid,
29-
'X-BRING-VERSION': `303070050`,
30-
'X-BRING-COUNTRY': `de`
31-
};
37+
this.bearerToken = data.access_token;
38+
this.refreshToken = data.refresh_token;
3239

40+
this.headers['X-BRING-USER-UUID'] = this.uuid;
41+
this.headers = Object.assign({'Authorization': `Bearer ${this.bearerToken}`}, this.headers);
3342
this.putHeaders = {...this.headers, ...{'Content-Type': `application/x-www-form-urlencoded; charset=UTF-8`}};
3443

3544
return Promise.resolve();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bring-shopping",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "Nodejs wrapper for the Bring! API",
55
"author": {
66
"name": "Moritz Heusinger",

0 commit comments

Comments
 (0)