Пример #1
0
 @Override
 public void onPostExecute(String result) {
   try {
     JSONObject object = new JSONObject(result);
     String apiHits = object.getString("api_hits");
     a.logMessage(apiHits);
     delegate.onApiAggregated(apiHits);
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
Пример #2
0
  @Override
  protected String doInBackground(Void... voids) {
    a = new A(context);

    HttpURLConnection connection = null;
    BufferedReader reader = null;
    String membersString = null;

    Uri.Builder builder1 = new Uri.Builder();
    // https://tipstat.0x10.info/api/tipstat?type=json&query=api_hits
    builder1
        .scheme("https")
        .authority("tipstat.0x10.info")
        .appendPath("api")
        .appendPath("tipstat")
        .appendQueryParameter("type", "json")
        .appendQueryParameter("query", "api_hits");
    String builtUrl = builder1.build().toString();
    Log.d("URL", builtUrl);

    try {
      URL url = new URL(builtUrl);
      connection = (HttpURLConnection) url.openConnection();
      connection.setRequestMethod("GET");
      connection.connect();

      InputStream inputStream = connection.getInputStream();
      StringBuilder builder = new StringBuilder();
      reader = new BufferedReader(new InputStreamReader(inputStream));

      String line;
      while ((line = reader.readLine()) != null) {
        builder.append(line + "\n");
      }

      membersString = builder.toString();
    } catch (IOException e) {
      Log.e("ApiHitsAggregator", "Error ", e);
    } finally {
      if (connection != null) {
        connection.disconnect();
      }
      if (reader != null) {
        try {
          reader.close();
        } catch (final IOException e) {
          Log.e("ApiHitsAggregator", "Error closing stream", e);
        }
      }
    }

    a.logMessage(membersString);
    return membersString;
  }