Last active
August 21, 2017 13:12
-
-
Save JarvisPrestidge/103c5ce5c3266d5b488199f1b010276b to your computer and use it in GitHub Desktop.
Accounts API
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
// Get api dependencies - referer uri & cookies | |
const referer = await browser.getUrl(); | |
const cookies = await (await browser.getCookies()).get(); | |
const cookie = cookies.map((c: ICookie) => c.name + "=" + c.value).join("; "); | |
// Identifier for api call | |
const ajaxIdentifier = await browser.getAttribute(rootAccountSelector, "data-ajax-identifier"); | |
// Fetch account info from accounts api | |
const apiAccountInfoResponse = await getAccountInfo(cookie, bankUrl, referer, ajaxIdentifier); | |
const apiAccountInfo: IAccountApiResponse = JSON.parse(apiAccountInfoResponse); | |
// Destructuring out 'displayName', 'sortCode' & 'accountNo' | |
const { "account-name": displayName, "sort-code": sortCode, "account-number": accountNo } = apiAccountInfo; | |
/** | |
* Returns account information (account name, IBAN, sort-code, account, bic) from api | |
* | |
* @param {string} cookie | |
* @param {string} bankUrl | |
* @param {string} referer | |
* @param {string} ajaxIdentifier | |
* @returns {Promise<string>} | |
*/ | |
const getAccountInfo = async (cookie: string, | |
bankUrl: string, | |
referer: string, | |
ajaxIdentifier: string): Promise<string> => { | |
const getUri = `https://${bankUrl}/personal/ajax/IbanBic`; | |
const headers = { | |
"accept": "application/json, text/javascript, */*; q=0.01", | |
"accept-encoding": "gzip, deflate, br", | |
"accept-language": "en-GB,en-US;q=0.8,en;q=0.6", | |
"adrum": "isAjax:true", | |
"connection": "keep-alive", | |
"cookie": cookie, | |
"host": bankUrl, | |
"referer": referer, | |
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36", | |
"x-requested-with": "XMLHttpRequest" | |
}; | |
const qs = { | |
NOMINATED_ARRANGEMENT_ID: ajaxIdentifier | |
}; | |
const requestOpts = { | |
uri: getUri, | |
method: "GET", | |
qs, | |
gzip: true, | |
headers | |
}; | |
return await requestPromise(requestOpts); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment