-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclientimpl_template.js
55 lines (45 loc) · 1.57 KB
/
clientimpl_template.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Template implementation.
const moment = require('moment')
const formatPayload = payload => {
// Add custom payload formatting logic here. To see what's
// in payload, simply console.log it here.
return payload
}
const buildAPIURL = (config, payload) => {
// Add custom API URL creation logic here. Has access
// to the config.json file through 'config', and the
// results of calling formatPayload on the message payload
// through 'payload'. This can access any value in config.json
// as config.<name>. To see what's in payload, simply
// console.log it here.
return config.http.apiUrl
}
const buildAPIHeaders = (config, payload) => {
// Returns an object describing HTTP headers to be
// added when calling the API URL returned by
// buildAPIURL. If none are required, simply return
// an empty object. Has access to the config.json
// file through 'config', and the results of calling
// formatPayload on the message payload through 'payload'.
// Example:
// { 'x-some-header-name': 'secretpassword' }
return {}
}
const getAPIVerb = () => {
// Should return 'POST' or 'PUT'. This is the HTTP
// verb that will be used when calling the API.
return 'POST'
}
const onMeterReadFail = (meterSerialNumber) => {
// Called whenever a meter reading fails due to a
// message not being received after the configurable
// number of retries has been reached.
console.log(`Meter reading failed for meter ${meterSerialNumber}`)
}
module.exports = {
formatPayload,
buildAPIURL,
buildAPIHeaders,
getAPIVerb,
onMeterReadFail
}