mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-17 06:20:23 +00:00
173 lines
4.9 KiB
HTML
173 lines
4.9 KiB
HTML
<script src="js/ace-src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
|
|
<script id="template_event_poller" type="text/template">
|
|
#
|
|
# EmailYak EVENT POLLER
|
|
# ---------------------
|
|
#
|
|
# Requires user params:
|
|
# - apikey: The user's EmailYak API key
|
|
#
|
|
|
|
url = 'https://api.emailyak.com/v1/' + params.apikey + '/json/get/new/email/'
|
|
|
|
exports.newMail = () ->
|
|
|
|
# needlereq allows the user to make calls to API's
|
|
# Refer to https://github.com/tomas/needle for more information
|
|
#
|
|
# Syntax: needle.request method, url, data, [options], callback
|
|
#
|
|
needle.request 'get', url, null, null, ( err, resp, body ) ->
|
|
log 'Poll function executed'
|
|
if err
|
|
log 'Error in EmailYak EM newMail: ' + err.message
|
|
else
|
|
if resp.statusCode is 200
|
|
if body.Emails.length > 0
|
|
log "#{ body.Emails.length } mail events pushed into the system"
|
|
exports.pushEvent mail for mail in body.Emails
|
|
|
|
###
|
|
This will emit events of the form:
|
|
( Refer to http://docs.emailyak.com/get-new-email.html for more information. )
|
|
|
|
{
|
|
"EmailID": "xquukd5z",
|
|
"Received": "2014-04-19T11:27:11",
|
|
"ToAddress": "test@mscliveweb.simpleyak.com",
|
|
"ParsedData": [
|
|
{
|
|
"Data": "Best Regards\nTest User",
|
|
"Part": 0,
|
|
"Type": "Email"
|
|
}
|
|
],
|
|
"FromName": "Test User",
|
|
"ToAddressList": "test@mscliveweb.simpleyak.com",
|
|
"FromAddress": "test.address@provider.com",
|
|
"HtmlBody": "Best Regards\nTest User",
|
|
"CcAddressList": "",
|
|
"TextBody": "Best Regards\nTest User",
|
|
"Subject": "test subject"
|
|
}
|
|
###
|
|
</script>
|
|
<script id="template_action_invoker" type="text/template">
|
|
###
|
|
ProBinder ACTION INVOKER
|
|
------------------------
|
|
|
|
Global variables
|
|
This module requires user-specific parameters:
|
|
- username
|
|
- password
|
|
###
|
|
urlService = 'https://probinder.com/service/'
|
|
credentials =
|
|
username: params.username
|
|
password: params.password
|
|
|
|
#
|
|
# The standard callback can be used if callback is not provided, e.g. if
|
|
# the function is called from outside
|
|
#
|
|
standardCallback = ( funcName ) ->
|
|
( err, resp, body ) ->
|
|
if err
|
|
log "ERROR: During function '#{ funcName }'"
|
|
else
|
|
if resp.statusCode is 200
|
|
log "Function '#{ funcName }' ran through without error"
|
|
else
|
|
log "ERROR: During function '#{ funcName }': #{ body.error.message }"
|
|
|
|
###
|
|
Call the ProBinder service with the given parameters.
|
|
|
|
@param {Object} args the required function arguments object
|
|
@param {Object} [args.data] the data to be posted
|
|
@param {String} args.service the required service identifier to be appended to the url
|
|
@param {String} args.method the required method identifier to be appended to the url
|
|
@param {function} [args.callback] the function to receive the request answer
|
|
###
|
|
callService = ( args ) ->
|
|
if not args.service or not args.method
|
|
log 'ERROR in call function: Missing arguments!'
|
|
else
|
|
if not args.callback
|
|
args.callback = standardCallback 'call'
|
|
url = urlService + args.service + '/' + args.method
|
|
log 'call service executed: ' + url
|
|
needle.request 'post', url, args.data, credentials, args.callback
|
|
|
|
|
|
###
|
|
Does everything to post something in a binder
|
|
|
|
@param {String} companyId the comany associated to the binder
|
|
@param {String} contextId the binder id
|
|
@param {String} content the content to be posted
|
|
###
|
|
exports.newContent = ( companyId, contextId, content ) ->
|
|
if arguments[ 4 ]
|
|
callback = arguments[ 4 ]
|
|
else
|
|
callback = standardCallback 'newContent'
|
|
callService
|
|
service: '27'
|
|
method: 'save'
|
|
data:
|
|
companyId: companyId
|
|
context: contextId
|
|
text: content
|
|
callback: callback
|
|
|
|
###
|
|
Does everything to post a file info in a binder tab
|
|
|
|
@param {String} fromService the content service which grabs the content
|
|
@param {String} fromId the content id from which the information is grabbed
|
|
###
|
|
exports.makeFileEntry = ( fromService, fromId, toCompany, toContext ) ->
|
|
getContent
|
|
serviceid: fromService
|
|
contentid: fromId
|
|
callback: ( err, resp, body ) ->
|
|
content = "New file (#{ body.title }) in tab \"#{ body.context[0].name }\",
|
|
find it here!'"
|
|
exports.newContent toCompanyId, toContextId, content, standardCallback 'makeFileEntry'
|
|
|
|
|
|
###
|
|
Calls the content get service with the content id and the service id provided.
|
|
|
|
@param {Object} args the object containing the service id and the content id,
|
|
success and error callback methods
|
|
@param {String} args.serviceid the service id that is able to process this content
|
|
@param {String} args.contentid the content id
|
|
@param {function} [args.callback] receives the needle answer from the "call" function
|
|
###
|
|
getContent = ( args ) ->
|
|
if not args.callback
|
|
args.callback = standardCallback 'getContent'
|
|
callService
|
|
service: '2'
|
|
method: 'get'
|
|
data:
|
|
id: args.contentid
|
|
service: args.serviceid
|
|
callback: args.callback
|
|
|
|
###
|
|
Sets the content as read.
|
|
|
|
@param {Object} id the content id to be set to read.
|
|
###
|
|
exports.setRead = ( id ) ->
|
|
callService
|
|
service: '2'
|
|
method: 'setread'
|
|
data:
|
|
id: id
|
|
callback: standardCallback 'setRead'
|
|
</script>
|