mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-22 17:12:03 -07:00
42 lines
809 B
JavaScript
42 lines
809 B
JavaScript
/*
|
|
The (Clean Architecture) Adapter for manageing a webhook connection to P2WDB.
|
|
*/
|
|
|
|
const config = require('../../config')
|
|
const axios = require('axios')
|
|
|
|
let _this
|
|
|
|
class WebHook {
|
|
constructor () {
|
|
_this = this
|
|
_this.config = config
|
|
_this.axios = axios
|
|
}
|
|
|
|
// REST petition to create a webhook in p2wdb-service
|
|
async createWebHook (url) {
|
|
try {
|
|
if (!url || typeof url !== 'string') {
|
|
throw new Error('url must be a string')
|
|
}
|
|
|
|
const endpoint = _this.config.webhookService
|
|
|
|
const obj = {
|
|
appId: 'torlist',
|
|
url
|
|
}
|
|
|
|
const result = await axios.post(endpoint, obj)
|
|
|
|
return result.data
|
|
} catch (err) {
|
|
console.log('Error in adapters/webhook/createWebHook()')
|
|
throw err
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = WebHook
|