Skip to content

Instantly share code, notes, and snippets.

@yotavm
Last active August 15, 2018 18:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yotavm/d9275f47a649e772c1edc85d976535c7 to your computer and use it in GitHub Desktop.
Save yotavm/d9275f47a649e772c1edc85d976535c7 to your computer and use it in GitHub Desktop.
Quovo class
import request from 'superagent';
const BASE_URL = 'https://api.quovo.com/v2';
const API_KEY = parameters.QUOVO_API_KEY;
const WEBHOOK_SECRET = parameters.QUOVO_WEBHOOK_SECRET;
const sendPRequest = async (method, path, payload) => {
try {
const newRequest = await request[method](`${BASE_URL}/${path}`)
.type('json')
.set('Authorization', `Bearer ${API_KEY}`)
.send(payload);
return newRequest;
} catch (e) {
const url = e.response && e.response.req.path;
console.error(`Error talking to ${url}: ${e.status}, ${e.Error}`);
throw 'Non 200 response from remote server';
}
};
class QuovoApi {
static async addUser(user) {
const path = 'users';
const {
body: { user }
} = await sendRequest('post', path, user);
return user;
}
static async addAccount(quovoUserId, accountCreateParameters) {
const path = 'accounts';
const {
body: { account }
} = await sendRequest('post', path, accountCreateParameters);
return account;
}
static async syncAccount(account) {
const path = `/accounts/${account.id}/sync`;
await sendRequest('post', path);
}
static async getPortfolios(account) {
const path = `accounts/${account.id}/portfolios`;
const {
body: { portfolios }
} = await sendRequest('get', path);
return portfolios;
}
static async getExtras(portfolio) {
const path = `portfolios/${portfolio.id}/extras`;
const {
body: { extras }
} = await sendRequest('get', path);
return extras;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment