Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
- added new methods
- loadTranslations, loadCatalog, getPendingInvitations
  • Loading branch information
foxriver76 committed Jul 9, 2019
1 parent 6e8e5a3 commit c582eed
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,34 @@ A node module for Bring! shopping lists.
```javascript
const bringApi = require(`bring-shopping`);

// provide user and email to login
const bring = new bringApi({mail: `example@example.com`, password: `secret`});

// login to get your uuid and Bearer token
await bring.login();

// get all lists and their listUuid
const lists = await bring.loadLists();
main()

async function main () {
// provide user and email to login
const bring = new bringApi({mail: `example@example.com`, password: `secret`});

// login to get your uuid and Bearer token
await bring.login();

// get all lists and their listUuid
const lists = await bring.loadLists();

// get items of a list by its list uuid
const items = await bring.getItems('9b3ba561-02ad-4744-a737-c43k7e5b93ec');

// get translations
const translations = await bring.loadTranslations('de-DE');
}
```

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

## Changelog

### 1.2.0
* (foxriver76) new functionalities -> getTranslations, getCatalog and getPendingInvitations

### 1.1.0
* (foxriver76) use API version v2

Expand Down
46 changes: 44 additions & 2 deletions lib/bring.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Bring {
this.bearerToken = data.access_token;
this.refreshToken = data.refresh_token;

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

Expand Down Expand Up @@ -147,7 +147,7 @@ class Bring {


/**
* @return json
* @return {json}
*/
async getUserSettings() {
try {
Expand All @@ -158,6 +158,48 @@ class Bring {
} // endCatch
} // endGetUserSettings

/**
* Load translation file e. g. via 'de-DE'
* @param {string} locale from which country translations will be loaded
* @return {json} translations
*/
async loadTranslations(locale) {
try {
const data = await request(`https://web.getbring.com/locale/articles.${locale}.json`);
this.useTranslations = true;
return Promise.resolve(JSON.parse(data));
} catch (e) {
return Promise.reject(`Cannot get translations: ${e}`);
} // endCatch
} //endLoadTranslations

/**
* Load translation file e. g. via 'de-DE'
* @param {string} locale from which country translations will be loaded
* @return {json} catalog
*/
async loadCatalog(locale) {
try {
const data = await request(`https://web.getbring.com/locale/catalog.${locale}.json`);
return Promise.resolve(JSON.parse(data));
} catch (e) {
return Promise.reject(`Cannot get catalog: ${e}`);
} // endCatch
} //endLoadCatalog

/**
* Get pending invitations
* @return {json} pending invitations
*/
async getPendingInvitations() {
try {
const data = await request(`${this.url}bringusers/${this.uuid}/invitations?status=pending`, {headers: this.headers});
return Promise.resolve(JSON.parse(data));
} catch (e) {
return Promise.reject(`Cannot get pending invitations: ${e}`);
} // endCatch
} // endGetPendingInvitations

} // endClassBring

module.exports = Bring;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bring-shopping",
"version": "1.1.0",
"version": "1.2.0",
"description": "Nodejs wrapper for the Bring! API",
"author": {
"name": "Moritz Heusinger",
Expand Down

0 comments on commit c582eed

Please sign in to comment.