-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpingity.js
67 lines (55 loc) · 1.5 KB
/
pingity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const request = require('request-promise');
const PINGITY_ID = "xE5Vj2EK503jtXPOfAQYo7Vb"
const PINGITY_SECRET = "TepNhXkENEcrbpHBro54EzvffVkByHTDkiQF9loPCOyfkcICvfvCnHIPhRCgtRO2"
function ValidateWithPingity(input) {
console.log(input)
let options = {
method: 'POST',
uri: 'https://pingity.com/api/v1/reports',
auth: {
'user': PINGITY_ID,
'pass': PINGITY_SECRET,
},
body: { resource: input },
json: true, // Automatically stringifies the body to JSON
resolveWithFullResponse: true // Make sure to return everything, not just response body
};
return request(options)
.then(function (response){
//success
result = response.toJSON();
report = result.body[0].status.code;
return {
response: result.statusCode,
body: result.body,
result: displayResult(report)
};
})
.catch(function (err){
//fail
console.log(err);
return ValidateWithRegex(input);
});
}
function ValidateWithRegex(input) {
let mailformat = /^\S+@\S+$/;
if(input.match(mailformat)) {
return "Format valid";
} else {
return "You have entered an invalid email address!";
}
}
function displayResult(result) {
switch (result) {
case "pass":
return "Address valid, passing all tests";
case "fail_critical":
return "Address not valid";
case "warning":
return "Address valid, some tests failing.";
}
}
module.exports = {
validate: ValidateWithPingity,
basic: ValidateWithRegex
};