UNPKG

1.08 kBJavaScriptView Raw
1const ora = require('ora');
2const request = require('request');
3const authorisify = require('../lib/authorisify');
4const config = require('../config/config.json');
5
6const LINC_API_HELLO_ENDPOINT = `${config.Api.LincBaseEndpoint}/hello`;
7
8/**
9 * Handle hello
10 */
11const 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
30exports.command = ['hello'];
31exports.desc = false;
32exports.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};