Skip to content

Commit 35a6763

Browse files
authored
Update api_client.js
1 parent 876993b commit 35a6763

File tree

1 file changed

+4
-62
lines changed

1 file changed

+4
-62
lines changed

lib/api_client.js

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,9 @@
1+
const { version, baseUrl } = require("./config");
2+
13
var request = require("request"),
24
logger,
3-
Config = require("./config"),
45
packageVersion = require("../../package.json").version;
56

6-
/**
7-
* Operates on an instance of ApiClient and returns latest version and list of supported versions.
8-
* @param {!AutomationApiClient} settings An object that for lambda user credentials
9-
* explanation that spans multiple lines.
10-
* @param {number} retries for max attemt to fetch
11-
* @param {Function} fnCallback is callback function.
12-
* @return {Function|Error} return version that is supported by lambdaTest Rest Client e.g. v1, v2 etc.
13-
*/
14-
var fetchApiVersions_ = function(settings, retries, fnCallback) {
15-
/** Check left retries */
16-
if (retries >= 0) {
17-
request(Config.httpApiVersionPath, function(e, response, body) {
18-
if (e) {
19-
logger.error("Error while fetching version from server path ", e);
20-
fetchApiVersions_(settings, retries - 1, fnCallback);
21-
} else {
22-
/** use try-catch Possibly Error due to json parse of non-parseable */
23-
try {
24-
body = JSON.parse(body);
25-
/** Check for supportedVersions list is there */
26-
if (body.supportedVersions && body.supportedVersions.length) {
27-
/** Check Requester request for version and exist in supportedVersions list */
28-
if (settings.version) {
29-
if (body.supportedVersions.indexOf(settings.version) === -1) {
30-
return fnCallback(true, null);
31-
} else {
32-
return fnCallback(false, settings.version);
33-
}
34-
} else {
35-
return fnCallback(false, body.latestVersion);
36-
}
37-
} else {
38-
fetchApiVersions_(settings, retries - 1, fnCallback);
39-
}
40-
} catch (e) {
41-
logger.error(
42-
"Error while parse to json of output response of versions json path ",
43-
e
44-
);
45-
/** Re-Attemp to fetch If getting Error */
46-
fetchApiVersions_(settings, retries - 1, fnCallback);
47-
}
48-
}
49-
});
50-
} else {
51-
return fnCallback(true, null);
52-
}
53-
};
54-
557
/**
568
* ApiClient is a function based Class.
579
* @param {!AutomationApiClient} settings An object that for lambda user credentials
@@ -95,18 +47,8 @@ ApiClient.request = function(options, fnCallback) {
9547
fnCallback = fnCallback || function() {};
9648
/** Check baseUrl is on ApiClient */
9749
if (ApiClient.baseUrl === undefined) {
98-
/** Calling method for Update baseUrl and Request pass to Server for Getting Response
99-
* @return {Function|Error} return response to Callable method or throw Error.
100-
*/
101-
fetchApiVersions_(ApiClient.settings, 5, function(e, response) {
102-
if (e) {
103-
logger.error("Error while fetching Versions", e);
104-
throw new Error("Invalid Api version");
105-
} else {
106-
ApiClient.baseUrl = Config.baseUrl + response;
107-
ApiClient.request(options, fnCallback);
108-
}
109-
});
50+
ApiClient.baseUrl = baseUrl + version.latestVersion;
51+
ApiClient.request(options, fnCallback);
11052
} else {
11153
/** Update Options with User Credential If It is object */
11254
if (typeof options === "object") {

0 commit comments

Comments
 (0)