Skip to content

Commit 42e77dd

Browse files
Merge pull request #740 from inplayer-org/external-account
new methods in Account: `syncWithExternalAccount` and `updateExternalAccount`
2 parents 956fd1c + 8fea75c commit 42e77dd

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
# [3.11.2] - 23-09-2021
6+
7+
### Added
8+
9+
- New `Account` methods: `synchWithExternalAccount` and `updateExternalAccount`
10+
511
# [3.11.1] - 26-04-2021
612

713
### Fixes

index.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ export declare interface RestrictionSettingsData {
154154
updated_at: number;
155155
}
156156

157+
export declare interface ExternalAccount {
158+
id: number;
159+
account_id: number;
160+
token: string;
161+
}
162+
157163
export declare class Account {
158164
constructor(config: Record<string, unknown>);
159165

@@ -198,6 +204,10 @@ export declare class Account {
198204
loadMerchantRestrictionSettings(
199205
merchantUuid: string
200206
): Promise<AxiosResponse<RestrictionSettingsData>>;
207+
syncWithExternalAccount(integration: string, itemId: number): Promise<AxiosResponse<ExternalAccount>>;
208+
updateExternalAccount(
209+
integration: string, body: Record<string, string | number>
210+
): Promise<AxiosResponse<CommonResponse>>;
201211
}
202212

203213
export declare interface AccessControlType {
@@ -899,6 +909,7 @@ export interface ApiEndpoints {
899909
deleteAccount: string;
900910
exportData: string;
901911
reportSSOtoken: (ssoDomain: string) => string;
912+
externalAccount: (integration: string) => string;
902913
// Asset
903914
checkAccessForAsset: (id: number) => string;
904915
checkFreeTrial: (id: number) => string;

src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const API = {
4545
validatePinCode: '/v2/accounts/pin-codes/validate',
4646
merchantRestrictionSettings: (merchantUuid: string) =>
4747
`/restrictions/settings/${merchantUuid}`,
48+
externalAccount: (integration: string) => `/v2/accounts/external/${integration}`,
4849
// Asset
4950
checkAccessForAsset: (id: any) => `/items/${id}/access`,
5051
checkFreeTrial: (id: any) => `/items/used-trial-period/${id}`,

src/endpoints/account.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,58 @@ class Account extends BaseExtend {
422422
});
423423
}
424424

425+
/**
426+
* Creates or returns an existing external account integrated with an InPlayer fan account
427+
* @method syncWithExternalAccount
428+
* @async
429+
* @param {string} integration - the name of the external integration
430+
* @param {number} itemId - the Id of the Inplayer item
431+
* @example
432+
* InPlayer.Account
433+
* .syncWithExternalAccount('livelike', 12345)
434+
* .then(data => console.log(data));
435+
* @returns {AxiosResponse<LivelikeProfile>} Contains the data - {
436+
"id": 3,
437+
"account_id": 54321,
438+
"token": '.....'
439+
}
440+
*/
441+
async syncWithExternalAccount(integration: string, itemId: number) {
442+
const body = { item_id: itemId };
443+
444+
const tokenObject = await this.request.getToken();
445+
446+
return this.request.post(API.externalAccount(integration), qs.stringify(body), {
447+
headers: {
448+
Authorization: `Bearer ${tokenObject.token}`,
449+
'Content-Type': 'application/x-www-form-urlencoded',
450+
},
451+
});
452+
}
453+
454+
/**
455+
* Updates an existing external account integrated with an InPlayer fan account
456+
* @method updateExternalAccount
457+
* @async
458+
* @param {string} integration - the name of the external integration
459+
* @param {string} nickname - the new nickname value
460+
* @example
461+
* InPlayer.Account
462+
* .updateExternalAccount('livelike', { nickname: 'My New Nickname' })
463+
* .then(data => console.log(data));
464+
* @returns {AxiosResponse<undefined>}
465+
*/
466+
async updateExternalAccount(integration: string, body: Record<string, any>) {
467+
const tokenObject = await this.request.getToken();
468+
469+
return this.request.patch(API.externalAccount(integration), qs.stringify(body), {
470+
headers: {
471+
Authorization: `Bearer ${tokenObject.token}`,
472+
'Content-Type': 'application/x-www-form-urlencoded',
473+
},
474+
});
475+
}
476+
425477
/**
426478
* Gets the account information for a given auth token
427479
* @method getAccountInfo

0 commit comments

Comments
 (0)