restQiitaAPI.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. // Qiita API v2 documant https://qiita.com/api/v2/docs
  3. const https = require('https');
  4. const team = 'team';
  5. const token = 'token';
  6. var options = {
  7. protocol: 'https:',
  8. host: `${team}.qiita.com`,
  9. method: 'GET',
  10. headers: {
  11. 'Content-Type': 'application/json',
  12. 'authorization': `Bearer ${token}`
  13. }
  14. };
  15. function restAPI(path) {
  16. options.path = `/api/v2/${path}`;
  17. const req = https.request(options, (res) => {
  18. res.on('data', (chunk) => {
  19. console.log(`${chunk}`);
  20. return chunk;
  21. });
  22. })
  23. req.on('error', (e) => {
  24. console.error(`problem with request: ${e.message}`);
  25. });
  26. req.end();
  27. };
  28. return {
  29. // tags: restAPI('tags'),
  30. // templates: restAPI('templates'),
  31. // projects: restAPI('projects'),
  32. // users: restAPI('users'),
  33. // comments: restAPI(`items/${item_id}/comments`),
  34. // project_comments: restAPI(`projects/${project_id}/comments`),
  35. // itemreactions: restAPI(`items/${item_id}/reactions`),
  36. // comment_reactions: restAPI(`comments/${comment_id}/reactions`),
  37. // project_reactions: restAPI(`projects/${project_id}/reactions`),
  38. items: restAPI('items')
  39. }