Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 42c30a8

Browse files
committed
merge #1 and update how person data is set
2 parents dd82e23 + a4eb8b8 commit 42c30a8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/main/java/com/rollbar/android/Notifier.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class Notifier {
4040
private Context context;
4141
private String accessToken;
4242
private String environment;
43+
44+
private JSONObject personData;
4345

4446
private String endpoint;
4547
private boolean reportUncaughtExceptions;
@@ -84,6 +86,29 @@ public Notifier(Context context, String accessToken, String environment) {
8486
scheduleItemFileHandler();
8587
}
8688

89+
public void setPersonData(JSONObject personData) {
90+
this.personData = personData;
91+
}
92+
93+
public void setPersonData(String id, String username, String email) {
94+
JSONObject personData = new JSONObject();
95+
96+
try {
97+
personData.put("id", id);
98+
99+
if (username != null) {
100+
personData.put("username", username);
101+
}
102+
if (email != null) {
103+
personData.put("email", email);
104+
}
105+
106+
this.personData = personData;
107+
} catch (JSONException e) {
108+
Log.e(Rollbar.TAG, "JSON error creating person data.", e);
109+
}
110+
}
111+
87112
private JSONObject buildNotifierData() throws JSONException {
88113
JSONObject notifier = new JSONObject();
89114
notifier.put("name", "rollbar-android");
@@ -118,6 +143,9 @@ private JSONObject buildData(String level, JSONObject body) throws JSONException
118143

119144
data.put("body", body);
120145

146+
if (personData != null) {
147+
data.put("person", personData);
148+
}
121149
data.put("client", buildClientData());
122150
data.put("notifier", buildNotifierData());
123151

src/main/java/com/rollbar/android/Rollbar.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.content.Context;
44
import android.util.Log;
55

6+
import org.json.JSONObject;
7+
68
public class Rollbar {
79
public static final String TAG = "Rollbar";
810

@@ -56,6 +58,14 @@ public void run() {
5658
});
5759
}
5860

61+
public static void setPersonData(JSONObject personData) {
62+
notifier.setPersonData(personData);
63+
}
64+
65+
public static void setPersonData(String id, String username, String email) {
66+
notifier.setPersonData(id, username, email);
67+
}
68+
5969
private static void ensureInit(Runnable runnable) {
6070
if (notifier == null) {
6171
Log.e(TAG, "Rollbar not initialized with an access token!");

0 commit comments

Comments
 (0)