Skip to content

Commit bb1023d

Browse files
committed
Issue 1.2.5
1 parent e8fb8ed commit bb1023d

14 files changed

+189
-80
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ $(function() {
4141
$('#result').html(JSON.stringify(handlerResponse, null, 2));
4242
});
4343
});
44+
45+
$(function() {
46+
var clientSettings = {
47+
URL: "https://apiserver.com",
48+
secureKey: 'ServiceSecureKey'
49+
}
50+
client = new MicroserviceClient(clientSettings);
51+
client.search('endpoint', {}, function(err, handlerResponse){
52+
if(err){
53+
return $('#result').html(err);
54+
}
55+
$('#result').html(JSON.stringify(handlerResponse, null, 2));
56+
});
57+
});
4458
</script>
4559
```
4660

@@ -96,3 +110,9 @@ client.post({
96110
});
97111

98112
```
113+
114+
## Changelog
115+
- 1.2.5
116+
- added nodejs package name to UserAgent
117+
- fixed URL variable
118+
- added support for API based requests
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<html>
2+
<head>
3+
<script src="http://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
4+
<script src="../microservice-client.js"></script>
5+
<script>
6+
$(function() {
7+
var clientSettings = {
8+
URL: "https://apiserver.com",
9+
accessToken: 'AccessToken'
10+
}
11+
client = new MicroserviceClient(clientSettings);
12+
client.search('endpoint', {query:{},limit: 10}, function(err, handlerResponse, headers){
13+
console.log(headers);
14+
if(err){
15+
return $('#result').html(err);
16+
}
17+
$('#result').html(JSON.stringify(handlerResponse, null, 2));
18+
client.get('endpoint/' + handlerResponse[0].id, function(err, handlerResponse, headers){
19+
console.log(headers);
20+
if(err){
21+
return $('#result').html(err);
22+
}
23+
$('#result').html(JSON.stringify(handlerResponse, null, 2));
24+
});
25+
});
26+
});
27+
</script>
28+
</head>
29+
<body>
30+
<pre id="result"></pre>
31+
</body>
32+
</html>

examples/browser-example-client.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<script>
66
$(function() {
77
var clientSettings = {
8-
URL: "https://apiserver.com/service",
9-
secureKey: 'ServiceSecureKey'
8+
URL: "https://project.zen.ci/api/v1/owners",
9+
secureKey: '983a71ab650893a38554a7bed5bc69ce3d7585a4'
1010
}
1111
client = new MicroserviceClient(clientSettings);
1212
client.search({query:{},limit: 10}, function(err, handlerResponse, headers){

includes/websocket.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ MicroserviceWebSocket.prototype.get = function(EndPoint, RecordID, token, callba
173173
EndPoint: EndPoint,
174174
}
175175

176-
if (arguments.length === 2) {
176+
if (arguments.length === 3) {
177177
callback = token;
178178
} else {
179179
statusRequest.RecordToken = token;
@@ -197,7 +197,7 @@ MicroserviceWebSocket.prototype.delete = function(EndPoint, RecordID, token, cal
197197
EndPoint: EndPoint,
198198
}
199199

200-
if (arguments.length === 2) {
200+
if (arguments.length === 3) {
201201
callback = token;
202202
} else {
203203
statusRequest.RecordToken = token;
@@ -270,7 +270,7 @@ MicroserviceWebSocket.prototype.put = function(EndPoint, RecordID, token, data,
270270
EndPoint: EndPoint,
271271
}
272272

273-
if (arguments.length === 3) {
273+
if (arguments.length === 4) {
274274
callback = data;
275275
data = token
276276
} else {

index.js

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const bind = function(fn, me) { return function() { return fn.apply(me, argument
1111
/**
1212
* Constructor of MicroserviceClientClient object.
1313
* .
14-
* settings.URL = process.env.MONGO_URL;
14+
* settings.URL = process.env.SELF_URL;
1515
* settings.secureKey = process.env.SECURE_KEY;
1616
* settings.accessToken = if microservice-auth used, accessToken can be set here.
1717
*/
@@ -46,9 +46,6 @@ MicroserviceClient.prototype._request = function(statusRequest, callback) {
4646
var self = this;
4747

4848
var signatureMethods = ['PUT', 'SEARCH', 'PATCH', 'POST', 'OPTIONS'];
49-
var recordMethods = ['PUT', 'PATCH', 'GET', 'DELETE' ];
50-
51-
var url = self.settings.URL;
5249

5350
var requestData = statusRequest.Request;
5451

@@ -64,7 +61,8 @@ MicroserviceClient.prototype._request = function(statusRequest, callback) {
6461

6562
// If we are running under node, set version User-agent.
6663
if (process.env.npm_package_version) {
67-
headers['User-Agent'] = 'MicroserviceClient.' + process.env.npm_package_version;
64+
headers['User-Agent'] = 'MicroserviceClient.' + process.env.npm_package_name
65+
+ '.' + process.env.npm_package_version;
6866
};
6967

7068
if (self.settings.accessToken) {
@@ -81,17 +79,19 @@ MicroserviceClient.prototype._request = function(statusRequest, callback) {
8179
}
8280
}
8381
}
82+
var url = self.settings.URL;
83+
if (url.slice(-1) == '/') {
84+
url = url.substring(0, url.length - 1);
85+
}
8486

85-
if (recordMethods.indexOf(statusRequest.method) > -1) {
86-
if (statusRequest.RecordID) {
87-
var url = self.settings.URL;
88-
if (self.settings.URL.slice(-1) == '/') {
89-
url = url + statusRequest.RecordID;
90-
} else {
91-
url = self.settings.URL + '/' + statusRequest.RecordID;
92-
}
93-
}
87+
if (statusRequest.EndPoint) {
88+
url = url + '/' + statusRequest.EndPoint;
89+
}
90+
91+
if (statusRequest.RecordID) {
92+
url = url + '/' + statusRequest.RecordID;
9493
}
94+
9595
var requestQuery = {
9696
url: url,
9797
method: statusRequest.method,
@@ -166,12 +166,19 @@ MicroserviceClient.prototype.delete = function(RecordID, token, callback) {
166166
* @param {object} data - values that need to be updated.
167167
* @param {function} callback - return result to callback function
168168
*/
169-
MicroserviceClient.prototype.search = function(data, callback) {
169+
MicroserviceClient.prototype.search = function(EndPoint, data, callback) {
170170
var self = this;
171+
if (arguments.length === 2) {
172+
callback = data;
173+
data = EndPoint;
174+
EndPoint = false;
175+
}
171176
var statusRequest = {
172177
method: 'SEARCH',
173-
Request: data
178+
Request: data,
179+
EndPoint: EndPoint,
174180
}
181+
175182
return self._request(statusRequest, callback);
176183
}
177184

@@ -181,11 +188,17 @@ MicroserviceClient.prototype.search = function(data, callback) {
181188
* @param {object} data - object with document to create.
182189
* @param {function} callback - return result to callback function
183190
*/
184-
MicroserviceClient.prototype.post = function(data, callback) {
191+
MicroserviceClient.prototype.post = function(EndPoint, data, callback) {
185192
var self = this;
193+
if (arguments.length === 2) {
194+
callback = data;
195+
data = EndPoint;
196+
EndPoint = false;
197+
}
186198
var statusRequest = {
187199
method: 'POST',
188-
Request: data
200+
Request: data,
201+
EndPoint: EndPoint,
189202
}
190203
return self._request(statusRequest, callback);
191204
}
@@ -196,11 +209,17 @@ MicroserviceClient.prototype.post = function(data, callback) {
196209
* @param {object} data - ignored. For future use.
197210
* @param {function} callback - return result to callback function
198211
*/
199-
MicroserviceClient.prototype.options = function(data, callback) {
212+
MicroserviceClient.prototype.options = function(EndPoint, data, callback) {
200213
var self = this;
214+
if (arguments.length === 2) {
215+
callback = data;
216+
data = EndPoint;
217+
EndPoint = false;
218+
}
201219
var statusRequest = {
202220
method: 'OPTIONS',
203-
Request: data
221+
Request: data,
222+
EndPoint: EndPoint,
204223
}
205224
return self._request(statusRequest, callback);
206225
}

microservice-all.js

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ MicroserviceWebSocket.prototype.get = function(EndPoint, RecordID, token, callba
280280
EndPoint: EndPoint,
281281
}
282282

283-
if (arguments.length === 2) {
283+
if (arguments.length === 3) {
284284
callback = token;
285285
} else {
286286
statusRequest.RecordToken = token;
@@ -304,7 +304,7 @@ MicroserviceWebSocket.prototype.delete = function(EndPoint, RecordID, token, cal
304304
EndPoint: EndPoint,
305305
}
306306

307-
if (arguments.length === 2) {
307+
if (arguments.length === 3) {
308308
callback = token;
309309
} else {
310310
statusRequest.RecordToken = token;
@@ -377,7 +377,7 @@ MicroserviceWebSocket.prototype.put = function(EndPoint, RecordID, token, data,
377377
EndPoint: EndPoint,
378378
}
379379

380-
if (arguments.length === 3) {
380+
if (arguments.length === 4) {
381381
callback = data;
382382
data = token
383383
} else {
@@ -406,7 +406,7 @@ const bind = function(fn, me) { return function() { return fn.apply(me, argument
406406
/**
407407
* Constructor of MicroserviceClientClient object.
408408
* .
409-
* settings.URL = process.env.MONGO_URL;
409+
* settings.URL = process.env.SELF_URL;
410410
* settings.secureKey = process.env.SECURE_KEY;
411411
* settings.accessToken = if microservice-auth used, accessToken can be set here.
412412
*/
@@ -441,9 +441,6 @@ MicroserviceClient.prototype._request = function(statusRequest, callback) {
441441
var self = this;
442442

443443
var signatureMethods = ['PUT', 'SEARCH', 'PATCH', 'POST', 'OPTIONS'];
444-
var recordMethods = ['PUT', 'PATCH', 'GET', 'DELETE' ];
445-
446-
var url = self.settings.URL;
447444

448445
var requestData = statusRequest.Request;
449446

@@ -459,7 +456,8 @@ MicroserviceClient.prototype._request = function(statusRequest, callback) {
459456

460457
// If we are running under node, set version User-agent.
461458
if (process.env.npm_package_version) {
462-
headers['User-Agent'] = 'MicroserviceClient.' + process.env.npm_package_version;
459+
headers['User-Agent'] = 'MicroserviceClient.' + process.env.npm_package_name
460+
+ '.' + process.env.npm_package_version;
463461
};
464462

465463
if (self.settings.accessToken) {
@@ -476,17 +474,19 @@ MicroserviceClient.prototype._request = function(statusRequest, callback) {
476474
}
477475
}
478476
}
477+
var url = self.settings.URL;
478+
if (url.slice(-1) == '/') {
479+
url = url.substring(0, url.length - 1);
480+
}
479481

480-
if (recordMethods.indexOf(statusRequest.method) > -1) {
481-
if (statusRequest.RecordID) {
482-
var url = self.settings.URL;
483-
if (self.settings.URL.slice(-1) == '/') {
484-
url = url + statusRequest.RecordID;
485-
} else {
486-
url = self.settings.URL + '/' + statusRequest.RecordID;
487-
}
488-
}
482+
if (statusRequest.EndPoint) {
483+
url = url + '/' + statusRequest.EndPoint;
489484
}
485+
486+
if (statusRequest.RecordID) {
487+
url = url + '/' + statusRequest.RecordID;
488+
}
489+
490490
var requestQuery = {
491491
url: url,
492492
method: statusRequest.method,
@@ -561,12 +561,19 @@ MicroserviceClient.prototype.delete = function(RecordID, token, callback) {
561561
* @param {object} data - values that need to be updated.
562562
* @param {function} callback - return result to callback function
563563
*/
564-
MicroserviceClient.prototype.search = function(data, callback) {
564+
MicroserviceClient.prototype.search = function(EndPoint, data, callback) {
565565
var self = this;
566+
if (arguments.length === 2) {
567+
callback = data;
568+
data = EndPoint;
569+
EndPoint = false;
570+
}
566571
var statusRequest = {
567572
method: 'SEARCH',
568-
Request: data
573+
Request: data,
574+
EndPoint: EndPoint,
569575
}
576+
570577
return self._request(statusRequest, callback);
571578
}
572579

@@ -576,11 +583,17 @@ MicroserviceClient.prototype.search = function(data, callback) {
576583
* @param {object} data - object with document to create.
577584
* @param {function} callback - return result to callback function
578585
*/
579-
MicroserviceClient.prototype.post = function(data, callback) {
586+
MicroserviceClient.prototype.post = function(EndPoint, data, callback) {
580587
var self = this;
588+
if (arguments.length === 2) {
589+
callback = data;
590+
data = EndPoint;
591+
EndPoint = false;
592+
}
581593
var statusRequest = {
582594
method: 'POST',
583-
Request: data
595+
Request: data,
596+
EndPoint: EndPoint,
584597
}
585598
return self._request(statusRequest, callback);
586599
}
@@ -591,11 +604,17 @@ MicroserviceClient.prototype.post = function(data, callback) {
591604
* @param {object} data - ignored. For future use.
592605
* @param {function} callback - return result to callback function
593606
*/
594-
MicroserviceClient.prototype.options = function(data, callback) {
607+
MicroserviceClient.prototype.options = function(EndPoint, data, callback) {
595608
var self = this;
609+
if (arguments.length === 2) {
610+
callback = data;
611+
data = EndPoint;
612+
EndPoint = false;
613+
}
596614
var statusRequest = {
597615
method: 'OPTIONS',
598-
Request: data
616+
Request: data,
617+
EndPoint: EndPoint,
599618
}
600619
return self._request(statusRequest, callback);
601620
}

microservice-all.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

microservice-all.min.map

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

0 commit comments

Comments
 (0)