001package com.box.sdkgen.managers.hubs;
002
003import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
004import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
005import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
006import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
007import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
008
009import com.box.sdkgen.networking.auth.Authentication;
010import com.box.sdkgen.networking.fetchoptions.FetchOptions;
011import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
012import com.box.sdkgen.networking.fetchresponse.FetchResponse;
013import com.box.sdkgen.networking.network.NetworkSession;
014import com.box.sdkgen.schemas.v2025r0.hubcopyrequestv2025r0.HubCopyRequestV2025R0;
015import com.box.sdkgen.schemas.v2025r0.hubcreaterequestv2025r0.HubCreateRequestV2025R0;
016import com.box.sdkgen.schemas.v2025r0.hubsv2025r0.HubsV2025R0;
017import com.box.sdkgen.schemas.v2025r0.hubupdaterequestv2025r0.HubUpdateRequestV2025R0;
018import com.box.sdkgen.schemas.v2025r0.hubv2025r0.HubV2025R0;
019import com.box.sdkgen.serialization.json.JsonManager;
020import java.util.Map;
021
022public class HubsManager {
023
024  public Authentication auth;
025
026  public NetworkSession networkSession;
027
028  public HubsManager() {
029    this.networkSession = new NetworkSession();
030  }
031
032  protected HubsManager(Builder builder) {
033    this.auth = builder.auth;
034    this.networkSession = builder.networkSession;
035  }
036
037  /** Retrieves all Box Hubs for requesting user. */
038  public HubsV2025R0 getHubsV2025R0() {
039    return getHubsV2025R0(new GetHubsV2025R0QueryParams(), new GetHubsV2025R0Headers());
040  }
041
042  /**
043   * Retrieves all Box Hubs for requesting user.
044   *
045   * @param queryParams Query parameters of getHubsV2025R0 method
046   */
047  public HubsV2025R0 getHubsV2025R0(GetHubsV2025R0QueryParams queryParams) {
048    return getHubsV2025R0(queryParams, new GetHubsV2025R0Headers());
049  }
050
051  /**
052   * Retrieves all Box Hubs for requesting user.
053   *
054   * @param headers Headers of getHubsV2025R0 method
055   */
056  public HubsV2025R0 getHubsV2025R0(GetHubsV2025R0Headers headers) {
057    return getHubsV2025R0(new GetHubsV2025R0QueryParams(), headers);
058  }
059
060  /**
061   * Retrieves all Box Hubs for requesting user.
062   *
063   * @param queryParams Query parameters of getHubsV2025R0 method
064   * @param headers Headers of getHubsV2025R0 method
065   */
066  public HubsV2025R0 getHubsV2025R0(
067      GetHubsV2025R0QueryParams queryParams, GetHubsV2025R0Headers headers) {
068    Map<String, String> queryParamsMap =
069        prepareParams(
070            mapOf(
071                entryOf("query", convertToString(queryParams.getQuery())),
072                entryOf("scope", convertToString(queryParams.getScope())),
073                entryOf("sort", convertToString(queryParams.getSort())),
074                entryOf("direction", convertToString(queryParams.getDirection())),
075                entryOf("marker", convertToString(queryParams.getMarker())),
076                entryOf("limit", convertToString(queryParams.getLimit()))));
077    Map<String, String> headersMap =
078        prepareParams(
079            mergeMaps(
080                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
081                headers.getExtraHeaders()));
082    FetchResponse response =
083        this.networkSession
084            .getNetworkClient()
085            .fetch(
086                new FetchOptions.Builder(
087                        String.join(
088                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/hubs"),
089                        "GET")
090                    .params(queryParamsMap)
091                    .headers(headersMap)
092                    .responseFormat(ResponseFormat.JSON)
093                    .auth(this.auth)
094                    .networkSession(this.networkSession)
095                    .build());
096    return JsonManager.deserialize(response.getData(), HubsV2025R0.class);
097  }
098
099  /**
100   * Creates a new Box Hub.
101   *
102   * @param requestBody Request body of createHubV2025R0 method
103   */
104  public HubV2025R0 createHubV2025R0(HubCreateRequestV2025R0 requestBody) {
105    return createHubV2025R0(requestBody, new CreateHubV2025R0Headers());
106  }
107
108  /**
109   * Creates a new Box Hub.
110   *
111   * @param requestBody Request body of createHubV2025R0 method
112   * @param headers Headers of createHubV2025R0 method
113   */
114  public HubV2025R0 createHubV2025R0(
115      HubCreateRequestV2025R0 requestBody, CreateHubV2025R0Headers headers) {
116    Map<String, String> headersMap =
117        prepareParams(
118            mergeMaps(
119                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
120                headers.getExtraHeaders()));
121    FetchResponse response =
122        this.networkSession
123            .getNetworkClient()
124            .fetch(
125                new FetchOptions.Builder(
126                        String.join(
127                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/hubs"),
128                        "POST")
129                    .headers(headersMap)
130                    .data(JsonManager.serialize(requestBody))
131                    .contentType("application/json")
132                    .responseFormat(ResponseFormat.JSON)
133                    .auth(this.auth)
134                    .networkSession(this.networkSession)
135                    .build());
136    return JsonManager.deserialize(response.getData(), HubV2025R0.class);
137  }
138
139  /**
140   * Retrieves all Box Hubs for a given enterprise.
141   *
142   * <p>Admins or Hub Co-admins of an enterprise with GCM scope can make this call.
143   */
144  public HubsV2025R0 getEnterpriseHubsV2025R0() {
145    return getEnterpriseHubsV2025R0(
146        new GetEnterpriseHubsV2025R0QueryParams(), new GetEnterpriseHubsV2025R0Headers());
147  }
148
149  /**
150   * Retrieves all Box Hubs for a given enterprise.
151   *
152   * <p>Admins or Hub Co-admins of an enterprise with GCM scope can make this call.
153   *
154   * @param queryParams Query parameters of getEnterpriseHubsV2025R0 method
155   */
156  public HubsV2025R0 getEnterpriseHubsV2025R0(GetEnterpriseHubsV2025R0QueryParams queryParams) {
157    return getEnterpriseHubsV2025R0(queryParams, new GetEnterpriseHubsV2025R0Headers());
158  }
159
160  /**
161   * Retrieves all Box Hubs for a given enterprise.
162   *
163   * <p>Admins or Hub Co-admins of an enterprise with GCM scope can make this call.
164   *
165   * @param headers Headers of getEnterpriseHubsV2025R0 method
166   */
167  public HubsV2025R0 getEnterpriseHubsV2025R0(GetEnterpriseHubsV2025R0Headers headers) {
168    return getEnterpriseHubsV2025R0(new GetEnterpriseHubsV2025R0QueryParams(), headers);
169  }
170
171  /**
172   * Retrieves all Box Hubs for a given enterprise.
173   *
174   * <p>Admins or Hub Co-admins of an enterprise with GCM scope can make this call.
175   *
176   * @param queryParams Query parameters of getEnterpriseHubsV2025R0 method
177   * @param headers Headers of getEnterpriseHubsV2025R0 method
178   */
179  public HubsV2025R0 getEnterpriseHubsV2025R0(
180      GetEnterpriseHubsV2025R0QueryParams queryParams, GetEnterpriseHubsV2025R0Headers headers) {
181    Map<String, String> queryParamsMap =
182        prepareParams(
183            mapOf(
184                entryOf("query", convertToString(queryParams.getQuery())),
185                entryOf("sort", convertToString(queryParams.getSort())),
186                entryOf("direction", convertToString(queryParams.getDirection())),
187                entryOf("marker", convertToString(queryParams.getMarker())),
188                entryOf("limit", convertToString(queryParams.getLimit()))));
189    Map<String, String> headersMap =
190        prepareParams(
191            mergeMaps(
192                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
193                headers.getExtraHeaders()));
194    FetchResponse response =
195        this.networkSession
196            .getNetworkClient()
197            .fetch(
198                new FetchOptions.Builder(
199                        String.join(
200                            "",
201                            this.networkSession.getBaseUrls().getBaseUrl(),
202                            "/2.0/enterprise_hubs"),
203                        "GET")
204                    .params(queryParamsMap)
205                    .headers(headersMap)
206                    .responseFormat(ResponseFormat.JSON)
207                    .auth(this.auth)
208                    .networkSession(this.networkSession)
209                    .build());
210    return JsonManager.deserialize(response.getData(), HubsV2025R0.class);
211  }
212
213  /**
214   * Retrieves details for a Box Hub by its ID.
215   *
216   * @param hubId The unique identifier that represent a hub.
217   *     <p>The ID for any hub can be determined by visiting this hub in the web application and
218   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/hubs/123` the
219   *     `hub_id` is `123`. Example: "12345"
220   */
221  public HubV2025R0 getHubByIdV2025R0(String hubId) {
222    return getHubByIdV2025R0(hubId, new GetHubByIdV2025R0Headers());
223  }
224
225  /**
226   * Retrieves details for a Box Hub by its ID.
227   *
228   * @param hubId The unique identifier that represent a hub.
229   *     <p>The ID for any hub can be determined by visiting this hub in the web application and
230   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/hubs/123` the
231   *     `hub_id` is `123`. Example: "12345"
232   * @param headers Headers of getHubByIdV2025R0 method
233   */
234  public HubV2025R0 getHubByIdV2025R0(String hubId, GetHubByIdV2025R0Headers headers) {
235    Map<String, String> headersMap =
236        prepareParams(
237            mergeMaps(
238                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
239                headers.getExtraHeaders()));
240    FetchResponse response =
241        this.networkSession
242            .getNetworkClient()
243            .fetch(
244                new FetchOptions.Builder(
245                        String.join(
246                            "",
247                            this.networkSession.getBaseUrls().getBaseUrl(),
248                            "/2.0/hubs/",
249                            convertToString(hubId)),
250                        "GET")
251                    .headers(headersMap)
252                    .responseFormat(ResponseFormat.JSON)
253                    .auth(this.auth)
254                    .networkSession(this.networkSession)
255                    .build());
256    return JsonManager.deserialize(response.getData(), HubV2025R0.class);
257  }
258
259  /**
260   * Updates a Box Hub. Can be used to change title, description, or Box Hub settings.
261   *
262   * @param hubId The unique identifier that represent a hub.
263   *     <p>The ID for any hub can be determined by visiting this hub in the web application and
264   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/hubs/123` the
265   *     `hub_id` is `123`. Example: "12345"
266   * @param requestBody Request body of updateHubByIdV2025R0 method
267   */
268  public HubV2025R0 updateHubByIdV2025R0(String hubId, HubUpdateRequestV2025R0 requestBody) {
269    return updateHubByIdV2025R0(hubId, requestBody, new UpdateHubByIdV2025R0Headers());
270  }
271
272  /**
273   * Updates a Box Hub. Can be used to change title, description, or Box Hub settings.
274   *
275   * @param hubId The unique identifier that represent a hub.
276   *     <p>The ID for any hub can be determined by visiting this hub in the web application and
277   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/hubs/123` the
278   *     `hub_id` is `123`. Example: "12345"
279   * @param requestBody Request body of updateHubByIdV2025R0 method
280   * @param headers Headers of updateHubByIdV2025R0 method
281   */
282  public HubV2025R0 updateHubByIdV2025R0(
283      String hubId, HubUpdateRequestV2025R0 requestBody, UpdateHubByIdV2025R0Headers headers) {
284    Map<String, String> headersMap =
285        prepareParams(
286            mergeMaps(
287                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
288                headers.getExtraHeaders()));
289    FetchResponse response =
290        this.networkSession
291            .getNetworkClient()
292            .fetch(
293                new FetchOptions.Builder(
294                        String.join(
295                            "",
296                            this.networkSession.getBaseUrls().getBaseUrl(),
297                            "/2.0/hubs/",
298                            convertToString(hubId)),
299                        "PUT")
300                    .headers(headersMap)
301                    .data(JsonManager.serialize(requestBody))
302                    .contentType("application/json")
303                    .responseFormat(ResponseFormat.JSON)
304                    .auth(this.auth)
305                    .networkSession(this.networkSession)
306                    .build());
307    return JsonManager.deserialize(response.getData(), HubV2025R0.class);
308  }
309
310  /**
311   * Deletes a single Box Hub.
312   *
313   * @param hubId The unique identifier that represent a hub.
314   *     <p>The ID for any hub can be determined by visiting this hub in the web application and
315   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/hubs/123` the
316   *     `hub_id` is `123`. Example: "12345"
317   */
318  public void deleteHubByIdV2025R0(String hubId) {
319    deleteHubByIdV2025R0(hubId, new DeleteHubByIdV2025R0Headers());
320  }
321
322  /**
323   * Deletes a single Box Hub.
324   *
325   * @param hubId The unique identifier that represent a hub.
326   *     <p>The ID for any hub can be determined by visiting this hub in the web application and
327   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/hubs/123` the
328   *     `hub_id` is `123`. Example: "12345"
329   * @param headers Headers of deleteHubByIdV2025R0 method
330   */
331  public void deleteHubByIdV2025R0(String hubId, DeleteHubByIdV2025R0Headers headers) {
332    Map<String, String> headersMap =
333        prepareParams(
334            mergeMaps(
335                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
336                headers.getExtraHeaders()));
337    FetchResponse response =
338        this.networkSession
339            .getNetworkClient()
340            .fetch(
341                new FetchOptions.Builder(
342                        String.join(
343                            "",
344                            this.networkSession.getBaseUrls().getBaseUrl(),
345                            "/2.0/hubs/",
346                            convertToString(hubId)),
347                        "DELETE")
348                    .headers(headersMap)
349                    .responseFormat(ResponseFormat.NO_CONTENT)
350                    .auth(this.auth)
351                    .networkSession(this.networkSession)
352                    .build());
353  }
354
355  /**
356   * Creates a copy of a Box Hub.
357   *
358   * <p>The original Box Hub will not be modified.
359   *
360   * @param hubId The unique identifier that represent a hub.
361   *     <p>The ID for any hub can be determined by visiting this hub in the web application and
362   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/hubs/123` the
363   *     `hub_id` is `123`. Example: "12345"
364   * @param requestBody Request body of copyHubV2025R0 method
365   */
366  public HubV2025R0 copyHubV2025R0(String hubId, HubCopyRequestV2025R0 requestBody) {
367    return copyHubV2025R0(hubId, requestBody, new CopyHubV2025R0Headers());
368  }
369
370  /**
371   * Creates a copy of a Box Hub.
372   *
373   * <p>The original Box Hub will not be modified.
374   *
375   * @param hubId The unique identifier that represent a hub.
376   *     <p>The ID for any hub can be determined by visiting this hub in the web application and
377   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/hubs/123` the
378   *     `hub_id` is `123`. Example: "12345"
379   * @param requestBody Request body of copyHubV2025R0 method
380   * @param headers Headers of copyHubV2025R0 method
381   */
382  public HubV2025R0 copyHubV2025R0(
383      String hubId, HubCopyRequestV2025R0 requestBody, CopyHubV2025R0Headers headers) {
384    Map<String, String> headersMap =
385        prepareParams(
386            mergeMaps(
387                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
388                headers.getExtraHeaders()));
389    FetchResponse response =
390        this.networkSession
391            .getNetworkClient()
392            .fetch(
393                new FetchOptions.Builder(
394                        String.join(
395                            "",
396                            this.networkSession.getBaseUrls().getBaseUrl(),
397                            "/2.0/hubs/",
398                            convertToString(hubId),
399                            "/copy"),
400                        "POST")
401                    .headers(headersMap)
402                    .data(JsonManager.serialize(requestBody))
403                    .contentType("application/json")
404                    .responseFormat(ResponseFormat.JSON)
405                    .auth(this.auth)
406                    .networkSession(this.networkSession)
407                    .build());
408    return JsonManager.deserialize(response.getData(), HubV2025R0.class);
409  }
410
411  public Authentication getAuth() {
412    return auth;
413  }
414
415  public NetworkSession getNetworkSession() {
416    return networkSession;
417  }
418
419  public static class Builder {
420
421    protected Authentication auth;
422
423    protected NetworkSession networkSession;
424
425    public Builder() {}
426
427    public Builder auth(Authentication auth) {
428      this.auth = auth;
429      return this;
430    }
431
432    public Builder networkSession(NetworkSession networkSession) {
433      this.networkSession = networkSession;
434      return this;
435    }
436
437    public HubsManager build() {
438      if (this.networkSession == null) {
439        this.networkSession = new NetworkSession();
440      }
441      return new HubsManager(this);
442    }
443  }
444}