Skip to content

Commit

Permalink
fix instance creation and made request protected
Browse files Browse the repository at this point in the history
  • Loading branch information
Niek van Gogh committed Oct 24, 2020
1 parent 601895a commit faf907b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"name": "Niek van Gogh",
"email": "[email protected]",
"url": "https://github.com/niekvangogh"
}
}
],
"license": "ISC",
"bugs": {
Expand Down
38 changes: 17 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,22 @@ import { WhmcsUsersService } from "./module/users";

export default class WhmcsApi {

public static options: WhmcsSetupOptions;
constructor(private readonly options: WhmcsSetupOptions) { }

constructor(options: WhmcsSetupOptions) {
WhmcsApi.options = options
}

public addons: WhmcsAddonsService = new WhmcsAddonsService;
public affiliates: WhmcsAffiliatesService = new WhmcsAffiliatesService;
public authentication: WhmcsAuthenticationService = new WhmcsAuthenticationService;
public billing: WhmcsBillingService = new WhmcsBillingService;
public client: WhmcsClientService = new WhmcsClientService;
public domains: WhmcsDomainsService = new WhmcsDomainsService;
public module: WhmcsModuleService = new WhmcsModuleService;
public orders: WhmcsOrdersService = new WhmcsOrdersService;
public products: WhmcsProductsService = new WhmcsProductsService;
public projectmanagement: WhmcsProjectManagementService = new WhmcsProjectManagementService;
public servers: WhmcsServersService = new WhmcsServersService;
public service: WhmcsServiceService = new WhmcsServiceService;
public support: WhmcsSupportService = new WhmcsSupportService;
public system: WhmcsSystemService = new WhmcsSystemService;
public tickets: WhmcsTicketsService = new WhmcsTicketsService;
public users: WhmcsUsersService = new WhmcsUsersService;
public addons: WhmcsAddonsService = new WhmcsAddonsService(options);
public affiliates: WhmcsAffiliatesService = new WhmcsAffiliatesService(options);
public authentication: WhmcsAuthenticationService = new WhmcsAuthenticationService(options);
public billing: WhmcsBillingService = new WhmcsBillingService(options);
public client: WhmcsClientService = new WhmcsClientService(options);
public domains: WhmcsDomainsService = new WhmcsDomainsService(options);
public module: WhmcsModuleService = new WhmcsModuleService(options);
public orders: WhmcsOrdersService = new WhmcsOrdersService(options);
public products: WhmcsProductsService = new WhmcsProductsService(options);
public projectmanagement: WhmcsProjectManagementService = new WhmcsProjectManagementService(options);
public servers: WhmcsServersService = new WhmcsServersService(options);
public service: WhmcsServiceService = new WhmcsServiceService(options);
public support: WhmcsSupportService = new WhmcsSupportService(options);
public system: WhmcsSystemService = new WhmcsSystemService(options);
public tickets: WhmcsTicketsService = new WhmcsTicketsService(options);
public users: WhmcsUsersService = new WhmcsUsersService(options);
}
11 changes: 7 additions & 4 deletions src/module/base.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import got from 'got';
import WhmcsApi from '..';
import { WhmcsSetupOptions } from '../interface/whmcs.setup.options';

export abstract class BaseModule {

async request(methodName: string, options?: any): Promise<any> {
options.identifier = WhmcsApi.options.identifier;
options.secret = WhmcsApi.options.secret;
constructor(private readonly options: WhmcsSetupOptions) { }

protected async request(methodName: string, options?: any): Promise<any> {
options.identifier = this.options.identifier;
options.secret = this.options.secret;
options.action = methodName;
options.responsetype = 'json';

return new Promise(async (resolve, reject) => {
const res = await got(WhmcsApi.options.apiUrl, {
const res = await got(this.options.apiUrl, {
method: 'post',
form: options
});
Expand Down
4 changes: 2 additions & 2 deletions src/module/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { UpdateTransactionRequest, UpdateTransactionResponse } from "../interfac

export class WhmcsBillingService extends BaseModule {

public async acceptQuote(options: AcceptQuoteRequest): Promise <AcceptQuoteResponse > {
public async acceptQuote(options: AcceptQuoteRequest): Promise<AcceptQuoteResponse> {
return this.request('AcceptQuote', options);
}

Expand Down Expand Up @@ -101,7 +101,7 @@ export class WhmcsBillingService extends BaseModule {
public async getTransactions(options: GetTransactionsRequest): Promise<GetTransactionsResponse> {
return this.request('GetTransactions', options);
}

public async sendQuote(options: SendQuoteRequest): Promise<SendQuoteResponse> {
return this.request('SendQuote', options);
}
Expand Down

0 comments on commit faf907b

Please sign in to comment.