Skip to content

Commit 591a519

Browse files
committed
Add path to makeApiCall
1 parent 297ac9d commit 591a519

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

dist/javascript-core.js

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

lib/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
55
});
66
exports.buildUrl = exports.makeApiCall = void 0;
77

8-
var makeApiCall = function makeApiCall(service, apiKey, params) {
9-
var url = buildUrl(service, apiKey, params);
8+
var makeApiCall = function makeApiCall(service, apiKey, params, path) {
9+
var url = buildUrl(service, apiKey, params, path);
1010
var xmlHttp = new XMLHttpRequest();
1111
return new Promise(function (resolve, reject) {
1212
xmlHttp.onreadystatechange = function () {
@@ -28,7 +28,7 @@ var makeApiCall = function makeApiCall(service, apiKey, params) {
2828

2929
exports.makeApiCall = makeApiCall;
3030

31-
var buildUrl = function buildUrl(service, apiKey, params) {
31+
var buildUrl = function buildUrl(service, apiKey, params, path) {
3232
if (!apiKey) {
3333
throw new Error('No api key is set.');
3434
}
@@ -43,7 +43,13 @@ var buildUrl = function buildUrl(service, apiKey, params) {
4343
});
4444
}
4545

46-
return "https://".concat(service, ".abstractapi.com/v1?api_key=").concat(apiKey).concat(paramString, "&lang=js");
46+
var pathString = '';
47+
48+
if (typeof path === 'string') {
49+
pathString = "/".concat(path);
50+
}
51+
52+
return "https://".concat(service, ".abstractapi.com/v1").concat(pathString, "?api_key=").concat(apiKey).concat(paramString, "&lang=js");
4753
};
4854

4955
exports.buildUrl = buildUrl;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@abstractapi/javascript-core",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "AbstractAPI Javascript Core Library - Used by the other Abstract API libraries",
55
"main": "index.js",
66
"scripts": {

src/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const makeApiCall = (service, apiKey, params) => {
2-
3-
const url = buildUrl(service, apiKey, params);
1+
const makeApiCall = (service, apiKey, params, path) => {
42

3+
const url = buildUrl(service, apiKey, params, path);
54
let xmlHttp = new XMLHttpRequest();
65
return new Promise((resolve, reject) => {
76
xmlHttp.onreadystatechange = () => {
@@ -21,7 +20,7 @@ const makeApiCall = (service, apiKey, params) => {
2120
})
2221
};
2322

24-
const buildUrl = (service, apiKey, params) => {
23+
const buildUrl = (service, apiKey, params, path) => {
2524
if (!apiKey) {
2625
throw new Error('No api key is set.')
2726
}
@@ -36,7 +35,13 @@ const buildUrl = (service, apiKey, params) => {
3635
})
3736
}
3837

39-
return`https://${service}.abstractapi.com/v1?api_key=${apiKey}${paramString}&lang=js`;
38+
let pathString = '';
39+
40+
if (typeof path === 'string') {
41+
pathString = "/".concat(path);
42+
}
43+
44+
return`https://${service}.abstractapi.com/v1${pathString}?api_key=${apiKey}${paramString}&lang=js`;
4045
}
4146

4247
export {

0 commit comments

Comments
 (0)