Skip to content

Commit

Permalink
Fixes & corrections.
Browse files Browse the repository at this point in the history
  • Loading branch information
whoisxmlapi committed Aug 1, 2018
1 parent f9f9550 commit 071e10a
Show file tree
Hide file tree
Showing 26 changed files with 666 additions and 528 deletions.
8 changes: 3 additions & 5 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.whoisxmlapi.whoisapi</groupId>
<artifactId>whois2-api-key-example</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>whois-api-v2-example</artifactId>
<version>1.0</version>

<dependencies>
<dependency>
Expand All @@ -30,12 +30,10 @@
</execution>
</executions>
<configuration>
<executable>Whois2ApiKeyExample</executable>
<mainClass>Whois2ApiKeyExample</mainClass>
<mainClass>WhoisApiV2Sample</mainClass>
</configuration>
</plugin>
</plugins>
</build>


</project>
59 changes: 0 additions & 59 deletions java/src/main/java/Whois2ApiKeyExample.java

This file was deleted.

83 changes: 83 additions & 0 deletions java/src/main/java/WhoisApiV2Sample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.ResponseHandler;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class WhoisApiV2Sample
{
public static final String API_URL =
"https://www.whoisxmlapi.com/whoisserver/WhoisService";

public static void main(String[]args) throws IOException
{
String apiKey = "Your Whois API key";
String domainName = "test.com";

String url = API_URL
+ "?domainName=" + URLEncoder.encode(domainName, "UTF-8")
+ "&apiKey=" + URLEncoder.encode(apiKey, "UTF-8");

CloseableHttpClient httpclient = null;

try {
httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet(url);

System.out.println("executing request " + httpget.getURI());

// Create a response handler
ResponseHandler<String> responseHandler =
new BasicResponseHandler();

String responseBody = httpclient.execute(httpget,responseHandler);

System.out.println(responseBody);
System.out.println("----------------------------------------");

// Parse

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();

InputSource is = new InputSource();
is.setCharacterStream(new StringReader(responseBody));

Document doc = db.parse(is);

System.out.println("Root element "
+ doc.getDocumentElement().getNodeName());

}
catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
catch (SAXException ex) {
ex.printStackTrace();
}
catch (ParserConfigurationException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
finally {
if (httpclient != null)
httpclient.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.7" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
</component>
</module>
37 changes: 0 additions & 37 deletions js/whois2_jquery_jsonp.html

This file was deleted.

53 changes: 0 additions & 53 deletions js/whois2_js.html

This file was deleted.

40 changes: 40 additions & 0 deletions js/whois_api_jquery_jsonp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<title>Whois API jQuery JSONP Sample</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript">

var apiUrl = "https://www.whoisxmlapi.com/whoisserver/WhoisService";

var apiKey = "Your whois API key";
var domain = "google.com";

$(function() {
$.ajax(
{
url: apiUrl,
dataType: "jsonp",
data: {
apiKey: apiKey,
domainName: domain,
outputFormat: "json"
},
success: function(response) {
$("#json").append("<div>JSON answer:</div>"
+ JSON.stringify(response, null,2));
},
error: function(e) {
console.log(e);
}
}
);
});

</script>
</head>

<body>
<pre id="json"></pre>
</body>
</html>
70 changes: 70 additions & 0 deletions js/whois_api_js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html>
<head>
<title>Sample Javascript Whois API Client</title>
<script type="text/javascript">

var apiUrl = "https://www.whoisxmlapi.com/whoisserver/WhoisService";

// Fill in your details
var apiKey = "Your Whois API key";
var domain = "google.com";
var format = "JSON";
var jsonCallback = "LoadJSON";

window.addEventListener("load", onPageLoad, false);

function onPageLoad() {
// Use a JSON resource
var url = apiUrl
+ "?domainName=" + encodeURIComponent(domain)
+ "&apiKey=" + encodeURIComponent(apiKey)
+ "&outputFormat=" + encodeURIComponent(format);

// Dynamically Add a script tag to get our JSON data from a
// different server, avoiding cross origin problems.

var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");

// The function specified in jsonCallback will be called with a
// single argument representing the JSON object.

script.type = "text/javascript";
script.src = url + "&callback=" + jsonCallback;

head.appendChild(script);
}

// Do something with the json result
function LoadJSON(result) {
// Print out a nice informative string
document.body.innerHTML += "<div>JSON:</div>"
+ RecursivePrettyPrint(result);
}

function RecursivePrettyPrint(obj) {
var str = "";

for (var x in obj) {
if (obj.hasOwnProperty(x)) {
str += '<div style="'
+ "margin-left: 25px;border-left:1px solid black"
+ '">' + x + ": ";
if (typeof(obj[x]) == "string")
str += obj[x];
else
str += RecursivePrettyPrint(obj[x]);
str += "</div>";
}
}

return str;
}

</script>

</head>
<body>
</body>
</html>
Loading

0 comments on commit 071e10a

Please sign in to comment.