-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
43 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
dist | ||
dist | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |