001package com.box.sdkgen.managers.sharedlinksfiles;
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.filefull.FileFull;
015import com.box.sdkgen.serialization.json.JsonManager;
016import java.util.Map;
017
018public class SharedLinksFilesManager {
019
020  public Authentication auth;
021
022  public NetworkSession networkSession;
023
024  public SharedLinksFilesManager() {
025    this.networkSession = new NetworkSession();
026  }
027
028  protected SharedLinksFilesManager(Builder builder) {
029    this.auth = builder.auth;
030    this.networkSession = builder.networkSession;
031  }
032
033  /**
034   * Returns the file represented by a shared link.
035   *
036   * <p>A shared file can be represented by a shared link, which can originate within the current
037   * enterprise or within another.
038   *
039   * <p>This endpoint allows an application to retrieve information about a shared file when only
040   * given a shared link.
041   *
042   * <p>The `shared_link_permission_options` array field can be returned by requesting it in the
043   * `fields` query parameter.
044   *
045   * @param headers Headers of findFileForSharedLink method
046   */
047  public FileFull findFileForSharedLink(FindFileForSharedLinkHeaders headers) {
048    return findFileForSharedLink(new FindFileForSharedLinkQueryParams(), headers);
049  }
050
051  /**
052   * Returns the file represented by a shared link.
053   *
054   * <p>A shared file can be represented by a shared link, which can originate within the current
055   * enterprise or within another.
056   *
057   * <p>This endpoint allows an application to retrieve information about a shared file when only
058   * given a shared link.
059   *
060   * <p>The `shared_link_permission_options` array field can be returned by requesting it in the
061   * `fields` query parameter.
062   *
063   * @param queryParams Query parameters of findFileForSharedLink method
064   * @param headers Headers of findFileForSharedLink method
065   */
066  public FileFull findFileForSharedLink(
067      FindFileForSharedLinkQueryParams queryParams, FindFileForSharedLinkHeaders headers) {
068    Map<String, String> queryParamsMap =
069        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
070    Map<String, String> headersMap =
071        prepareParams(
072            mergeMaps(
073                mapOf(
074                    entryOf("if-none-match", convertToString(headers.getIfNoneMatch())),
075                    entryOf("boxapi", convertToString(headers.getBoxapi()))),
076                headers.getExtraHeaders()));
077    FetchResponse response =
078        this.networkSession
079            .getNetworkClient()
080            .fetch(
081                new FetchOptions.Builder(
082                        String.join(
083                            "",
084                            this.networkSession.getBaseUrls().getBaseUrl(),
085                            "/2.0/shared_items"),
086                        "GET")
087                    .params(queryParamsMap)
088                    .headers(headersMap)
089                    .responseFormat(ResponseFormat.JSON)
090                    .auth(this.auth)
091                    .networkSession(this.networkSession)
092                    .build());
093    return JsonManager.deserialize(response.getData(), FileFull.class);
094  }
095
096  /**
097   * Gets the information for a shared link on a file.
098   *
099   * @param fileId The unique identifier that represents a file.
100   *     <p>The ID for any file can be determined by visiting a file in the web application and
101   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
102   *     `file_id` is `123`. Example: "12345"
103   * @param queryParams Query parameters of getSharedLinkForFile method
104   */
105  public FileFull getSharedLinkForFile(String fileId, GetSharedLinkForFileQueryParams queryParams) {
106    return getSharedLinkForFile(fileId, queryParams, new GetSharedLinkForFileHeaders());
107  }
108
109  /**
110   * Gets the information for a shared link on a file.
111   *
112   * @param fileId The unique identifier that represents a file.
113   *     <p>The ID for any file can be determined by visiting a file in the web application and
114   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
115   *     `file_id` is `123`. Example: "12345"
116   * @param queryParams Query parameters of getSharedLinkForFile method
117   * @param headers Headers of getSharedLinkForFile method
118   */
119  public FileFull getSharedLinkForFile(
120      String fileId,
121      GetSharedLinkForFileQueryParams queryParams,
122      GetSharedLinkForFileHeaders headers) {
123    Map<String, String> queryParamsMap =
124        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
125    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
126    FetchResponse response =
127        this.networkSession
128            .getNetworkClient()
129            .fetch(
130                new FetchOptions.Builder(
131                        String.join(
132                            "",
133                            this.networkSession.getBaseUrls().getBaseUrl(),
134                            "/2.0/files/",
135                            convertToString(fileId),
136                            "#get_shared_link"),
137                        "GET")
138                    .params(queryParamsMap)
139                    .headers(headersMap)
140                    .responseFormat(ResponseFormat.JSON)
141                    .auth(this.auth)
142                    .networkSession(this.networkSession)
143                    .build());
144    return JsonManager.deserialize(response.getData(), FileFull.class);
145  }
146
147  /**
148   * Adds a shared link to a file.
149   *
150   * @param fileId The unique identifier that represents a file.
151   *     <p>The ID for any file can be determined by visiting a file in the web application and
152   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
153   *     `file_id` is `123`. Example: "12345"
154   * @param queryParams Query parameters of addShareLinkToFile method
155   */
156  public FileFull addShareLinkToFile(String fileId, AddShareLinkToFileQueryParams queryParams) {
157    return addShareLinkToFile(
158        fileId, new AddShareLinkToFileRequestBody(), queryParams, new AddShareLinkToFileHeaders());
159  }
160
161  /**
162   * Adds a shared link to a file.
163   *
164   * @param fileId The unique identifier that represents a file.
165   *     <p>The ID for any file can be determined by visiting a file in the web application and
166   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
167   *     `file_id` is `123`. Example: "12345"
168   * @param requestBody Request body of addShareLinkToFile method
169   * @param queryParams Query parameters of addShareLinkToFile method
170   */
171  public FileFull addShareLinkToFile(
172      String fileId,
173      AddShareLinkToFileRequestBody requestBody,
174      AddShareLinkToFileQueryParams queryParams) {
175    return addShareLinkToFile(fileId, requestBody, queryParams, new AddShareLinkToFileHeaders());
176  }
177
178  /**
179   * Adds a shared link to a file.
180   *
181   * @param fileId The unique identifier that represents a file.
182   *     <p>The ID for any file can be determined by visiting a file in the web application and
183   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
184   *     `file_id` is `123`. Example: "12345"
185   * @param queryParams Query parameters of addShareLinkToFile method
186   * @param headers Headers of addShareLinkToFile method
187   */
188  public FileFull addShareLinkToFile(
189      String fileId, AddShareLinkToFileQueryParams queryParams, AddShareLinkToFileHeaders headers) {
190    return addShareLinkToFile(fileId, new AddShareLinkToFileRequestBody(), queryParams, headers);
191  }
192
193  /**
194   * Adds a shared link to a file.
195   *
196   * @param fileId The unique identifier that represents a file.
197   *     <p>The ID for any file can be determined by visiting a file in the web application and
198   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
199   *     `file_id` is `123`. Example: "12345"
200   * @param requestBody Request body of addShareLinkToFile method
201   * @param queryParams Query parameters of addShareLinkToFile method
202   * @param headers Headers of addShareLinkToFile method
203   */
204  public FileFull addShareLinkToFile(
205      String fileId,
206      AddShareLinkToFileRequestBody requestBody,
207      AddShareLinkToFileQueryParams queryParams,
208      AddShareLinkToFileHeaders headers) {
209    Map<String, String> queryParamsMap =
210        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
211    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
212    FetchResponse response =
213        this.networkSession
214            .getNetworkClient()
215            .fetch(
216                new FetchOptions.Builder(
217                        String.join(
218                            "",
219                            this.networkSession.getBaseUrls().getBaseUrl(),
220                            "/2.0/files/",
221                            convertToString(fileId),
222                            "#add_shared_link"),
223                        "PUT")
224                    .params(queryParamsMap)
225                    .headers(headersMap)
226                    .data(JsonManager.serialize(requestBody))
227                    .contentType("application/json")
228                    .responseFormat(ResponseFormat.JSON)
229                    .auth(this.auth)
230                    .networkSession(this.networkSession)
231                    .build());
232    return JsonManager.deserialize(response.getData(), FileFull.class);
233  }
234
235  /**
236   * Updates a shared link on a file.
237   *
238   * @param fileId The unique identifier that represents a file.
239   *     <p>The ID for any file can be determined by visiting a file in the web application and
240   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
241   *     `file_id` is `123`. Example: "12345"
242   * @param queryParams Query parameters of updateSharedLinkOnFile method
243   */
244  public FileFull updateSharedLinkOnFile(
245      String fileId, UpdateSharedLinkOnFileQueryParams queryParams) {
246    return updateSharedLinkOnFile(
247        fileId,
248        new UpdateSharedLinkOnFileRequestBody(),
249        queryParams,
250        new UpdateSharedLinkOnFileHeaders());
251  }
252
253  /**
254   * Updates a shared link on a file.
255   *
256   * @param fileId The unique identifier that represents a file.
257   *     <p>The ID for any file can be determined by visiting a file in the web application and
258   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
259   *     `file_id` is `123`. Example: "12345"
260   * @param requestBody Request body of updateSharedLinkOnFile method
261   * @param queryParams Query parameters of updateSharedLinkOnFile method
262   */
263  public FileFull updateSharedLinkOnFile(
264      String fileId,
265      UpdateSharedLinkOnFileRequestBody requestBody,
266      UpdateSharedLinkOnFileQueryParams queryParams) {
267    return updateSharedLinkOnFile(
268        fileId, requestBody, queryParams, new UpdateSharedLinkOnFileHeaders());
269  }
270
271  /**
272   * Updates a shared link on a file.
273   *
274   * @param fileId The unique identifier that represents a file.
275   *     <p>The ID for any file can be determined by visiting a file in the web application and
276   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
277   *     `file_id` is `123`. Example: "12345"
278   * @param queryParams Query parameters of updateSharedLinkOnFile method
279   * @param headers Headers of updateSharedLinkOnFile method
280   */
281  public FileFull updateSharedLinkOnFile(
282      String fileId,
283      UpdateSharedLinkOnFileQueryParams queryParams,
284      UpdateSharedLinkOnFileHeaders headers) {
285    return updateSharedLinkOnFile(
286        fileId, new UpdateSharedLinkOnFileRequestBody(), queryParams, headers);
287  }
288
289  /**
290   * Updates a shared link on a file.
291   *
292   * @param fileId The unique identifier that represents a file.
293   *     <p>The ID for any file can be determined by visiting a file in the web application and
294   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
295   *     `file_id` is `123`. Example: "12345"
296   * @param requestBody Request body of updateSharedLinkOnFile method
297   * @param queryParams Query parameters of updateSharedLinkOnFile method
298   * @param headers Headers of updateSharedLinkOnFile method
299   */
300  public FileFull updateSharedLinkOnFile(
301      String fileId,
302      UpdateSharedLinkOnFileRequestBody requestBody,
303      UpdateSharedLinkOnFileQueryParams queryParams,
304      UpdateSharedLinkOnFileHeaders headers) {
305    Map<String, String> queryParamsMap =
306        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
307    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
308    FetchResponse response =
309        this.networkSession
310            .getNetworkClient()
311            .fetch(
312                new FetchOptions.Builder(
313                        String.join(
314                            "",
315                            this.networkSession.getBaseUrls().getBaseUrl(),
316                            "/2.0/files/",
317                            convertToString(fileId),
318                            "#update_shared_link"),
319                        "PUT")
320                    .params(queryParamsMap)
321                    .headers(headersMap)
322                    .data(JsonManager.serialize(requestBody))
323                    .contentType("application/json")
324                    .responseFormat(ResponseFormat.JSON)
325                    .auth(this.auth)
326                    .networkSession(this.networkSession)
327                    .build());
328    return JsonManager.deserialize(response.getData(), FileFull.class);
329  }
330
331  /**
332   * Removes a shared link from a file.
333   *
334   * @param fileId The unique identifier that represents a file.
335   *     <p>The ID for any file can be determined by visiting a file in the web application and
336   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
337   *     `file_id` is `123`. Example: "12345"
338   * @param queryParams Query parameters of removeSharedLinkFromFile method
339   */
340  public FileFull removeSharedLinkFromFile(
341      String fileId, RemoveSharedLinkFromFileQueryParams queryParams) {
342    return removeSharedLinkFromFile(
343        fileId,
344        new RemoveSharedLinkFromFileRequestBody(),
345        queryParams,
346        new RemoveSharedLinkFromFileHeaders());
347  }
348
349  /**
350   * Removes a shared link from a file.
351   *
352   * @param fileId The unique identifier that represents a file.
353   *     <p>The ID for any file can be determined by visiting a file in the web application and
354   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
355   *     `file_id` is `123`. Example: "12345"
356   * @param requestBody Request body of removeSharedLinkFromFile method
357   * @param queryParams Query parameters of removeSharedLinkFromFile method
358   */
359  public FileFull removeSharedLinkFromFile(
360      String fileId,
361      RemoveSharedLinkFromFileRequestBody requestBody,
362      RemoveSharedLinkFromFileQueryParams queryParams) {
363    return removeSharedLinkFromFile(
364        fileId, requestBody, queryParams, new RemoveSharedLinkFromFileHeaders());
365  }
366
367  /**
368   * Removes a shared link from a file.
369   *
370   * @param fileId The unique identifier that represents a file.
371   *     <p>The ID for any file can be determined by visiting a file in the web application and
372   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
373   *     `file_id` is `123`. Example: "12345"
374   * @param queryParams Query parameters of removeSharedLinkFromFile method
375   * @param headers Headers of removeSharedLinkFromFile method
376   */
377  public FileFull removeSharedLinkFromFile(
378      String fileId,
379      RemoveSharedLinkFromFileQueryParams queryParams,
380      RemoveSharedLinkFromFileHeaders headers) {
381    return removeSharedLinkFromFile(
382        fileId, new RemoveSharedLinkFromFileRequestBody(), queryParams, headers);
383  }
384
385  /**
386   * Removes a shared link from a file.
387   *
388   * @param fileId The unique identifier that represents a file.
389   *     <p>The ID for any file can be determined by visiting a file in the web application and
390   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
391   *     `file_id` is `123`. Example: "12345"
392   * @param requestBody Request body of removeSharedLinkFromFile method
393   * @param queryParams Query parameters of removeSharedLinkFromFile method
394   * @param headers Headers of removeSharedLinkFromFile method
395   */
396  public FileFull removeSharedLinkFromFile(
397      String fileId,
398      RemoveSharedLinkFromFileRequestBody requestBody,
399      RemoveSharedLinkFromFileQueryParams queryParams,
400      RemoveSharedLinkFromFileHeaders headers) {
401    Map<String, String> queryParamsMap =
402        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
403    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
404    FetchResponse response =
405        this.networkSession
406            .getNetworkClient()
407            .fetch(
408                new FetchOptions.Builder(
409                        String.join(
410                            "",
411                            this.networkSession.getBaseUrls().getBaseUrl(),
412                            "/2.0/files/",
413                            convertToString(fileId),
414                            "#remove_shared_link"),
415                        "PUT")
416                    .params(queryParamsMap)
417                    .headers(headersMap)
418                    .data(JsonManager.serialize(requestBody))
419                    .contentType("application/json")
420                    .responseFormat(ResponseFormat.JSON)
421                    .auth(this.auth)
422                    .networkSession(this.networkSession)
423                    .build());
424    return JsonManager.deserialize(response.getData(), FileFull.class);
425  }
426
427  public Authentication getAuth() {
428    return auth;
429  }
430
431  public NetworkSession getNetworkSession() {
432    return networkSession;
433  }
434
435  public static class Builder {
436
437    protected Authentication auth;
438
439    protected NetworkSession networkSession;
440
441    public Builder() {}
442
443    public Builder auth(Authentication auth) {
444      this.auth = auth;
445      return this;
446    }
447
448    public Builder networkSession(NetworkSession networkSession) {
449      this.networkSession = networkSession;
450      return this;
451    }
452
453    public SharedLinksFilesManager build() {
454      if (this.networkSession == null) {
455        this.networkSession = new NetworkSession();
456      }
457      return new SharedLinksFilesManager(this);
458    }
459  }
460}