Skip to content

Commit 6b9162d

Browse files
Merge pull request #780 from inplayer-org/add-profile-endpoints
Add profile endpoints to SDK
2 parents bd136ef + c80301e commit 6b9162d

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

src/constants/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export const API = {
2828
getWatchHistory: '/v2/accounts/media/watch-history',
2929
getWatchHistoryForItem: (id: string): string =>
3030
`/v2/accounts/media/watch-history/${id}`,
31+
32+
profiles: '/v2/accounts/profiles',
33+
getProfilesItem: (id: string): string =>
34+
`/v2/accounts/profiles/${id}`,
35+
3136
// restrictions
3237
merchantRestrictionSettings: (merchantUuid: string): string =>
3338
`/restrictions/settings/${merchantUuid}`,

src/endpoints/account.ts

+90
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
FavoritesData,
1515
WatchHistory,
1616
CollectionWithCursorArgs,
17+
ProfilesData,
1718
} from '../models/IAccount&Authentication';
1819
import {
1920
CommonResponse,
@@ -1377,6 +1378,95 @@ class Account extends BaseExtend {
13771378
},
13781379
});
13791380
}
1381+
1382+
async getProfiles(): Promise<
1383+
AxiosResponse<ProfilesData[]>
1384+
> {
1385+
const tokenObject = await this.request.getToken();
1386+
return this.request.get(API.profiles, {
1387+
headers: {
1388+
Authorization: `Bearer ${tokenObject.token}`,
1389+
'Content-Type': 'application/x-www-form-urlencoded',
1390+
},
1391+
});
1392+
}
1393+
1394+
async enterProfile(id: string, pin?:number): Promise<AxiosResponse<ProfilesData>> {
1395+
const body = {
1396+
pin,
1397+
};
1398+
const tokenObject = await this.request.getToken();
1399+
return this.request.post(`${API.getProfilesItem(id)}/token`, qs.stringify(body), {
1400+
headers: {
1401+
Authorization: `Bearer ${tokenObject.token}`,
1402+
'Content-Type': 'application/x-www-form-urlencoded',
1403+
},
1404+
});
1405+
}
1406+
1407+
async createProfile(
1408+
name: string,
1409+
adult: boolean,
1410+
avatar_url?: string,
1411+
pin?:number,
1412+
): Promise<
1413+
AxiosResponse<ProfilesData>
1414+
> {
1415+
const body = {
1416+
name,
1417+
adult,
1418+
avatar_url,
1419+
pin,
1420+
};
1421+
const tokenObject = await this.request.getToken();
1422+
return this.request.post(API.profiles, qs.stringify(body), {
1423+
headers: {
1424+
Authorization: `Bearer ${tokenObject.token}`,
1425+
'Content-Type': 'application/x-www-form-urlencoded',
1426+
},
1427+
});
1428+
}
1429+
1430+
async getProfileDetails(
1431+
id: string,
1432+
): Promise<AxiosResponse<ProfilesData>> {
1433+
const tokenObject = await this.request.getToken();
1434+
return this.request.get(API.getProfilesItem(id), {
1435+
headers: {
1436+
Authorization: `Bearer ${tokenObject.token}`,
1437+
'Content-Type': 'application/x-www-form-urlencoded',
1438+
},
1439+
});
1440+
}
1441+
async updateProfile(
1442+
id: string,
1443+
name: string,
1444+
avatar_url: string,
1445+
): Promise<AxiosResponse<ProfilesData>> {
1446+
const body = {
1447+
name,
1448+
avatar_url,
1449+
};
1450+
const tokenObject = await this.request.getToken();
1451+
return this.request.put(API.getProfilesItem(id), qs.stringify(body), {
1452+
headers: {
1453+
Authorization: `Bearer ${tokenObject.token}`,
1454+
'Content-Type': 'application/x-www-form-urlencoded',
1455+
},
1456+
});
1457+
}
1458+
1459+
async deleteProfile(
1460+
id: string,
1461+
): Promise<AxiosResponse<ProfilesData>> {
1462+
const tokenObject = await this.request.getToken();
1463+
return this.request.delete(API.getProfilesItem(id), {
1464+
headers: {
1465+
Authorization: `Bearer ${tokenObject.token}`,
1466+
'Content-Type': 'application/x-www-form-urlencoded',
1467+
},
1468+
});
1469+
}
13801470
}
13811471

13821472
export default Account;

src/models/IAccount&Authentication.ts

+23
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,17 @@ export interface FavoritesData {
168168
media_id: string;
169169
created_at: number;
170170
}
171+
export interface ProfilesData {
172+
id: string,
173+
account_id: string,
174+
name: string,
175+
avatar_url: string,
176+
default: boolean,
177+
adult: boolean,
178+
pin_required: boolean,
179+
created_at: number,
180+
updated_at: number,
181+
}
171182

172183
export interface CollectionWithCursor<T> {
173184
collection: T[];
@@ -233,4 +244,16 @@ export interface Account extends BaseExtend {
233244
deleteWatchHistoryForItem(
234245
mediaId: string
235246
): Promise<AxiosResponse<CommonResponse>>;
247+
getProfiles(): Promise<AxiosResponse<ProfilesData>>;
248+
enterProfile(id: string, pin?:number): Promise<AxiosResponse<ProfilesData>>;
249+
createProfile(name: string,
250+
adult: boolean,
251+
avatar_url?: string,
252+
pin?:number,): Promise<AxiosResponse<ProfilesData>>;
253+
getProfileDetails(id: string): Promise<AxiosResponse<ProfilesData>>;
254+
updateProfile(id: string, name: string,
255+
avatar_url?: string,
256+
): Promise<AxiosResponse<ProfilesData>>;
257+
deleteProfile(id: string): Promise<AxiosResponse<ProfilesData>>;
258+
236259
}

0 commit comments

Comments
 (0)