Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Commit

Permalink
add examples for getClientInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
pladaria committed Aug 11, 2017
1 parent 2b20caf commit 0c9e7b9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,20 @@ degiro.getAskBidPrice('350009261').then(console.log);

```javascript
degiro.getProductsByIds(['8066561', '350009261'])).then(console.log);
// displays product details
```

### getClientInfo

Requests client info (name, email, address, role, etc) to the server and updates the session information

```javascript
degiro.getClientInfo().then(console.log);
// displays client information
```

You can also access this information in `degiro.session.clientInfo` after a successful login

## Examples

See [examples](./examples)
Expand Down
10 changes: 10 additions & 0 deletions examples/get-client-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const DeGiro = require('..');

const degiro = DeGiro.create({
// username: 'your-username',
// password: 'your-password',
});

degiro.login().then(degiro.getClientInfo)
.then(res => console.log('from network:', res))
.then(() => console.log('from session:', degiro.session.clientInfo));
20 changes: 6 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,19 @@ const create = (
};

/**
* Update client info
* Get client info
*
* @return {Promise}
*/
const updateClientInfo = () => {
log('updateClientInfo');
return fetch(`${BASE_TRADER_URL}/pa/secure/client?sessionId=${session.id}`)
const getClientInfo = () =>
fetch(`${BASE_TRADER_URL}/pa/secure/client?sessionId=${session.id}`)
.then(res => res.json())
.then(clientInfo => {
session.account = clientInfo.intAccount;
session.userToken = clientInfo.id;
this.clientInfo = clientInfo;
session.clientInfo = clientInfo;
return clientInfo;
});
};

/**
* Get client info
*
* @return Client info
*/
const getClientInfo = () => this.clientInfo;

/**
* Login
Expand All @@ -209,7 +201,7 @@ const create = (
throw Error('Login error');
}
})
.then(updateClientInfo)
.then(getClientInfo)
.then(() => session);
};

Expand Down

0 comments on commit 0c9e7b9

Please sign in to comment.