File: 0001_port_to_axios_from_request.patch

package info (click to toggle)
node-telegram-bot-api 2.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,980 kB
  • sloc: javascript: 1,333; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,901 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Description: Remove dependency to node-request
 Upstream has deprecated node-request. We port this lib to node-axios
Author: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
Bug-Debian: https://bugs.debian.org/958691
Forwarded: https://github.com/mast/telegram-bot-api/issues/77
Last-Update: 2020-11-20

Index: node-telegram-bot-api-2.0.1/lib/api.js
===================================================================
--- node-telegram-bot-api-2.0.1.orig/lib/api.js
+++ node-telegram-bot-api-2.0.1/lib/api.js
@@ -1,6 +1,6 @@
 const EventEmitter = require('events')
 const debug = require('debug')('telegram-bot-api:api')
-const request = require('request')
+const axios = require('axios')
 const stream = require('stream')
 
 class Api extends EventEmitter {
@@ -30,9 +30,7 @@ class Api extends EventEmitter {
         this._validateParameters()
 
         // Default request settings
-        this._request = request.defaults({
-            proxy: this._proxy
-        })
+        this._request = this._fakeRequest
 
         // Register Api calls
         this._registerApiCall('getMe')
@@ -115,6 +113,26 @@ class Api extends EventEmitter {
         this._registerApiCall('getGameHighScores')
     }
 
+    _fakeRequest(parameters, f) {
+	if (parameters.method == "GET") {
+	    axios.get(parameters.uri, {timeout: parameters.timeout})
+	    .then(function (body) {
+		f(null, body.request.res, JSON.stringify(body.data));
+	    })
+	    .catch(function(err){
+		f(err, null, null);
+	    })
+	} else if (parameters.method == "POST") {
+	    axios.post(parameters.uri, parameters.formData, {timeout: parameters.timeout})
+	    .then(function (body) {
+		f(null, body.request.res, JSON.stringify(body.data));
+	    })
+	    .catch(function(err){
+		f(err, null, null);
+	    })
+	}
+    }
+
     _applyParameters(parameters) {
         if (parameters.token) {
             this._token = parameters.token