robinhood-typescript
Advanced tools
Comparing version 1.2.0 to 1.3.0
import { AccountsLoaded } from './models/account'; | ||
import { FundamentalsLoaded } from './models/fundamentals'; | ||
import { Userloaded } from './models/user'; | ||
declare class RobinhoodAPI { | ||
@@ -10,4 +11,5 @@ private _authToken; | ||
account(): Promise<AccountsLoaded>; | ||
user(): Promise<Userloaded>; | ||
fundamentals(ticker: string): Promise<FundamentalsLoaded>; | ||
} | ||
export default RobinhoodAPI; |
@@ -53,2 +53,14 @@ "use strict"; | ||
} | ||
async user() { | ||
const config = { | ||
headers: { Authorization: `Bearer ${this._authToken}` }, | ||
}; | ||
try { | ||
const response = await axios_1.default.get(`${defaults_1.apiUrl}${defaults_1.endpoints.user}`, config); | ||
return response.data; | ||
} | ||
catch (error) { | ||
return error; | ||
} | ||
} | ||
// This will pull info on any individual ticker. | ||
@@ -55,0 +67,0 @@ // User needs to input a comma btwn each string. |
{ | ||
"name": "robinhood-typescript", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "NodeJS Framework to make trades with the private Robinhood API. Using this API is not encouraged, since it's not officially available and it has been reverse engineered. See @Sanko's Unofficial Documentation for more information.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -121,2 +121,40 @@ import RobinhoodAPI from '../index'; | ||
describe('User', () => { | ||
test('successful retrive user information', async () => { | ||
const data = { | ||
url: 'https://api.robinhood.com/user/', | ||
id: '1324546', | ||
id_info: 'https://api.robinhood.com/user/id/', | ||
username: 'johnsmith@hotmail.com', | ||
email: 'johnsmith@hotmail.com', | ||
email_verified: true, | ||
first_name: 'John', | ||
last_name: 'Smith', | ||
origin: { locality: 'US' }, | ||
profile_name: 'JohnS12651', | ||
created_at: '2019-01-03T20:35:43.232669-05:00', | ||
}; | ||
const api = new RobinhoodAPI('token'); | ||
mockedAxios.get.mockResolvedValue({ data }); | ||
const userInfo = await api.user(); | ||
expect(userInfo).toEqual(data); | ||
}); | ||
}); | ||
test('failure retrive user information', async () => { | ||
const errorMessage = 'provided bad token'; | ||
const api = new RobinhoodAPI('token'); | ||
mockedAxios.get.mockRejectedValue({ errorMessage }); | ||
const userInfo = await api.user(); | ||
expect(userInfo).toEqual({ errorMessage }); | ||
}); | ||
describe('Fundamentals', () => { | ||
@@ -123,0 +161,0 @@ test('successful retrieve fundamentals infromation', async () => { |
@@ -7,2 +7,3 @@ import { apiUrl, endpoints } from './models/defaults'; | ||
import { FundamentalsLoaded } from './models/fundamentals'; | ||
import { Userloaded } from './models/user'; | ||
@@ -62,2 +63,15 @@ class RobinhoodAPI { | ||
async user(): Promise<Userloaded> { | ||
const config = { | ||
headers: { Authorization: `Bearer ${this._authToken}` }, | ||
}; | ||
try { | ||
const response: AxiosResponse<Userloaded> = await axios.get(`${apiUrl}${endpoints.user}`, config); | ||
return response.data; | ||
} catch (error) { | ||
return error; | ||
} | ||
} | ||
// This will pull info on any individual ticker. | ||
@@ -64,0 +78,0 @@ // User needs to input a comma btwn each string. |
Sorry, the diff of this file is too big to display
548201
29
13922