Skip to content

Instantly share code, notes, and snippets.

@sirkirby
Created October 22, 2012 22:01
Show Gist options
  • Save sirkirby/3934844 to your computer and use it in GitHub Desktop.
Save sirkirby/3934844 to your computer and use it in GitHub Desktop.
RyanTech VIN Explosion API Decode VIN w/ Java
//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