Browse Source

fix error

yusuketk 7 years ago
parent
commit
c6faae08c0
1 changed files with 4 additions and 5 deletions
  1. 4 5
      lib/util/restQiitaAPI.js

+ 4 - 5
lib/util/restQiitaAPI.js

@@ -9,7 +9,6 @@ module.exports = function(Team, Token) {
   const token = Token;
   const token = Token;
 
 
   var options = {
   var options = {
-    url: `https://${team}.qiita.com`,
     method: 'GET',
     method: 'GET',
     headers: {
     headers: {
       'Content-Type': 'application/json',
       'Content-Type': 'application/json',
@@ -17,9 +16,9 @@ module.exports = function(Team, Token) {
     }
     }
   };
   };
 
 
-  function restAPI(path, options) {
+  function restAPI(path, team, options) {
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
-      options.url = `${options.url}/api/v2/${path}`;
+      options.url = `https://${team}.qiita.com/api/v2/${path}`;
       request(options, function(err, res, body) {
       request(options, function(err, res, body) {
         if (err) {
         if (err) {
           return console.error('upload failed:', err);
           return console.error('upload failed:', err);
@@ -32,7 +31,7 @@ module.exports = function(Team, Token) {
 
 
   restQiitaAPI.getQiitaUser = function() {
   restQiitaAPI.getQiitaUser = function() {
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
-      restAPI('users', options)
+      restAPI('users', team, options)
       .then(function(res){
       .then(function(res){
         return JSON.parse(res[0].toString());
         return JSON.parse(res[0].toString());
       })
       })
@@ -52,7 +51,7 @@ module.exports = function(Team, Token) {
 
 
   restQiitaAPI.getQiitaPages = function(pageNum) {
   restQiitaAPI.getQiitaPages = function(pageNum) {
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
-      restAPI(`items?page=${pageNum}&per_page=100`, options)
+      restAPI(`items?page=${pageNum}&per_page=100`, team, options)
       .then(function(res) {
       .then(function(res) {
         const pages = JSON.parse(res[0].toString());
         const pages = JSON.parse(res[0].toString());
         const total = res[1];
         const total = res[1];