Created
August 4, 2011 18:17
-
-
Save ghermeto/1125814 to your computer and use it in GitHub Desktop.
Using blitz node.js api client
This file contains 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
var Blitz = require('blitz'); | |
var email = "[email protected]", | |
apiKey = "aqbcdge-sjfkgurti-sjdhgft-skdiues", | |
myWebsite = "http://your.cool.app", | |
blitz= new Blitz(email, apiKey); | |
// Run a sprint | |
blitz.sprint({ | |
steps: [{url: myWebsite}], | |
region: 'california' | |
}).on('status', function (data) { | |
// do something... | |
}).on('complete', function (data) { | |
console.log('region: ' + data.region); | |
console.log('duration: ' + data.duration); | |
var steps = data.steps; | |
for(var i in steps) { | |
var step = steps[i]; | |
console.log("> Step " + i); | |
console.log("\tstatus: " + step.response.status); | |
console.log("\tduration: " + step.duration); | |
console.log("\tconnect: " + step.connect); | |
} | |
}).on('error', function (response) { | |
console.log("error: " + response.error); | |
console.log("reason: " + response.reason); | |
}); | |
// Run a rush | |
blitz.rush({ | |
steps: [{url: myWebsite}], | |
region: 'california', | |
pattern: { intervals: [{start: 1, end: 10, duration: 30}]} | |
}).on('status', function (data) { | |
// do something... | |
}).on('complete', function (data) { | |
console.log('region: ' + data.region); | |
console.log('duration: ' + data.duration); | |
var steps = data.steps; | |
for(var i in steps) { | |
var step = steps[i]; | |
console.log("> Step " + i); | |
console.log("\tstatus: " + step.response.status); | |
console.log("\tduration: " + step.duration); | |
console.log("\tconnect: " + step.connect); | |
} | |
}).on('error', function (response) { | |
console.log("error: " + response.error); | |
console.log("reason: " + response.reason); | |
}); | |
//Run a sprint or rush using the command parser | |
blitz.execute('-r ireland http://example.com').on('status', function (data) { | |
// do something... | |
}).on('complete', function (data) { | |
console.log('region: ' + data.region); | |
console.log('duration: ' + data.duration); | |
var steps = data.steps; | |
for(var i in steps) { | |
var step = steps[i]; | |
console.log("> Step " + i); | |
console.log("\tstatus: " + step.response.status); | |
console.log("\tduration: " + step.duration); | |
console.log("\tconnect: " + step.connect); | |
} | |
}).on('error', function (response) { | |
console.log("error: " + response.error); | |
console.log("reason: " + response.reason); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment