-
Notifications
You must be signed in to change notification settings - Fork 0
/
pingity-widget.js
61 lines (52 loc) · 1.46 KB
/
pingity-widget.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
const PINGITY_ID = "xE5Vj2EK503jtXPOfAQYo7Vb"
const PINGITY_SECRET = "TepNhXkENEcrbpHBro54EzvffVkByHTDkiQF9loPCOyfkcICvfvCnHIPhRCgtRO2"
function ValidateWithPingity() {
let input = document.getElementById('pingity-address').value
console.log(input)
$(document).ajaxStart(function() {
$( "#pingity-status" ).children().hide();
$( "#working" ).show();
});
var request = $.ajax({
url: 'https://pingity.com/api/v1/reports',
type: 'POST',
data: { resource: input } ,
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', 'Basic ' + btoa(PINGITY_ID + ':' + PINGITY_SECRET));
},
dataType: "json"
});
request.done(function(report) {
// your success code here
result = report[0].status.code;
return displayResult(result);
});
request.fail(function(jqXHR, textStatus) {
$( "#pingity-status" ).children().hide();
$( "#skipped" ).show();
$( "#oops" ).show();
return ValidateWithRegex(input);
});
}
function ValidateWithRegex(input) {
let mailformat = /^\S+@\S+$/;
if(input.match(mailformat)) {
alert("Format valid");
} else {
alert("You have entered an invalid email address!");
}
}
function displayResult(result) {
$( "#pingity-status" ).children().hide();
switch (result) {
case "pass":
$( "#success" ).show();
break;
case "fail_critical":
$( "#fail" ).show();
break;
case "warning":
$( "#warning" ).show();
break;
}
}