binhend 2.1.19 → 2.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/https.js +76 -79
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "2.1.19",
3
+ "version": "2.1.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
package/src/https.js CHANGED
@@ -5,90 +5,87 @@ const https = require('https');
5
5
  function HTTPS(url) {
6
6
  this.url = url;
7
7
  this.parameters = [];
8
- };
9
-
10
- var prototype = HTTPS.prototype;
11
-
12
- prototype.get = function(callback) {
13
- return this.request('GET', callback);
14
- }
15
-
16
- prototype.post = function(callback) {
17
- return this.request('POST', callback);
18
- }
19
-
20
- prototype.request = function(method, callback) {
21
-
22
- var URL = this.url + this.parameters.join('/') + (this.queries || '');
23
8
 
24
- var options = {
25
- method,
26
- headers: this.headers
27
- };
28
-
29
- var req = https.request(URL, options, function(res) {
30
- res.setEncoding('utf8');
31
-
32
- var data = '';
33
-
34
- res.on('data', (chunk) => {
35
- data += chunk;
9
+ this.get = function(callback) {
10
+ return this.request('GET', callback);
11
+ }
12
+
13
+ this.post = function(callback) {
14
+ return this.request('POST', callback);
15
+ }
16
+
17
+ this.request = function(method, callback) {
18
+ var URL = this.url + this.parameters.join('/') + (this.queries || '');
19
+
20
+ var options = {
21
+ method,
22
+ headers: this.headers
23
+ };
24
+
25
+ var req = https.request(URL, options, function(res) {
26
+ res.setEncoding('utf8');
27
+
28
+ var data = '';
29
+
30
+ res.on('data', (chunk) => {
31
+ data += chunk;
32
+ });
33
+
34
+ res.on('end', () => {
35
+ var response;
36
+
37
+ try {
38
+ response = JSON.parse(data);
39
+ }
40
+ catch(error) {
41
+ response = data;
42
+ }
43
+
44
+ if (callback instanceof Function) {
45
+ callback(response);
46
+ }
47
+ });
36
48
  });
37
-
38
- res.on('end', () => {
39
- var response;
40
-
41
- try {
42
- response = JSON.parse(data);
43
- }
44
- catch(error) {
45
- response = data;
46
- }
47
-
48
- if (callback instanceof Function) {
49
- callback(response);
50
- }
49
+
50
+ req.on("error", (err) => {
51
+ console.log("HTTPS request encounters error:" + err.message);
51
52
  });
52
- });
53
-
54
- req.on("error", (err) => {
55
- console.log("HTTPS request encounters error:" + err.message);
56
- });
57
-
58
- if (this.payload) {
59
- req.write(JSON.stringify(this.payload));
53
+
54
+ if (this.payload) {
55
+ req.write(JSON.stringify(this.payload));
56
+ }
57
+
58
+ req.end();
59
+
60
+ return this;
60
61
  }
61
-
62
- req.end();
63
-
64
- return this;
65
- }
66
-
67
- prototype.header = function(map) {
68
- this.headers = map;
69
- return this;
70
- }
71
-
72
- prototype.body = function(map) {
73
- this.payload = JSON.stringify(map);
74
- return this;
75
- }
76
-
77
- prototype.parameter = function(array) {
78
- if (array instanceof Array) {
79
- var last_char = this.url[this.url.length - 1];
80
- this.parameters = (last_char === '/' ? [] : ['']).concat(array);
62
+
63
+ this.header = function(map) {
64
+ this.headers = map;
65
+ return this;
81
66
  }
82
- return this;
83
- }
84
-
85
- prototype.query = function(map) {
86
- var query_string = '';
87
- for (var key in map) {
88
- query_string += key + '=' + map[key] + '&';
67
+
68
+ this.body = function(map) {
69
+ this.payload = JSON.stringify(map);
70
+ return this;
89
71
  }
90
- this.queries = '?' + query_string;
91
- return this;
92
- }
72
+
73
+ this.parameter = function(array) {
74
+ if (array instanceof Array) {
75
+ var last_char = this.url[this.url.length - 1];
76
+ this.parameters = (last_char === '/' ? [] : ['']).concat(array);
77
+ }
78
+ return this;
79
+ }
80
+
81
+ this.query = function(map) {
82
+ var query_string = '';
83
+ for (var key in map) {
84
+ query_string += key + '=' + map[key] + '&';
85
+ }
86
+ this.queries = '?' + query_string;
87
+ return this;
88
+ }
89
+ };
93
90
 
94
91
  module.exports = { HTTPS };