Created
June 6, 2012 16:00
-
-
Save KirinDave/2882881 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initializing variables | |
var action = "enter"; | |
var location = { | |
name: "CrowdFlower", | |
latitude: "37.00000", | |
longitude: "-122.00000" | |
}; | |
console.log("Setting up campfire chatter."); | |
// End of variables initializing | |
// Helper functions | |
function sayInCampfire(phrase) { | |
device.ajax({ | |
url: 'https://TOPSEKRITAPIKEYZ:[email protected]/room/123456/speak.json', | |
data: '{"message": {"body": "' + phrase + '"}}', | |
type: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
onSuccess: function(body, textStatus, response) { | |
device.notifications.createNotification("Announced you on Campfire!").show(); | |
}, | |
onError: function(textStatus, response) { | |
device.notifications.createNotification("Failed to announce you on Campfire: " + textStatus).show(); | |
} | |
}); | |
} | |
console.log('Started script: Tell Campfire when I am here'); | |
// create a geo region for the trigger to take place at | |
var region = device.regions.createRegion({ | |
latitude: parseFloat(location.latitude, 10), | |
longitude: parseFloat(location.longitude, 10), | |
name: location.name, | |
radius: 1000 | |
}); | |
// register a callback to show a notification on entering/exiting the region | |
region.on(action, | |
function() { | |
device.notifications.createNotification("I'm going to try an announce you in campfire.").show(); | |
sayInCampfire("I am now at the office."); | |
}); | |
// start monitoring the region | |
device.regions.startMonitoring(region); | |
console.log('Completed script: When i get to work hit campfire.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Btw it seems there is a bug where console output doesn't show on load. Not sure why, but I'm going to have to use notifications.