(Context context, String api, String apiKey)
| 198 | } |
| 199 | |
| 200 | private static Pair<Integer, String> call(Context context, String api, String apiKey) throws IOException { |
| 201 | URL url = new URL(URI_ENDPOINT + api); |
| 202 | HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); |
| 203 | connection.setRequestMethod("GET"); |
| 204 | connection.setReadTimeout(VT_TIMEOUT * 1000); |
| 205 | connection.setConnectTimeout(VT_TIMEOUT * 1000); |
| 206 | ConnectionHelper.setUserAgent(context, connection); |
| 207 | connection.setRequestProperty("x-apikey", apiKey); |
| 208 | connection.setRequestProperty("Accept", "application/json"); |
| 209 | connection.connect(); |
| 210 | |
| 211 | try { |
| 212 | int status = connection.getResponseCode(); |
| 213 | if (status != HttpsURLConnection.HTTP_OK) { |
| 214 | String error = "Error " + status + ": " + connection.getResponseMessage(); |
| 215 | try { |
| 216 | InputStream is = connection.getErrorStream(); |
| 217 | if (is != null) |
| 218 | error += "\n" + Helper.readStream(is); |
| 219 | } catch (Throwable ex) { |
| 220 | Log.w(ex); |
| 221 | } |
| 222 | return new Pair<>(status, error); |
| 223 | } |
| 224 | |
| 225 | String response = Helper.readStream(connection.getInputStream()); |
| 226 | //Log.i("VT response=" + response); |
| 227 | return new Pair<>(status, response); |
| 228 | |
| 229 | } finally { |
| 230 | connection.disconnect(); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | public static class ScanResult implements Parcelable { |
| 235 | public String name; |
no test coverage detected