|
|
@@ -4,11 +4,10 @@
|
|
|
|
|
|
const https = require('https');
|
|
|
const team = 'team';
|
|
|
-const token = 'API token';
|
|
|
-const options = {
|
|
|
+const token = 'api token';
|
|
|
+var options = {
|
|
|
protocol: 'https:',
|
|
|
host: `${team}.qiita.com`,
|
|
|
- path: '/api/v2/items',
|
|
|
method: 'GET',
|
|
|
headers: {
|
|
|
'Content-Type': 'application/json',
|
|
|
@@ -16,17 +15,22 @@ const options = {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-const req = https.request(options, (res) => {
|
|
|
- res.on('data', (chunk) => {
|
|
|
- console.log(`BODY: ${chunk}`);
|
|
|
- });
|
|
|
- res.on('end', () => {
|
|
|
- console.log('No more data in response.');
|
|
|
- });
|
|
|
-})
|
|
|
+function restAPI(path) {
|
|
|
+ options.path = `/api/v2/${path}`;
|
|
|
+ const req = https.request(options, (res) => {
|
|
|
+ res.on('data', (chunk) => {
|
|
|
+ console.log(`BODY: ${chunk}`);
|
|
|
+ return chunk;
|
|
|
+ });
|
|
|
+ })
|
|
|
|
|
|
-req.on('error', (e) => {
|
|
|
- console.error(`problem with request: ${e.message}`);
|
|
|
-});
|
|
|
+ req.on('error', (e) => {
|
|
|
+ console.error(`problem with request: ${e.message}`);
|
|
|
+ });
|
|
|
|
|
|
-req.end();
|
|
|
+ req.end();
|
|
|
+};
|
|
|
+
|
|
|
+return {
|
|
|
+ items: restAPI('items')
|
|
|
+}
|