Skip to content

Commit c93a21b

Browse files
fix(APIClient): setUserAgent returns APIClient instance now
use the returned instance for method chaining
1 parent 2199944 commit c93a21b

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

dist/apiclient.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export declare class APIClient {
1414
getPOSTData(cmd: any): string;
1515
getSession(): string | null;
1616
getURL(): string;
17-
setUserAgent(str: string, rv: string): void;
17+
setUserAgent(str: string, rv: string): APIClient;
1818
getUserAgent(): string;
1919
getVersion(): string;
2020
saveSession(session: any): APIClient;

dist/apiclient.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apiclient.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/apiclient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,16 @@ export class APIClient {
130130
* Possibility to customize default user agent to fit your needs
131131
* @param str user agent label
132132
* @param rv revision of user agent
133+
* @returns Current APIClient instance for method chaining
133134
*/
134-
public setUserAgent(str: string, rv: string) {
135+
public setUserAgent(str: string, rv: string): APIClient {
135136
this.ua = (
136137
`${str} ` +
137138
`(${process.platform}; ${process.arch}; rv:${rv}) ` +
138139
`node-sdk/${this.getVersion()} ` +
139140
`node/${process.version}`
140141
);
142+
return this;
141143
}
142144

143145
/**

test/apiclient.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ describe('APIClient class', function () {
127127

128128
describe('#.setUserAgent', function () {
129129
it('validate response', function () {
130-
cl.setUserAgent('WHMCS', '7.7.0')
130+
const cls = cl.setUserAgent('WHMCS', '7.7.0')
131131
const ua = cl.getUserAgent()
132+
expect(cls).to.be.instanceOf(apiclient.APIClient)
132133
expect(ua).to.equal(`WHMCS (${process.platform}; ${process.arch}; rv:7.7.0) node-sdk/${cl.getVersion()} node/${process.version}`)
133134
})
134135
})

0 commit comments

Comments
 (0)