Skip to content

Commit 11c502c

Browse files
author
Usman Liaqat
committed
Use JSON.stringify to convert JSON to string
1 parent dd2c94d commit 11c502c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Diff for: IPGeolocationAPI.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,17 @@ module.exports = class IPGeolocationAPI {
2525
}
2626

2727
getUserAgent(callback, uaString ="") {
28-
var jsonData = "{\"uaString\":\"" + uaString + "\"}";
28+
var jsonData = JSON.stringify({
29+
"uaString": uaString
30+
});
31+
2932
postRequest('user-agent', "apiKey=" + this.apiKey, jsonData, callback);
3033
}
3134

3235
getBulkUserAgent(callback, uaStrings = []) {
33-
var jsonData = "{\"uaStrings\":[";
34-
for(let i = 0; i < uaStrings.length; i++){
35-
if(i === 0){
36-
jsonData = jsonData.concat("\"" + uaStrings[i] + "\"");
37-
} else{
38-
jsonData = jsonData.concat(",");
39-
jsonData = jsonData.concat("\"" + uaStrings[i] + "\"");
40-
}
41-
}
42-
jsonData = jsonData.concat("]}");
36+
var jsonData = JSON.stringify({
37+
"uaStrings": uaStrings
38+
});
4339

4440
postRequest('user-agent-bulk', "apiKey=" + this.apiKey, jsonData, callback);
4541
}
@@ -96,6 +92,7 @@ function buildGeolocationUrlParams(apiKey = '', geolocationParams = null) {
9692
if (geolocationParams.isIncludeHostname() || geolocationParams.isIncludeHostnameFallbackLive() || geolocationParams.isIncludeLiveHostname() || geolocationParams.isIncludeSecurity() || geolocationParams.isIncludeUserAgent()) {
9793
var val = "";
9894
var includeHost = false;
95+
9996
if (geolocationParams.isIncludeHostname()) {
10097
val = "hostname";
10198
includeHost = true;
@@ -106,28 +103,33 @@ function buildGeolocationUrlParams(apiKey = '', geolocationParams = null) {
106103
val = "liveHostname";
107104
includeHost = true;
108105
}
106+
109107
if (geolocationParams.isIncludeSecurity()) {
110108
if (includeHost) {
111109
val = val + ",security";
112110
} else {
113111
val = "security";
114112
}
115113
}
114+
116115
if (geolocationParams.isIncludeUserAgent()) {
117116
if (includeHost || geolocationParams.isIncludeSecurity()) {
118117
val = val + ",useragent";
119118
} else {
120119
val = "useragent";
121120
}
122121
}
122+
123123
if (urlParams) {
124124
urlParams = urlParams.concat('&');
125125
}
126+
126127
urlParams = urlParams.concat('include=', val);
127128

128129
}
129130

130131
}
132+
131133
return urlParams;
132134
}
133135

@@ -167,6 +169,7 @@ function buildTimezoneUrlParams(apiKey = '', timezoneParams = null) {
167169
if (urlParams) {
168170
urlParams = urlParams.concat('&');
169171
}
172+
170173
urlParams = urlParams.concat('lat=', timezoneParams.getLatitude(), '&long=', timezoneParams.getLongitude());
171174
}
172175

0 commit comments

Comments
 (0)