Last active
December 28, 2015 04:19
-
-
Save pfn/7442087 to your computer and use it in GitHub Desktop.
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
private static Future<String> requestJson(final String uri) { | |
return Future.create(new Callable<String>() { | |
public String call() throws IOException { | |
OkHttpClient client = new OkHttpClient(); | |
HttpURLConnection conn = client.open(new URL(uri)); | |
InputStreamReader in = | |
new InputStreamReader(conn.getInputStream(), "utf-8"); | |
try { | |
return CharStreams.toString(in); | |
} finally { | |
in.close(); | |
conn.disconnect(); | |
} | |
} | |
}); | |
} | |
public Future<Config> getConfig() { | |
return requestJson(CONFIG).map(new Function<String,Config>() { | |
public Config apply(String in) { | |
Gson gson = new Gson(); | |
Config.Envelope envelope = gson.fromJson(in, Config.Envelope.class); | |
return envelope.result; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment