Last active
August 15, 2018 18:50
-
-
Save yotavm/d9275f47a649e772c1edc85d976535c7 to your computer and use it in GitHub Desktop.
Quovo class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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