Created
September 1, 2015 21:29
-
-
Save fluffels/5cc39d5f7f2f042f5238 to your computer and use it in GitHub Desktop.
Mock out kickbox.io service
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 http = require("http"); | |
var url = require("url"); | |
var listen_port = 49153; | |
var listen_ip = "127.0.0.1"; | |
var headers = { | |
"Content-Type": "application/json" | |
} | |
var response_error_api_key_invalid = { | |
message: "Invalid API key", | |
success: false | |
} | |
var response_valid = { | |
result: "deliverable", | |
reason: "accepted_email", | |
role: false, | |
free: true, | |
disposable: false, | |
accept_all: false, | |
did_you_mean: null, | |
sendex: 0.75, | |
email: "[email protected]", | |
user: "valid", | |
domain: "example.com", | |
success: true, | |
message: null | |
} | |
var response_invalid = { | |
result: "undeliverable", | |
reason: "rejected_email", | |
role: false, | |
free: true, | |
disposable: false, | |
accept_all: false, | |
did_you_mean: null, | |
sendex: 0, | |
email: "[email protected]", | |
user: "invalid", | |
domain: "example.com", | |
success: true, | |
message: null | |
} | |
var response_other = { | |
result: "undeliverable", | |
reason: "invalid_domain", | |
role: false, | |
free: false, | |
disposable: false, | |
accept_all: false, | |
did_you_mean: null, | |
sendex: 0, | |
email: "Arglebargle, glop-glyf?!?", | |
user: "Arglebargle, glop-glyf?!?", | |
domain: "Arglebargle, glop-glyf?!?", | |
success: true, | |
message: null | |
} | |
http.createServer(function (request, response) { | |
var args = url.parse(request.url, true).query; | |
if (args['apikey'] != '1234567890') { | |
response.writeHead(403, headers); | |
response.end(JSON.stringify(response_error_api_key_invalid)); | |
} else if (args['email'] == '[email protected]') { | |
response.writeHead(200, headers); | |
response.end(JSON.stringify(response_valid)); | |
} else if (args['email'] == '[email protected]') { | |
response.writeHead(200, headers); | |
response.end(JSON.stringify(response_invalid)); | |
} else { | |
response.writeHead(200, headers); | |
response.end(JSON.stringify(response_other)); | |
} | |
}).listen(listen_port, listen_ip); | |
console.log("Mock kickbox.io running at " + listen_ip + ":" + listen_port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment