-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (45 loc) · 882 Bytes
/
index.js
File metadata and controls
48 lines (45 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const request = require('request');
/**
* This is a simple jim-workflow that prints a random dadjoke to the console
*/
module.exports = class JimDadjoke {
/**
* Kick things off
*
* @param {Object} jim The jim-object
*/
constructor(jim) {
this.headers = {
'User-Agent': 'jim',
Accept: 'application/json',
};
this.api = 'https://icanhazdadjoke.com';
this.jim = jim;
}
/**
* The jim-run method.
*/
run() {
request(
{
url: this.api,
headers: this.headers,
},
(error, response, body) => {
if (!error && response.statusCode === 200) {
this._displayJoke(body);
} else {
this.jim.Logger.error(error);
}
}
);
}
/**
* Prints the joke to the console
* @param {String} _jokeData the API response
*/
_displayJoke(_jokeData) {
const data = JSON.parse(_jokeData);
this.jim.Logger.log(data.joke);
}
};