Skip to content

Commit

Permalink
Merge branch 'gitlab-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHawkinss committed Nov 8, 2023
2 parents 57a71be + 54abb44 commit 6329186
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
dist
.idea/
38 changes: 22 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,31 @@ import { WhmcsSupportService } from "./module/support";
import { WhmcsSystemService } from "./module/system";
import { WhmcsTicketsService } from "./module/tickets";
import { WhmcsUsersService } from "./module/users";
import { WhmcsClientCustom } from "./module/custom";

export default class WhmcsApi {

constructor(private readonly options: WhmcsSetupOptions) { }

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

export abstract class BaseModule {

constructor(private readonly options: WhmcsSetupOptions) { }

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

return new Promise(async (resolve, reject) => {
try {
const res = await got(this.options.apiUrl, {
method: 'post',
form: options
const res = await got(WhmcsApi.options.apiUrl, {
method: "post",
form: options,
});

const data = JSON.parse(res.body);

if (data.result != "success") return reject(data);
resolve(data);
} catch (error) {
reject(error);
}
});
}
}
}
7 changes: 7 additions & 0 deletions src/module/custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {BaseModule} from "./base";

export class WhmcsClientCustom extends BaseModule {
public async call<T>(method: string, options: Record<string, unknown>): Promise<T> {
return this.request(method, options);
}
}

0 comments on commit 6329186

Please sign in to comment.