Skip to content

Instantly share code, notes, and snippets.

@trevordixon
Last active August 29, 2015 13:57
Show Gist options
  • Save trevordixon/9542620 to your computer and use it in GitHub Desktop.
Save trevordixon/9542620 to your computer and use it in GitHub Desktop.
ruleset examine_location {
meta {
name "Examine Location Data"
description <<
Examine Location Data
>>
author ""
logging off
use module b505206x2 alias LocationData
}
rule show_fs_location is active {
select when web cloudAppSelected
pre {
checkin = LocationData:get_location_data("fs_checkin");
venue = checkin.pick("$..venue");
city = checkin.pick("$..city");
shout = checkin.pick("$..shout");
createdAt = checkin.pick("$..createdAt");
}
notify("Last Checkin", "#{venue} in #{city}");
}
}
ruleset foursquare_checkins {
meta {
name "Foursquare Checkins"
description <<
Foursquare Checkins
>>
author ""
logging off
use module a169x701 alias CloudRain
use module a41x186 alias SquareTag
}
dispatch {
}
global {
}
rule display_checkin is active {
select when web cloudAppSelected
pre {
venue = ent:venue;
city = ent:city;
shout = ent:shout;
createdAt = ent:createdAt;
my_html = <<
<ul>
<li><strong>Venue</strong>: #{venue}</li>
<li><strong>City</strong>: #{city}</li>
<li><strong>Shout</strong>: #{shout}</li>
<li><strong>Created</strong>: #{createdAt}</li>
</ul>
>>;
}
{
SquareTag:inject_styling();
CloudRain:createLoadPanel("Latest Foursquare Checkin", {}, my_html);
}
}
rule process_fs_checkin {
select when foursquare checkin
pre {
checkin = event:attr("checkin").decode();
venue = checkin.pick("$..venue.name");
city = checkin.pick("$..location.city");
shout = checkin.pick("$..shout", true).head();
createdAt = checkin.pick("$..createdAt");
}
send_directive(venue) 
  with checkin = venue;
fired {
set ent:venue venue;
set ent:city city;
set ent:shout shout;
set ent:createdAt createdAt;
raise pds event new_location_data with
key = "fs_checkin" and
value = {
"venue": venue,
"city": city,
"shout": shout,
"createdAt": createdAt
}
}
}
}
ruleset b505206x2 {
meta {
name "Location Data"
description <<
Location Data
>>
author ""
logging off
provides get_location_data
}
dispatch {
}
global {
get_location_data = function(key) {
ent:location{key};
};
}
rule add_location_item {
select when pds new_location_data
pre {
key = event:attr("key");
value = event:attr("value");
}
send_directive(key) 
  with location = value;
always {
set ent:location{key} value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment