-
Notifications
You must be signed in to change notification settings - Fork 204
/
Report.java
119 lines (96 loc) · 2.75 KB
/
Report.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.bugsnag.android;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.File;
import java.io.IOException;
/**
* An error report payload.
* <p>
* This payload contains an error report and identifies the source application
* using your API key.
*/
public class Report implements JsonStream.Streamable {
@Nullable
private final File errorFile;
@Nullable
private final Error error;
@NonNull
private final Notifier notifier;
@NonNull
private String apiKey;
Report(@NonNull String apiKey, @Nullable File errorFile) {
this.error = null;
this.errorFile = errorFile;
this.notifier = Notifier.getInstance();
this.apiKey = apiKey;
}
Report(@NonNull String apiKey, @Nullable Error error) {
this.error = error;
this.errorFile = null;
this.notifier = Notifier.getInstance();
this.apiKey = apiKey;
}
@Override
public void toStream(@NonNull JsonStream writer) throws IOException {
// Create a JSON stream and top-level object
writer.beginObject();
writer.name("apiKey").value(apiKey);
writer.name("payloadVersion").value("4.0");
// Write the notifier info
writer.name("notifier").value(notifier);
// Start events array
writer.name("events").beginArray();
// Write in-memory event
if (error != null) {
writer.value(error);
} else if (errorFile != null) { // Write on-disk event
writer.value(errorFile);
} else {
Logger.warn("Expected error or errorFile, found empty payload instead");
}
// End events array
writer.endArray();
// End the main JSON object
writer.endObject();
}
@Nullable
public Error getError() {
return error;
}
/**
* Alters the API key used for this error report.
*
* @param apiKey the new API key
*/
public void setApiKey(@NonNull String apiKey) {
this.apiKey = apiKey;
}
/**
* @return the API key sent as part of this report.
*/
@NonNull
public String getApiKey() {
return apiKey;
}
@InternalApi
@Deprecated
public void setNotifierVersion(@NonNull String version) {
notifier.setVersion(version);
}
@InternalApi
@Deprecated
public void setNotifierName(@NonNull String name) {
notifier.setName(name);
}
@InternalApi
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@Deprecated
public void setNotifierURL(@NonNull String url) {
notifier.setURL(url);
}
@InternalApi
@NonNull
public Notifier getNotifier() {
return notifier;
}
}