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

box / box-java-sdk-gen / #296

25 Jun 2025 10:12AM UTC coverage: 35.677% (-0.05%) from 35.723%
#296

Pull #348

github

web-flow
Merge d48b178e0 into d8480ee6c
Pull Request #348: chore: Update .codegen.json with commit hash of codegen and openapi spec

68 of 82 new or added lines in 2 files covered. (82.93%)

11820 existing lines in 631 files now uncovered.

16946 of 47499 relevant lines covered (35.68%)

0.36 hits per line

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

91.73
/src/main/java/com/box/sdkgen/managers/webhooks/WebhooksManager.java
1
package com.box.sdkgen.managers.webhooks;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.compareSignatures;
4
import static com.box.sdkgen.internal.utils.UtilsManager.computeWebhookSignature;
5
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
6
import static com.box.sdkgen.internal.utils.UtilsManager.dateTimeFromString;
7
import static com.box.sdkgen.internal.utils.UtilsManager.dateTimeToEpochSeconds;
8
import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
9
import static com.box.sdkgen.internal.utils.UtilsManager.getEpochTimeInSeconds;
10
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
11
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
12
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
13

14
import com.box.sdkgen.networking.auth.Authentication;
15
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
16
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
17
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
18
import com.box.sdkgen.networking.network.NetworkSession;
19
import com.box.sdkgen.schemas.webhook.Webhook;
20
import com.box.sdkgen.schemas.webhooks.Webhooks;
21
import com.box.sdkgen.serialization.json.JsonManager;
22
import java.util.Date;
23
import java.util.Map;
24

25
public class WebhooksManager {
26

27
  public Authentication auth;
28

29
  public NetworkSession networkSession;
30

31
  public WebhooksManager() {
×
32
    this.networkSession = new NetworkSession();
×
33
  }
×
34

35
  protected WebhooksManager(Builder builder) {
1✔
36
    this.auth = builder.auth;
1✔
37
    this.networkSession = builder.networkSession;
1✔
38
  }
1✔
39

40
  public Webhooks getWebhooks() {
41
    return getWebhooks(new GetWebhooksQueryParams(), new GetWebhooksHeaders());
1✔
42
  }
43

44
  public Webhooks getWebhooks(GetWebhooksQueryParams queryParams) {
45
    return getWebhooks(queryParams, new GetWebhooksHeaders());
×
46
  }
47

48
  public Webhooks getWebhooks(GetWebhooksHeaders headers) {
49
    return getWebhooks(new GetWebhooksQueryParams(), headers);
×
50
  }
51

52
  public Webhooks getWebhooks(GetWebhooksQueryParams queryParams, GetWebhooksHeaders headers) {
53
    Map<String, String> queryParamsMap =
1✔
54
        prepareParams(
1✔
55
            mapOf(
1✔
56
                entryOf("marker", convertToString(queryParams.getMarker())),
1✔
57
                entryOf("limit", convertToString(queryParams.getLimit()))));
1✔
58
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
59
    FetchResponse response =
1✔
60
        this.networkSession
61
            .getNetworkClient()
1✔
62
            .fetch(
1✔
63
                new FetchOptions.Builder(
64
                        String.join(
1✔
65
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/webhooks"),
1✔
66
                        "GET")
67
                    .params(queryParamsMap)
1✔
68
                    .headers(headersMap)
1✔
69
                    .responseFormat(ResponseFormat.JSON)
1✔
70
                    .auth(this.auth)
1✔
71
                    .networkSession(this.networkSession)
1✔
72
                    .build());
1✔
73
    return JsonManager.deserialize(response.getData(), Webhooks.class);
1✔
74
  }
75

76
  public Webhook createWebhook(CreateWebhookRequestBody requestBody) {
77
    return createWebhook(requestBody, new CreateWebhookHeaders());
1✔
78
  }
79

80
  public Webhook createWebhook(CreateWebhookRequestBody requestBody, CreateWebhookHeaders headers) {
81
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
82
    FetchResponse response =
1✔
83
        this.networkSession
84
            .getNetworkClient()
1✔
85
            .fetch(
1✔
86
                new FetchOptions.Builder(
87
                        String.join(
1✔
88
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/webhooks"),
1✔
89
                        "POST")
90
                    .headers(headersMap)
1✔
91
                    .data(JsonManager.serialize(requestBody))
1✔
92
                    .contentType("application/json")
1✔
93
                    .responseFormat(ResponseFormat.JSON)
1✔
94
                    .auth(this.auth)
1✔
95
                    .networkSession(this.networkSession)
1✔
96
                    .build());
1✔
97
    return JsonManager.deserialize(response.getData(), Webhook.class);
1✔
98
  }
99

100
  public Webhook getWebhookById(String webhookId) {
101
    return getWebhookById(webhookId, new GetWebhookByIdHeaders());
1✔
102
  }
103

104
  public Webhook getWebhookById(String webhookId, GetWebhookByIdHeaders headers) {
105
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
106
    FetchResponse response =
1✔
107
        this.networkSession
108
            .getNetworkClient()
1✔
109
            .fetch(
1✔
110
                new FetchOptions.Builder(
111
                        String.join(
1✔
112
                            "",
113
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
114
                            "/2.0/webhooks/",
115
                            convertToString(webhookId)),
1✔
116
                        "GET")
117
                    .headers(headersMap)
1✔
118
                    .responseFormat(ResponseFormat.JSON)
1✔
119
                    .auth(this.auth)
1✔
120
                    .networkSession(this.networkSession)
1✔
121
                    .build());
1✔
122
    return JsonManager.deserialize(response.getData(), Webhook.class);
1✔
123
  }
124

125
  public Webhook updateWebhookById(String webhookId) {
126
    return updateWebhookById(
×
127
        webhookId, new UpdateWebhookByIdRequestBody(), new UpdateWebhookByIdHeaders());
128
  }
129

130
  public Webhook updateWebhookById(String webhookId, UpdateWebhookByIdRequestBody requestBody) {
131
    return updateWebhookById(webhookId, requestBody, new UpdateWebhookByIdHeaders());
1✔
132
  }
133

134
  public Webhook updateWebhookById(String webhookId, UpdateWebhookByIdHeaders headers) {
135
    return updateWebhookById(webhookId, new UpdateWebhookByIdRequestBody(), headers);
×
136
  }
137

138
  public Webhook updateWebhookById(
139
      String webhookId,
140
      UpdateWebhookByIdRequestBody requestBody,
141
      UpdateWebhookByIdHeaders headers) {
142
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
143
    FetchResponse response =
1✔
144
        this.networkSession
145
            .getNetworkClient()
1✔
146
            .fetch(
1✔
147
                new FetchOptions.Builder(
148
                        String.join(
1✔
149
                            "",
150
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
151
                            "/2.0/webhooks/",
152
                            convertToString(webhookId)),
1✔
153
                        "PUT")
154
                    .headers(headersMap)
1✔
155
                    .data(JsonManager.serialize(requestBody))
1✔
156
                    .contentType("application/json")
1✔
157
                    .responseFormat(ResponseFormat.JSON)
1✔
158
                    .auth(this.auth)
1✔
159
                    .networkSession(this.networkSession)
1✔
160
                    .build());
1✔
161
    return JsonManager.deserialize(response.getData(), Webhook.class);
1✔
162
  }
163

164
  public void deleteWebhookById(String webhookId) {
165
    deleteWebhookById(webhookId, new DeleteWebhookByIdHeaders());
1✔
166
  }
1✔
167

168
  public void deleteWebhookById(String webhookId, DeleteWebhookByIdHeaders headers) {
169
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
170
    FetchResponse response =
1✔
171
        this.networkSession
172
            .getNetworkClient()
1✔
173
            .fetch(
1✔
174
                new FetchOptions.Builder(
175
                        String.join(
1✔
176
                            "",
177
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
178
                            "/2.0/webhooks/",
179
                            convertToString(webhookId)),
1✔
180
                        "DELETE")
181
                    .headers(headersMap)
1✔
182
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
183
                    .auth(this.auth)
1✔
184
                    .networkSession(this.networkSession)
1✔
185
                    .build());
1✔
186
  }
1✔
187

188
  public static boolean validateMessage(
189
      String body, Map<String, String> headers, String primaryKey) {
NEW
190
    return validateMessage(body, headers, primaryKey, null, 600);
×
191
  }
192

193
  public static boolean validateMessage(
194
      String body, Map<String, String> headers, String primaryKey, String secondaryKey) {
195
    return validateMessage(body, headers, primaryKey, secondaryKey, 600);
1✔
196
  }
197

198
  public static boolean validateMessage(
199
      String body, Map<String, String> headers, String primaryKey, Integer maxAge) {
NEW
200
    return validateMessage(body, headers, primaryKey, null, maxAge);
×
201
  }
202

203
  public static boolean validateMessage(
204
      String body,
205
      Map<String, String> headers,
206
      String primaryKey,
207
      String secondaryKey,
208
      Integer maxAge) {
209
    Date deliveryTimestamp = dateTimeFromString(headers.get("box-delivery-timestamp"));
1✔
210
    long currentEpoch = getEpochTimeInSeconds();
1✔
211
    if (currentEpoch - maxAge > dateTimeToEpochSeconds(deliveryTimestamp)
1✔
212
        || dateTimeToEpochSeconds(deliveryTimestamp) > currentEpoch) {
1✔
213
      return false;
1✔
214
    }
215
    if (!(primaryKey == null)
1✔
216
        && !(headers.get("box-signature-primary") == null)
1✔
217
        && compareSignatures(
1✔
218
            computeWebhookSignature(body, headers, primaryKey, false),
1✔
219
            headers.get("box-signature-primary"))) {
1✔
220
      return true;
1✔
221
    }
222
    if (!(primaryKey == null)
1✔
223
        && !(headers.get("box-signature-primary") == null)
1✔
224
        && compareSignatures(
1✔
225
            computeWebhookSignature(body, headers, primaryKey, true),
1✔
226
            headers.get("box-signature-primary"))) {
1✔
227
      return true;
1✔
228
    }
229
    if (!(secondaryKey == null)
1✔
230
        && !(headers.get("box-signature-secondary") == null)
1✔
231
        && compareSignatures(
1✔
232
            computeWebhookSignature(body, headers, secondaryKey, false),
1✔
233
            headers.get("box-signature-secondary"))) {
1✔
234
      return true;
1✔
235
    }
236
    if (!(secondaryKey == null)
1✔
237
        && !(headers.get("box-signature-secondary") == null)
1✔
238
        && compareSignatures(
1✔
239
            computeWebhookSignature(body, headers, secondaryKey, true),
1✔
240
            headers.get("box-signature-secondary"))) {
1✔
241
      return true;
1✔
242
    }
243
    return false;
1✔
244
  }
245

246
  public Authentication getAuth() {
247
    return auth;
×
248
  }
249

250
  public NetworkSession getNetworkSession() {
251
    return networkSession;
×
252
  }
253

254
  public static class Builder {
255

256
    protected Authentication auth;
257

258
    protected NetworkSession networkSession;
259

260
    public Builder() {
1✔
261
      this.networkSession = new NetworkSession();
1✔
262
    }
1✔
263

264
    public Builder auth(Authentication auth) {
265
      this.auth = auth;
1✔
266
      return this;
1✔
267
    }
268

269
    public Builder networkSession(NetworkSession networkSession) {
270
      this.networkSession = networkSession;
1✔
271
      return this;
1✔
272
    }
273

274
    public WebhooksManager build() {
275
      return new WebhooksManager(this);
1✔
276
    }
277
  }
278
}
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