fix(core): Fixed module name inconsistencies and documentation links
This commit is contained in:
66
ts/medium.classes.account.ts
Normal file
66
ts/medium.classes.account.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { MediumPublication } from './medium.classes.publication.js';
|
||||
import * as plugins from './medium.plugins.js';
|
||||
|
||||
export interface IMediumAccountData {
|
||||
id: string;
|
||||
username: string;
|
||||
url: string;
|
||||
imageUrl: string;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export class MediumAccount implements IMediumAccountData {
|
||||
// STATIC
|
||||
|
||||
// INSTANCE
|
||||
private accessToken: string;
|
||||
public readyDeferred = plugins.smartpromise.defer();
|
||||
public baseApiDomain = 'https://api.medium.com/v1';
|
||||
|
||||
id: string;
|
||||
username: string;
|
||||
url: string;
|
||||
imageUrl: string;
|
||||
|
||||
constructor(accessTokenArg: string) {
|
||||
this.accessToken = accessTokenArg;
|
||||
this.getAccountInfo().then((dataArg) => {
|
||||
Object.assign(this, dataArg);
|
||||
this.readyDeferred.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
public async getAccountInfo(): Promise<IMediumAccountData> {
|
||||
const result = await this.request('/me', 'GET');
|
||||
const accountData = result.body.data;
|
||||
return accountData;
|
||||
}
|
||||
|
||||
public async getAllPublications(): Promise<MediumPublication[]> {
|
||||
return MediumPublication.getAllPublications(this);
|
||||
}
|
||||
|
||||
public async getOwnPublications(): Promise<MediumPublication[]> {
|
||||
return MediumPublication.getOwnPublications(this);
|
||||
}
|
||||
|
||||
public async getPublicationByName(nameArg: string): Promise<MediumPublication> {
|
||||
return MediumPublication.getPublicationByName(this, nameArg);
|
||||
}
|
||||
|
||||
public async request(routeArg: string, methodArg: 'POST' | 'GET', payloadArg?: any) {
|
||||
const response = await plugins.smartrequest.request(`${this.baseApiDomain}${routeArg}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
'Accept-Charset': 'utf-8',
|
||||
},
|
||||
method: methodArg,
|
||||
requestBody: payloadArg ? JSON.stringify(payloadArg) : null
|
||||
});
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user