public static UserAgentModel lookupUserAgent(String userAgentString) throws IOException { String encodedUserAgent = StringUtils.encodeUrl(userAgentString); String url = "http://www.useragentstring.com/?getJSON=all&uas=" + encodedUserAgent; URLConnection connection = new URL(url).openConnection(); String json = IoUtils.toString(connection.getInputStream()); return objectMapper.readValue(json, UserAgentModel.class); }
public String shortenUnencodedUrl(String longUrl) throws IOException { longUrl = StringUtils.encodeUrl(longUrl); return shortenEncodedUrl(longUrl); }
public static LatLng getLatLng(String address, String city, String state, String zip) throws IOException { String url = "https://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address="; url += encodeUrl(String.format("%s, %s, %s %s", address, city, state, zip)); URLConnection connection = new URL(url).openConnection(); String data = IoUtils.toString(connection.getInputStream()); data = getTagContents(data, "location", 0); return new LatLng( getTagContents(data, "lat", 0), getTagContents(data, "lng", 0) ); } }