-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
36 lines (32 loc) · 1.08 KB
/
node_helper.js
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
/* Magic Mirror2
* Module: GHIN
*
* By Clint Decker https://github.com/C-DECK
* MIT Licensed.
*/
var NodeHelper = require('node_helper')
var GHINApi = require('./GHINApi/GHINApi')
var Notifcations = require('./Notifications')
const SUCCESS_STATUS_CODE = 200
module.exports = NodeHelper.create({
start: function () {
console.log('MMM-GHIN: started')
},
getLoginResponse: function (data) {
console.log(data)
if (data == SUCCESS_STATUS_CODE) {
this.sendSocketNotification(Notifcations.LOGIN_SUCCESS)
} else {
this.sendSocketNotification(Notifcations.LOGIN_FAILURE)
}
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function (notification, data) {
console.log(notification)
if (notification === Notifcations.LOGIN_USER) {
GHINApi.loginUser(data.email, data.password).then((data) => this.getLoginResponse(data))
} else if (notification === Notifcations.GET_HANDICAP) {
GHINApi.searchCurrentGolfer(data).then((data) => this.sendSocketNotification(Notifcations.HANDICAP_RESULT, data))
}
},
})