-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to check for website status
- Loading branch information
Tom Bell
committed
Sep 22, 2011
1 parent
13d2098
commit 4bde98f
Showing
5 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(function() { | ||
var http, isItUp; | ||
http = require("http"); | ||
exports.isItUp = isItUp = function(url, callback) { | ||
var opts, request; | ||
opts = { | ||
host: "www.isup.me", | ||
path: "/" + url | ||
}; | ||
request = http.request(opts, function(response) { | ||
var data; | ||
data = ""; | ||
response.on("data", function(chunk) { | ||
return data += chunk; | ||
}); | ||
response.on("end", function() { | ||
var body, down, unknown, up; | ||
body = ""; | ||
unknown = data.indexOf('doesn\'t look like a site on the interwho.'); | ||
down = data.indexOf('looks down from here.'); | ||
up = data.indexOf('is up.'); | ||
if (unknown !== -1) { | ||
body = "" + url + " doesn't look like a site on the interwho."; | ||
} else if (down !== -1) { | ||
body = "" + url + " looks down from here."; | ||
} else if (up !== -1) { | ||
body = "" + url + " is up."; | ||
} else { | ||
body = null; | ||
} | ||
if (!body) { | ||
return callback("Could not find the status for " + url); | ||
} else { | ||
return callback(null, body); | ||
} | ||
}); | ||
return response.on("error", function(error) { | ||
return callback(error); | ||
}); | ||
}); | ||
request.on("error", function(error) { | ||
return callback(error); | ||
}); | ||
return request.end(); | ||
}; | ||
}).call(this); |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
http = require "http" | ||
|
||
exports.isItUp = isItUp = (url, callback) -> | ||
opts = | ||
host: "www.isup.me" | ||
path: "/#{url}" | ||
|
||
request = http.request opts, (response) -> | ||
data = "" | ||
|
||
response.on "data", (chunk) -> | ||
data += chunk | ||
|
||
response.on "end", -> | ||
body = "" | ||
|
||
|
||
unknown = data.indexOf 'doesn\'t look like a site on the interwho.' | ||
down = data.indexOf 'looks down from here.' | ||
up = data.indexOf 'is up.' | ||
|
||
if unknown isnt -1 | ||
body = "#{url} doesn't look like a site on the interwho." | ||
else if down isnt -1 | ||
body = "#{url} looks down from here." | ||
else if up isnt -1 | ||
body = "#{url} is up." | ||
else | ||
body = null | ||
|
||
if not body | ||
callback "Could not find the status for #{url}" | ||
else | ||
callback null, body | ||
|
||
response.on "error", (error) -> | ||
callback error | ||
|
||
request.on "error", (error) -> | ||
callback error | ||
|
||
request.end() |