Created
October 22, 2012 22:01
-
-
Save sirkirby/3934844 to your computer and use it in GitHub Desktop.
RyanTech VIN Explosion API Decode VIN w/ Java
This file contains hidden or 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
//using Base64Coder and google-gson | |
// initiate the http request to the vin explosion api | |
HttpClient client = new DefaultHttpClient(); | |
String getUrl = "http://vinexplosion.com/api/vin/decode/"; | |
getUrl += vin + "/"; | |
getUrl += "?fuzzy=" + URLEncoder.encode("true"); | |
HttpGet get = new HttpGet(getUrl); | |
// set the appropriate request headers | |
get.addHeader("Authorization", "Basic " + Base64Coder.encodeString("username:password")); | |
get.addHeader("Accept", "application/json"); | |
HttpResponse responseGet = client.execute(get); | |
HttpEntity resEntityGet = responseGet.getEntity(); | |
// process the response | |
String jsonResponse = EntityUtils.toString(resEntityGet); | |
JsonParser parser = new JsonParser(); | |
JsonObject json = parser.parse(jsonResponse).getAsJsonObject(); | |
JsonObject provider = json.getAsJsonArray("Vehicles").get(0).getAsJsonObject().getAsJsonArray("Providers").get(0).getAsJsonObject(); | |
String year = provider.get("Year").getAsString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment