get user info
This commit is contained in:
parent
6c9a801aef
commit
cdeff63b85
10
README.md
10
README.md
|
@ -20,6 +20,16 @@ import * as api from 'd-fi-core';
|
|||
// Init api with arl from cookie
|
||||
await api.initDeezerApi(arl_cookie);
|
||||
|
||||
// Verify user
|
||||
try {
|
||||
const user = await api.getUser();
|
||||
// Successfully logged in
|
||||
console.log('Logged in as ' + user.BLOG_NAME);
|
||||
} catch (err) {
|
||||
// Invalid arl cookie set
|
||||
console.error(err.message);
|
||||
}
|
||||
|
||||
// GET Track Object
|
||||
const track = await api.getTrackInfo(song_id);
|
||||
|
||||
|
|
17
src/api.ts
17
src/api.ts
|
@ -13,6 +13,7 @@ import type {
|
|||
searchType,
|
||||
trackTypePublicApi,
|
||||
albumTypePublicApi,
|
||||
userType,
|
||||
} from './types';
|
||||
|
||||
// expire cache in 60 minutes
|
||||
|
@ -163,3 +164,19 @@ type searchTypesProp = 'ALBUM' | 'ARTIST' | 'TRACK' | 'PLAYLIST' | 'RADIO' | 'SH
|
|||
*/
|
||||
export const searchMusic = (query: string, types: searchTypesProp[] = ['TRACK'], nb = 15): Promise<searchType> =>
|
||||
request({query, nb, types}, 'mobile_suggest');
|
||||
|
||||
/**
|
||||
* Get details about current user
|
||||
*/
|
||||
export const getUser = async (): Promise<userType> => {
|
||||
const {
|
||||
data: {error, results},
|
||||
} = await axios.get('/gateway.php', {params: {method: 'user_getInfo'}});
|
||||
|
||||
if (Object.keys(results).length > 0) {
|
||||
return results;
|
||||
}
|
||||
|
||||
const errorMessage = Object.entries(error).join(', ');
|
||||
throw new Error(errorMessage);
|
||||
};
|
||||
|
|
|
@ -4,3 +4,4 @@ export * from './playlist';
|
|||
export * from './profile';
|
||||
export * from './search';
|
||||
export * from './tracks';
|
||||
export * from './user';
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
export interface userType {
|
||||
USER_ID: string;
|
||||
EMAIL: string;
|
||||
FIRSTNAME: string;
|
||||
LASTNAME: string;
|
||||
BIRTHDAY: string;
|
||||
BLOG_NAME: string;
|
||||
SEX: string;
|
||||
ADDRESS?: string;
|
||||
CITY?: string;
|
||||
ZIP?: string;
|
||||
COUNTRY: string;
|
||||
LANG: string;
|
||||
PHONE?: string;
|
||||
__TYPE__: 'user';
|
||||
}
|
Loading…
Reference in New Issue