account.js

  1. import axios from 'axios';
  2. import debug from 'debug';
  3. import {defaultHeaders} from './http';
  4. const log = debug('starling:account-service');
  5. /**
  6. * Service to interact with a customer's account
  7. */
  8. class Account {
  9. /**
  10. * Creates an instance of the account client
  11. * @param {Object} options - application config
  12. */
  13. constructor (options) {
  14. this.options = options;
  15. }
  16. /**
  17. * Retrieves a customer's account
  18. * @param {string} accessToken - the oauth bearer token
  19. * @return {Promise} - the http request promise
  20. */
  21. getAccount (accessToken) {
  22. const url = `${this.options.apiUrl}/api/v1/accounts`;
  23. log(`GET ${url}`);
  24. return axios({
  25. method: 'GET',
  26. url,
  27. headers: defaultHeaders(accessToken)
  28. });
  29. }
  30. /**
  31. * Retrieves the customer's balance
  32. * @param {string} accessToken - the oauth bearer token
  33. * @return {Promise} - the http request promise
  34. */
  35. getBalance (accessToken) {
  36. const url = `${this.options.apiUrl}/api/v1/accounts/balance`;
  37. log(`GET ${url}`);
  38. return axios({
  39. method: 'GET',
  40. url,
  41. headers: defaultHeaders(accessToken)
  42. });
  43. }
  44. }
  45. module.exports = Account;