1 | const ora = require('ora');
|
2 | const request = require('request');
|
3 | const authorisify = require('../lib/authorisify');
|
4 | const config = require('../config/config.json');
|
5 |
|
6 | const LINC_API_HELLO_ENDPOINT = `${config.Api.LincBaseEndpoint}/hello`;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const hello = () => (jwtToken) => new Promise((resolve, reject) => {
|
12 | const options = {
|
13 | method: 'GET',
|
14 | url: LINC_API_HELLO_ENDPOINT,
|
15 | headers: {
|
16 | 'Content-Type': 'application/json',
|
17 | Authorization: `X-Bearer ${jwtToken}`,
|
18 | },
|
19 | };
|
20 | request(options, (err, response, body) => {
|
21 | if (!err && response.statusCode === 200) {
|
22 | const obj = JSON.parse(body);
|
23 | return resolve(obj);
|
24 | }
|
25 |
|
26 | return reject(err);
|
27 | });
|
28 | });
|
29 |
|
30 | exports.command = ['hello'];
|
31 | exports.desc = false;
|
32 | exports.handler = () => {
|
33 | const spinner = ora('Please wait...').start();
|
34 |
|
35 | authorisify(hello())
|
36 | .then(body => spinner.succeed(`${body.response}\n`))
|
37 | .catch(err => spinner.fail(`Error: ${err.message ? err.message : err}`));
|
38 | };
|