Skip to content

Commit 7b80e0e

Browse files
authored
Merge pull request #1 from dubesar/master
2 parents 876993b + 9e69617 commit 7b80e0e

File tree

3 files changed

+6
-65
lines changed

3 files changed

+6
-65
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") {

lib/config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module.exports = {
2-
httpApiVersionPath:
3-
"https://downloads.lambdatest.com/npm/api/supported_versions.json",
2+
version: {"latestVersion": "v1", "supportedVersions": ["v1"]},
43
baseUrl: "https://api.lambdatest.com/automation/api/"
54
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/node-rest-client",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "LambdaTest Rest Client for Node.js",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)