Skip to content

Commit c582eed

Browse files
committed
v1.2.0
- added new methods - loadTranslations, loadCatalog, getPendingInvitations
1 parent 6e8e5a3 commit c582eed

File tree

3 files changed

+66
-11
lines changed

3 files changed

+66
-11
lines changed

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,34 @@ A node module for Bring! shopping lists.
1414
```javascript
1515
const bringApi = require(`bring-shopping`);
1616

17-
// provide user and email to login
18-
const bring = new bringApi({mail: `example@example.com`, password: `secret`});
19-
20-
// login to get your uuid and Bearer token
21-
await bring.login();
22-
23-
// get all lists and their listUuid
24-
const lists = await bring.loadLists();
17+
main()
18+
19+
async function main () {
20+
// provide user and email to login
21+
const bring = new bringApi({mail: `example@example.com`, password: `secret`});
22+
23+
// login to get your uuid and Bearer token
24+
await bring.login();
25+
26+
// get all lists and their listUuid
27+
const lists = await bring.loadLists();
28+
29+
// get items of a list by its list uuid
30+
const items = await bring.getItems('9b3ba561-02ad-4744-a737-c43k7e5b93ec');
31+
32+
// get translations
33+
const translations = await bring.loadTranslations('de-DE');
34+
}
2535
```
2636

2737
More important methods are `getItems(listUUID)`, `saveItem(listUuid, itemName, specificaiton)`,
2838
`moveToRecentList(listUuid, itemName)` and `getAllUsersFromList(listUuid)`.
2939

3040
## Changelog
3141

42+
### 1.2.0
43+
* (foxriver76) new functionalities -> getTranslations, getCatalog and getPendingInvitations
44+
3245
### 1.1.0
3346
* (foxriver76) use API version v2
3447

lib/bring.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Bring {
3737
this.bearerToken = data.access_token;
3838
this.refreshToken = data.refresh_token;
3939

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

@@ -147,7 +147,7 @@ class Bring {
147147

148148

149149
/**
150-
* @return json
150+
* @return {json}
151151
*/
152152
async getUserSettings() {
153153
try {
@@ -158,6 +158,48 @@ class Bring {
158158
} // endCatch
159159
} // endGetUserSettings
160160

161+
/**
162+
* Load translation file e. g. via 'de-DE'
163+
* @param {string} locale from which country translations will be loaded
164+
* @return {json} translations
165+
*/
166+
async loadTranslations(locale) {
167+
try {
168+
const data = await request(`https://web.getbring.com/locale/articles.${locale}.json`);
169+
this.useTranslations = true;
170+
return Promise.resolve(JSON.parse(data));
171+
} catch (e) {
172+
return Promise.reject(`Cannot get translations: ${e}`);
173+
} // endCatch
174+
} //endLoadTranslations
175+
176+
/**
177+
* Load translation file e. g. via 'de-DE'
178+
* @param {string} locale from which country translations will be loaded
179+
* @return {json} catalog
180+
*/
181+
async loadCatalog(locale) {
182+
try {
183+
const data = await request(`https://web.getbring.com/locale/catalog.${locale}.json`);
184+
return Promise.resolve(JSON.parse(data));
185+
} catch (e) {
186+
return Promise.reject(`Cannot get catalog: ${e}`);
187+
} // endCatch
188+
} //endLoadCatalog
189+
190+
/**
191+
* Get pending invitations
192+
* @return {json} pending invitations
193+
*/
194+
async getPendingInvitations() {
195+
try {
196+
const data = await request(`${this.url}bringusers/${this.uuid}/invitations?status=pending`, {headers: this.headers});
197+
return Promise.resolve(JSON.parse(data));
198+
} catch (e) {
199+
return Promise.reject(`Cannot get pending invitations: ${e}`);
200+
} // endCatch
201+
} // endGetPendingInvitations
202+
161203
} // endClassBring
162204

163205
module.exports = Bring;

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.1.0",
3+
"version": "1.2.0",
44
"description": "Nodejs wrapper for the Bring! API",
55
"author": {
66
"name": "Moritz Heusinger",

0 commit comments

Comments
 (0)