• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #6112

23 Jan 2026 12:17PM UTC coverage: 35.064% (+0.002%) from 35.062%
#6112

push

github

web-flow
docs: Add missing tag to API resources (box/box-openapi#580) (#1689)

18716 of 53377 relevant lines covered (35.06%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.44
/src/main/java/com/box/sdkgen/managers/events/EventsManager.java
1
package com.box.sdkgen.managers.events;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
4
import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
5
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
6
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
7
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
8

9
import com.box.sdkgen.box.eventstream.EventStream;
10
import com.box.sdkgen.networking.auth.Authentication;
11
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
12
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
13
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
14
import com.box.sdkgen.networking.network.NetworkSession;
15
import com.box.sdkgen.schemas.events.Events;
16
import com.box.sdkgen.schemas.realtimeservers.RealtimeServers;
17
import com.box.sdkgen.serialization.json.JsonManager;
18
import java.util.Map;
19

20
public class EventsManager {
21

22
  public Authentication auth;
23

24
  public NetworkSession networkSession;
25

26
  public EventsManager() {
×
27
    this.networkSession = new NetworkSession();
×
28
  }
×
29

30
  protected EventsManager(Builder builder) {
1✔
31
    this.auth = builder.auth;
1✔
32
    this.networkSession = builder.networkSession;
1✔
33
  }
1✔
34

35
  /**
36
   * Returns a list of real-time servers that can be used for long-polling updates to the [event
37
   * stream](https://developer.box.com/reference/get-events).
38
   *
39
   * <p>Long polling is the concept where a HTTP request is kept open until the server sends a
40
   * response, then repeating the process over and over to receive updated responses.
41
   *
42
   * <p>Long polling the event stream can only be used for user events, not for enterprise events.
43
   *
44
   * <p>To use long polling, first use this endpoint to retrieve a list of long poll URLs. Next,
45
   * make a long poll request to any of the provided URLs.
46
   *
47
   * <p>When an event occurs in monitored account a response with the value `new_change` will be
48
   * sent. The response contains no other details as it only serves as a prompt to take further
49
   * action such as sending a request to the [events
50
   * endpoint](https://developer.box.com/reference/get-events) with the last known
51
   * `stream_position`.
52
   *
53
   * <p>After the server sends this response it closes the connection. You must now repeat the long
54
   * poll process to begin listening for events again.
55
   *
56
   * <p>If no events occur for a while and the connection times out you will receive a response with
57
   * the value `reconnect`. When you receive this response you’ll make another call to this endpoint
58
   * to restart the process.
59
   *
60
   * <p>If you receive no events in `retry_timeout` seconds then you will need to make another
61
   * request to the real-time server (one of the URLs in the response for this endpoint). This might
62
   * be necessary due to network errors.
63
   *
64
   * <p>Finally, if you receive a `max_retries` error when making a request to the real-time server,
65
   * you should start over by making a call to this endpoint first.
66
   */
67
  public RealtimeServers getEventsWithLongPolling() {
68
    return getEventsWithLongPolling(new GetEventsWithLongPollingHeaders());
1✔
69
  }
70

71
  /**
72
   * Returns a list of real-time servers that can be used for long-polling updates to the [event
73
   * stream](https://developer.box.com/reference/get-events).
74
   *
75
   * <p>Long polling is the concept where a HTTP request is kept open until the server sends a
76
   * response, then repeating the process over and over to receive updated responses.
77
   *
78
   * <p>Long polling the event stream can only be used for user events, not for enterprise events.
79
   *
80
   * <p>To use long polling, first use this endpoint to retrieve a list of long poll URLs. Next,
81
   * make a long poll request to any of the provided URLs.
82
   *
83
   * <p>When an event occurs in monitored account a response with the value `new_change` will be
84
   * sent. The response contains no other details as it only serves as a prompt to take further
85
   * action such as sending a request to the [events
86
   * endpoint](https://developer.box.com/reference/get-events) with the last known
87
   * `stream_position`.
88
   *
89
   * <p>After the server sends this response it closes the connection. You must now repeat the long
90
   * poll process to begin listening for events again.
91
   *
92
   * <p>If no events occur for a while and the connection times out you will receive a response with
93
   * the value `reconnect`. When you receive this response you’ll make another call to this endpoint
94
   * to restart the process.
95
   *
96
   * <p>If you receive no events in `retry_timeout` seconds then you will need to make another
97
   * request to the real-time server (one of the URLs in the response for this endpoint). This might
98
   * be necessary due to network errors.
99
   *
100
   * <p>Finally, if you receive a `max_retries` error when making a request to the real-time server,
101
   * you should start over by making a call to this endpoint first.
102
   *
103
   * @param headers Headers of getEventsWithLongPolling method
104
   */
105
  public RealtimeServers getEventsWithLongPolling(GetEventsWithLongPollingHeaders headers) {
106
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
107
    FetchResponse response =
1✔
108
        this.networkSession
109
            .getNetworkClient()
1✔
110
            .fetch(
1✔
111
                new FetchOptions.Builder(
112
                        String.join(
1✔
113
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/events"),
1✔
114
                        "OPTIONS")
115
                    .headers(headersMap)
1✔
116
                    .responseFormat(ResponseFormat.JSON)
1✔
117
                    .auth(this.auth)
1✔
118
                    .networkSession(this.networkSession)
1✔
119
                    .build());
1✔
120
    return JsonManager.deserialize(response.getData(), RealtimeServers.class);
1✔
121
  }
122

123
  /**
124
   * Returns up to a year of past events for a given user or for the entire enterprise.
125
   *
126
   * <p>By default this returns events for the authenticated user. To retrieve events for the entire
127
   * enterprise, set the `stream_type` to `admin_logs_streaming` for live monitoring of new events,
128
   * or `admin_logs` for querying across historical events. The user making the API call will need
129
   * to have admin privileges, and the application will need to have the scope `manage enterprise
130
   * properties` checked.
131
   */
132
  public Events getEvents() {
133
    return getEvents(new GetEventsQueryParams(), new GetEventsHeaders());
1✔
134
  }
135

136
  /**
137
   * Returns up to a year of past events for a given user or for the entire enterprise.
138
   *
139
   * <p>By default this returns events for the authenticated user. To retrieve events for the entire
140
   * enterprise, set the `stream_type` to `admin_logs_streaming` for live monitoring of new events,
141
   * or `admin_logs` for querying across historical events. The user making the API call will need
142
   * to have admin privileges, and the application will need to have the scope `manage enterprise
143
   * properties` checked.
144
   *
145
   * @param queryParams Query parameters of getEvents method
146
   */
147
  public Events getEvents(GetEventsQueryParams queryParams) {
148
    return getEvents(queryParams, new GetEventsHeaders());
1✔
149
  }
150

151
  /**
152
   * Returns up to a year of past events for a given user or for the entire enterprise.
153
   *
154
   * <p>By default this returns events for the authenticated user. To retrieve events for the entire
155
   * enterprise, set the `stream_type` to `admin_logs_streaming` for live monitoring of new events,
156
   * or `admin_logs` for querying across historical events. The user making the API call will need
157
   * to have admin privileges, and the application will need to have the scope `manage enterprise
158
   * properties` checked.
159
   *
160
   * @param headers Headers of getEvents method
161
   */
162
  public Events getEvents(GetEventsHeaders headers) {
163
    return getEvents(new GetEventsQueryParams(), headers);
×
164
  }
165

166
  /**
167
   * Returns up to a year of past events for a given user or for the entire enterprise.
168
   *
169
   * <p>By default this returns events for the authenticated user. To retrieve events for the entire
170
   * enterprise, set the `stream_type` to `admin_logs_streaming` for live monitoring of new events,
171
   * or `admin_logs` for querying across historical events. The user making the API call will need
172
   * to have admin privileges, and the application will need to have the scope `manage enterprise
173
   * properties` checked.
174
   *
175
   * @param queryParams Query parameters of getEvents method
176
   * @param headers Headers of getEvents method
177
   */
178
  public Events getEvents(GetEventsQueryParams queryParams, GetEventsHeaders headers) {
179
    Map<String, String> queryParamsMap =
1✔
180
        prepareParams(
1✔
181
            mapOf(
1✔
182
                entryOf("stream_type", convertToString(queryParams.getStreamType())),
1✔
183
                entryOf("stream_position", convertToString(queryParams.getStreamPosition())),
1✔
184
                entryOf("limit", convertToString(queryParams.getLimit())),
1✔
185
                entryOf("event_type", convertToString(queryParams.getEventType())),
1✔
186
                entryOf("created_after", convertToString(queryParams.getCreatedAfter())),
1✔
187
                entryOf("created_before", convertToString(queryParams.getCreatedBefore()))));
1✔
188
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
189
    FetchResponse response =
1✔
190
        this.networkSession
191
            .getNetworkClient()
1✔
192
            .fetch(
1✔
193
                new FetchOptions.Builder(
194
                        String.join(
1✔
195
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/events"),
1✔
196
                        "GET")
197
                    .params(queryParamsMap)
1✔
198
                    .headers(headersMap)
1✔
199
                    .responseFormat(ResponseFormat.JSON)
1✔
200
                    .auth(this.auth)
1✔
201
                    .networkSession(this.networkSession)
1✔
202
                    .build());
1✔
203
    return JsonManager.deserialize(response.getData(), Events.class);
1✔
204
  }
205

206
  /** Get an event stream for the Box API */
207
  public EventStream getEventStream() {
208
    return getEventStream(new GetEventStreamQueryParams(), new GetEventStreamHeaders());
1✔
209
  }
210

211
  /**
212
   * Get an event stream for the Box API
213
   *
214
   * @param queryParams Query parameters of getEvents method
215
   */
216
  public EventStream getEventStream(GetEventStreamQueryParams queryParams) {
217
    return getEventStream(queryParams, new GetEventStreamHeaders());
×
218
  }
219

220
  /**
221
   * Get an event stream for the Box API
222
   *
223
   * @param headers Headers of getEvents method
224
   */
225
  public EventStream getEventStream(GetEventStreamHeaders headers) {
226
    return getEventStream(new GetEventStreamQueryParams(), headers);
×
227
  }
228

229
  /**
230
   * Get an event stream for the Box API
231
   *
232
   * @param queryParams Query parameters of getEvents method
233
   * @param headers Headers of getEvents method
234
   */
235
  public EventStream getEventStream(
236
      GetEventStreamQueryParams queryParams, GetEventStreamHeaders headers) {
237
    return new EventStream.Builder(this, queryParams).headersInput(headers).build();
1✔
238
  }
239

240
  public Authentication getAuth() {
241
    return auth;
×
242
  }
243

244
  public NetworkSession getNetworkSession() {
245
    return networkSession;
×
246
  }
247

248
  public static class Builder {
249

250
    protected Authentication auth;
251

252
    protected NetworkSession networkSession;
253

254
    public Builder() {
1✔
255
      this.networkSession = new NetworkSession();
1✔
256
    }
1✔
257

258
    public Builder auth(Authentication auth) {
259
      this.auth = auth;
1✔
260
      return this;
1✔
261
    }
262

263
    public Builder networkSession(NetworkSession networkSession) {
264
      this.networkSession = networkSession;
1✔
265
      return this;
1✔
266
    }
267

268
    public EventsManager build() {
269
      return new EventsManager(this);
1✔
270
    }
271
  }
272
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc