Skip to content

Commit

Permalink
feat(requests): add support for toggling checkRequestStatus option (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
samrum committed May 2, 2021
1 parent 01cf729 commit 4f75d55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/RequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class RequestService {
private config: OnStarConfig;
private authToken?: OAuthToken;
private checkRequestTimeout = 6000;
private checkRequestStatus: boolean;
private tokenRefreshPromise?: Promise<OAuthToken>;
private tokenUpgradePromise?: Promise<void>;

Expand All @@ -50,10 +51,11 @@ class RequestService {
private client: HttpClient,
) {
this.config = {
checkRequestStatus: true,
...config,
vin: config.vin.toUpperCase(),
};

this.checkRequestStatus = this.config.checkRequestStatus ?? true;
}

setClient(client: HttpClient) {
Expand All @@ -74,6 +76,12 @@ class RequestService {
return this;
}

setCheckRequestStatus(checkStatus: boolean) {
this.checkRequestStatus = checkStatus;

return this;
}

async start(): Promise<Result> {
const request = this.getCommandRequest(OnStarApiCommand.Start);

Expand Down Expand Up @@ -335,7 +343,7 @@ class RequestService {
const response = await this.makeClientRequest(request);
const { data } = response;

if (this.config.checkRequestStatus && typeof data === "object") {
if (this.checkRequestStatus && typeof data === "object") {
const { commandResponse } = data;

if (commandResponse) {
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class OnStar {
async diagnostics(options?: DiagnosticsRequestOptions): Promise<Result> {
return this.requestService.diagnostics(options);
}

setCheckRequestStatus(checkStatus: boolean) {
this.requestService.setCheckRequestStatus(checkStatus);
}
}

export default OnStar;

0 comments on commit 4f75d55

Please sign in to comment.