Search in sources :

Example 1 with ABRow

use of com.clutch.ClutchStats.ABRow in project clutchandroid by clutchio.

the class ClutchAB method sendABLogs.

private static void sendABLogs() {
    ArrayList<ABRow> logs = stats.getABLogs();
    if (logs.size() == 0) {
        return;
    }
    final ABRow lastRow = logs.get(logs.size() - 1);
    JSONArray jsonLogs = new JSONArray();
    for (ABRow row : logs) {
        JSONObject rowObj = new JSONObject();
        try {
            rowObj.put("uuid", row.uuid);
            rowObj.put("ts", row.ts);
            rowObj.put("data", row.data);
        } catch (JSONException e1) {
            // TODO: Don't discard the row.
            Log.e(TAG, "Could not properly encode the AB logs into JSON for upload to Clutch. Discarding the row.");
            continue;
        }
        jsonLogs.put(rowObj);
    }
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("logs", jsonLogs);
    params.put("guid", ClutchAPIClient.getFakeGUID());
    ClutchAPIClient.callMethod("send_ab_logs", params, new ClutchAPIResponseHandler() {

        @Override
        public void onSuccess(JSONObject response) {
            if ("ok".equals(response.optString("status"))) {
                stats.deleteABLogs(lastRow.ts);
            } else {
                Log.e(TAG, "Failed to send the Clutch AB logs to the server.");
            }
        }

        @Override
        public void onFailure(Throwable e, JSONObject errorResponse) {
            Log.e(TAG, "Failed to send AB logs to Clutch: " + errorResponse);
        }
    });
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ABRow(com.clutch.ClutchStats.ABRow) JSONObject(org.json.JSONObject)

Aggregations

ABRow (com.clutch.ClutchStats.ABRow)1 HashMap (java.util.HashMap)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1