mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-16 22:10:31 +00:00
Updated remote engine example, called webhook now
This commit is contained in:
parent
a6690acb84
commit
842c73c475
2 changed files with 7 additions and 25 deletions
1
examples/.gitignore
vendored
Normal file
1
examples/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
params.json
|
||||
|
|
@ -3,27 +3,14 @@ Remote Engine
|
|||
-------------
|
||||
#
|
||||
# Requires user params:
|
||||
# - username: username to the remote system
|
||||
# - password: password to the remote system
|
||||
# - event: The event type to be pushed into the system
|
||||
# - url: The url to the WebAPI engine that will receive the event
|
||||
# - eventname: The event type to be pushed into the system
|
||||
# - webhook: The url to the emote webhook that will receive the event
|
||||
###
|
||||
hashedPassword = cryptoJS.SHA3( params.password, outputLength: 512 ).toString()
|
||||
options =
|
||||
method: 'POST'
|
||||
json: true
|
||||
jar: true
|
||||
|
||||
fPushEvent = ( evt ) ->
|
||||
options.url = params.url + '/event'
|
||||
options.body = JSON.stringify evt
|
||||
request options, ( err, resp, body ) ->
|
||||
if err or resp.statusCode isnt 200
|
||||
log 'Error in pushing event!'
|
||||
else
|
||||
log 'Successfully posted an event'
|
||||
|
||||
|
||||
###
|
||||
Push an event into a WebAPI engine.
|
||||
|
||||
|
|
@ -32,18 +19,12 @@ Push an event into a WebAPI engine.
|
|||
exports.pushEvent = ( evt ) ->
|
||||
if not evt
|
||||
evt = {}
|
||||
evt.event = params.event
|
||||
evt.event = params.eventname
|
||||
|
||||
data =
|
||||
username: params.username
|
||||
password: hashedPassword
|
||||
options.url = params.url + '/login'
|
||||
options.body = JSON.stringify data
|
||||
options.url = params.webhook
|
||||
options.body = JSON.stringify evt
|
||||
request options, ( err, resp, body ) ->
|
||||
if err or resp.statusCode isnt 200
|
||||
log 'Error in pushing event!'
|
||||
else
|
||||
fPushEvent evt
|
||||
|
||||
|
||||
# http://localhost:8125
|
||||
log 'Successfully posted an event'
|
||||
|
|
|
|||
Loading…
Reference in a new issue