Skip to content

Commit

Permalink
New: Opportunity to provide custom connection management agent for th…
Browse files Browse the repository at this point in the history
…e client
  • Loading branch information
Mantas Lapenas committed Mar 19, 2021
1 parent c36bfe2 commit 884004c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/request-helper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as rp from 'request-promise-native';
import * as http from 'http';
import * as https from 'https';

import { AccessProvider } from './access-provider';

export class RequestHelper {
constructor(private accessProvider: AccessProvider) {}
constructor(private accessProvider: AccessProvider, private agent?: http.Agent | https.Agent) {}

get basicRequest() {
const headers = this.accessProvider.trustpilotApiConfig.defaultHeaders || {};
Expand All @@ -12,6 +14,7 @@ export class RequestHelper {
baseUrl: this.accessProvider.trustpilotApiConfig.baseUrl,
headers,
json: true,
agent: this.agent,
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/trustpilot-api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { AccessProvider } from './access-provider';
import { ITrustpilotApiConfig } from './models';
import { RequestHelper } from './request-helper';
import * as http from 'http';
import * as https from 'https';

export class TrustpilotApi {
private requestHelper: RequestHelper;

constructor(config: Readonly<ITrustpilotApiConfig>) {
constructor(config: Readonly<ITrustpilotApiConfig>, agent?: http.Agent | https.Agent) {
const accessProvider = new AccessProvider(Object.freeze(config));
this.requestHelper = new RequestHelper(accessProvider);
this.requestHelper = new RequestHelper(accessProvider, agent);
}

get apiRequest() {
Expand Down

0 comments on commit 884004c

Please sign in to comment.