|
|
@@ -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();
|
|
|
});
|
|
|
};
|
|
|
|