Last active
December 18, 2015 08:49
-
-
Save cadams500/5756962 to your computer and use it in GitHub Desktop.
Example eDataSource API Usage
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
/* | |
* VERY raw way to read a restful API endpoint. | |
* This code can be refined and made into a very simple REST library quite easily. | |
* | |
* Code has not been tested and should be taken as pseudo-code. | |
*/ | |
String apiKey = "myapi-key"; | |
URL url = new URL("http://api.emaildatasource.com/service/2.0.0/rest/api.service.engagements?method=getAvailableDomains&api-key=" + apiKey); | |
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | |
conn.setRequestMethod("GET"); | |
conn.setRequestProperty("Accept", "application/json"); | |
conn.connect(); | |
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); | |
StringBuilder sb = new StringBuilder(); | |
String line; | |
while ((line = rd.readLine()) != null) { | |
sb.append(line); | |
} | |
rd.close(); | |
conn.disconnect(); | |
Gson gson = new Gson(); | |
String json = sb.toString(); | |
String [] domains = gson.fromJson(json,String[].class); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment