Przeglądaj źródła

change module for request

yusuketk 7 lat temu
rodzic
commit
ebc9ed85e4
3 zmienionych plików z 15 dodań i 15 usunięć
  1. 13 14
      lib/util/restQiitaAPI.js
  2. 1 0
      package.json
  3. 1 1
      yarn.lock

+ 13 - 14
lib/util/restQiitaAPI.js

@@ -4,13 +4,12 @@
 
 module.exports = function(Team, Token) {
   var restQiitaAPI = {};
-  const https = require('https');
+  const request = require('request');
   const team = Team;
   const token = Token;
 
   var options = {
-    protocol: 'https:',
-    host: `${team}.qiita.com`,
+    url: `https://${team}.qiita.com`,
     method: 'GET',
     headers: {
       'Content-Type': 'application/json',
@@ -20,19 +19,19 @@ module.exports = function(Team, Token) {
 
   function restAPI(path, options) {
     return new Promise((resolve, reject) => {
-      options.path = `/api/v2/${path}`;
-      const req = https.request(options, (res) => {
+      options.url = `${options.url}/api/v2/${path}`;
+      // const req = https.request(options, (res) => {
+      //   const total = res.headers['total-count'];
+      //   res.on('data', (chunk) => {
+      //     resolve([chunk, total]);
+      //   });
+      request(options, function(err, res, body) {
+        if (err) {
+          return console.error('upload failed:', err);
+        }
         const total = res.headers['total-count'];
-        res.on('data', (chunk) => {
-          resolve([chunk, total]);
-        });
-      });
-
-      req.on('error', (e) => {
-        console.error(`problem with request: ${e.message}`);
+        resolve([body, total]);
       });
-
-      req.end();
     });
   };
 

+ 1 - 0
package.json

@@ -103,6 +103,7 @@
     "passport-google-auth": "^1.0.2",
     "passport-ldapauth": "^2.0.0",
     "passport-local": "^1.0.0",
+    "request": "^2.87.0",
     "rimraf": "^2.6.1",
     "slack-node": "^0.1.8",
     "socket.io": "^2.0.3",

+ 1 - 1
yarn.lock

@@ -7349,7 +7349,7 @@ request@2.81.0:
     tunnel-agent "^0.6.0"
     uuid "^3.0.0"
 
-request@^2.72.0:
+request@^2.72.0, request@^2.87.0:
   version "2.87.0"
   resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e"
   dependencies: