diff --git a/examples/event-pollers/emailyak.coffee b/examples/event-pollers/emailyak.coffee
index 369d56c..5575bf1 100644
--- a/examples/event-pollers/emailyak.coffee
+++ b/examples/event-pollers/emailyak.coffee
@@ -1,4 +1,3 @@
-
#
# EmailYak EVENT POLLER
# ---------------------
@@ -17,10 +16,36 @@ exports.newMail = ( pushEvent ) ->
# 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
- log body
if resp.statusCode is 200
+ if body.Emails.length > 0
+ log "#{ body.Emails.length } mail events pushed into the system"
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"
+ }
+ ###
\ No newline at end of file
diff --git a/examples/event-pollers/importio.coffee b/examples/event-pollers/importio.coffee
index 4626335..a2aa5a1 100644
--- a/examples/event-pollers/importio.coffee
+++ b/examples/event-pollers/importio.coffee
@@ -8,13 +8,14 @@ required module params:
params.apikey = "Cc8AX35d4B89ozzmn5bpm7k70HRon5rrfUxZvOwkVRj31/oBGHzVfQSRp5mEvlOgxyh7xi+tFSL66iAFo1W/sQ=="
params.userGuid = "d19f0d08-bf73-4115-90a8-ac045ad4f225"
-params.queryGuid = "caff10dc-3bf8-402e-b1b8-c799a77c3e8c"
+params.queryGuid = "4f833315-7aa0-4fcd-b8d0-c65f6a6bafcf"
+
+io = new importio params.userGuid, params.apikey, "query.import.io"
exports.queryData = ( pushEvent ) ->
debug params.apikey
debug params.queryGuid
debug params.userGuid
- io = new importio params.userGuid, params.apikey, "query.import.io"
io.connect ( connected ) ->
if not connected
@@ -22,10 +23,15 @@ exports.queryData = ( pushEvent ) ->
else
log "Connected!"
data = []
- io.query "input": "input": "query", "connectorGuids": [ params.queryGuid ], ( finished, msg ) ->
+ io.query "input": { "input": "query" }, "connectorGuids": [ params.queryGuid ], ( finished, msg ) ->
+ log 'query returned'
+ log msg
if msg.type is "MESSAGE"
log "Adding #{ msg.data.results.length } results"
data = data.concat msg.data.results
if finished
log "Done"
log JSON.stringify data
+ log 'all work done'
+ log io
+ io = null
diff --git a/examples/event-pollers/weather.coffee b/examples/event-pollers/weather.coffee
index c827e2d..379b314 100644
--- a/examples/event-pollers/weather.coffee
+++ b/examples/event-pollers/weather.coffee
@@ -6,56 +6,38 @@ This module requires user-specific parameters:
- openweatherKey
- tempThreshold
- city
-- eventTime ( hh:mm of the day )
###
urlService = 'http://api.openweathermap.org/data/2.5/weather'
-lastEvent = new Date 0
-twentyFourHoursInms = 24 * 60 * 60 * 1000
-dayTimeInMin = 0
-
-calcEventDayTimeInMin = ( et ) ->
- arrTime = et.split ':'
- hrs = parseInt arrTime[ 0 ]
- mins = parseInt arrTime[ 1 ]
- dayTimeInMin = hrs * 60 + mins
- if isNaN dayTimeInMin
- log 'Wrong temperature input! ' + et
-
-try
- calcEventDayTimeInMin params.eventTime
-catch err
- log 'Unable to parse the eventTime parameter'
###
Fetches the temperature
###
-getTemperature = ( cb ) ->
+getWeatherData = ( cb ) ->
url = urlService + '?APPID=' + params.openweatherKey + '&q=' + params.city
needle.request 'get', url, null, null, cb
+###
+Pushes the current weather data into the system
+###
+exports.currentData = ( pushEvent ) ->
+ getWeatherData ( err, resp, body ) ->
+ if err or resp.statusCode isnt 200
+ log JSON.stringify body
+ else
+ pushEvent body
+
###
Emits one event per day if the temperature today raises above user defined threshold
###
exports.temperatureOverThreshold = ( pushEvent ) ->
- getTemperature ( err, resp, body ) ->
- timeNow = new Date()
-
+ getWeatherData ( err, resp, body ) ->
if err or resp.statusCode isnt 200
- debug body
+ log JSON.stringify body
else
#If temperature is above threshold
- if body.main.temp_max - 272.15 > params.tempThreshold and
-
- # If last event was more than 24 hours ago
- timeNow - lastEvent > twentyFourHoursInms and
-
- # If we are past the time the user wants to get the information
- timeNow.getHours() * 60 + timeNow.getMinutes() > dayTimeInMin
-
- lastEvent = timeNow
+ if body.main.temp_max - 272.15 > params.tempThreshold
pushEvent
threshold: params.tempThreshold
measured: body.main.temp_max - 272.15
- content: "The temperature will be #{ body.main.temp_max - 272.15 } today!"
diff --git a/webpages/handlers/coffee/edit_rules.coffee b/webpages/handlers/coffee/edit_rules.coffee
index be67715..5a3101c 100644
--- a/webpages/handlers/coffee/edit_rules.coffee
+++ b/webpages/handlers/coffee/edit_rules.coffee
@@ -68,8 +68,9 @@ fOnLoad = () ->
id: ruleName
$.post( '/usercommand', data )
.done ( data ) ->
+ ts = ( new Date() ).toISOString()
log = data.message.replace new RegExp("\n", 'g'), "
"
- $( '#log_col' ).html "