mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-07 20:35:30 +01:00
DRY
This commit is contained in:
parent
230c8ccf73
commit
c95bac34a0
@ -11,11 +11,20 @@ server.listen(4430)
|
||||
server.use(bodyParser.json())
|
||||
|
||||
//
|
||||
// Zoho API urls
|
||||
// Zoho APIs
|
||||
//
|
||||
const apiUrlZohoCampaigns = 'https://campaigns.zoho.com/api/'
|
||||
const apiUrlZohoCRM = 'https://www.zohoapis.com/crm/v2/'
|
||||
|
||||
const sendRequest = (options, res) => {
|
||||
request(options, (error, response, body) => {
|
||||
if (error) res.send(error)
|
||||
|
||||
res.send(body)
|
||||
res.sendStatus(200)
|
||||
})
|
||||
}
|
||||
|
||||
//
|
||||
// Subscribe to newsletter via Zoho Campaigns API
|
||||
// https://www.zoho.com/campaigns/newhelp/api/contact-subscribe.html
|
||||
@ -27,15 +36,7 @@ server.get('/newsletter/:data', (req, res) => {
|
||||
const options = {
|
||||
url: `${apiUrlZohoCampaigns}json/listsubscribe?authtoken=${ZOHO_CAMPAIGNS_TOKEN}&scope=CampaignsAPI&resfmt=JSON&listkey=${ZOHO_CAMPAIGNS_LIST_KEY}&contactinfo=${data}` // eslint-disable-line max-len
|
||||
}
|
||||
|
||||
request(options, (error, response, body) => {
|
||||
if (error) {
|
||||
res.send(error)
|
||||
}
|
||||
|
||||
res.send(body)
|
||||
res.sendStatus(200)
|
||||
})
|
||||
sendRequest(options, res)
|
||||
})
|
||||
|
||||
//
|
||||
@ -52,15 +53,7 @@ server.get('/crm/:data', (req, res) => {
|
||||
method: 'POST',
|
||||
formData: data
|
||||
}
|
||||
|
||||
request(options, (error, response, body) => {
|
||||
if (error) {
|
||||
res.send(error)
|
||||
}
|
||||
|
||||
res.send(body)
|
||||
res.sendStatus(200)
|
||||
})
|
||||
sendRequest(options, res)
|
||||
})
|
||||
|
||||
module.exports = Webtask.fromExpress(server)
|
||||
|
Loading…
Reference in New Issue
Block a user