-
Notifications
You must be signed in to change notification settings - Fork 2
/
openhim.js
59 lines (56 loc) · 1.61 KB
/
openhim.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
56
57
58
59
'use strict'
const request = require('request')
const utils = require('openhim-mediator-utils')
module.exports = (ohmOpts) => {
return {
fetchChannelByName: (name, callback) => {
utils.authenticate(ohmOpts, () => {
const options = {
url: `${ohmOpts.apiURL}/channels`,
headers: utils.genAuthHeaders(ohmOpts),
json: true
}
request.get(options, (err, res, channels) => {
if (err) { return callback(err) }
let channel = null
channels.forEach((c) => {
if (c.name === name) { channel = c }
})
if (channel) {
callback(null, channel)
} else {
callback(new Error('Could not find channel in result set'))
}
})
})
},
updateChannel: (_id, channel, callback) => {
utils.authenticate(ohmOpts, () => {
const options = {
url: `${ohmOpts.apiURL}/channels/${_id}`,
headers: utils.genAuthHeaders(ohmOpts),
body: channel,
json: true
}
request.put(options, (err, res) => {
if (err) { return callback(err) }
callback()
})
})
},
updateConfig: (urn, config_update, callback) => {
utils.authenticate(ohmOpts, () => {
const options = {
url: `${ohmOpts.apiURL}/mediators/${urn}/config`,
headers: utils.genAuthHeaders(ohmOpts),
body: config_update,
json: true
}
request.put(options, (err, res,body) => {
if (err) { return callback(err) }
callback()
})
})
}
}
}