001package com.box.sdkgen.managers.sharedlinksappitems;
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.appitem.AppItem;
015import com.box.sdkgen.serialization.json.JsonManager;
016import java.util.Map;
017
018public class SharedLinksAppItemsManager {
019
020  public Authentication auth;
021
022  public NetworkSession networkSession;
023
024  public SharedLinksAppItemsManager() {
025    this.networkSession = new NetworkSession();
026  }
027
028  protected SharedLinksAppItemsManager(Builder builder) {
029    this.auth = builder.auth;
030    this.networkSession = builder.networkSession;
031  }
032
033  /**
034   * Returns the app item represented by a shared link.
035   *
036   * <p>The link can originate from the current enterprise or another.
037   *
038   * @param headers Headers of findAppItemForSharedLink method
039   */
040  public AppItem findAppItemForSharedLink(FindAppItemForSharedLinkHeaders headers) {
041    Map<String, String> headersMap =
042        prepareParams(
043            mergeMaps(
044                mapOf(entryOf("boxapi", convertToString(headers.getBoxapi()))),
045                headers.getExtraHeaders()));
046    FetchResponse response =
047        this.networkSession
048            .getNetworkClient()
049            .fetch(
050                new FetchOptions.Builder(
051                        String.join(
052                            "",
053                            this.networkSession.getBaseUrls().getBaseUrl(),
054                            "/2.0/shared_items#app_items"),
055                        "GET")
056                    .headers(headersMap)
057                    .responseFormat(ResponseFormat.JSON)
058                    .auth(this.auth)
059                    .networkSession(this.networkSession)
060                    .build());
061    return JsonManager.deserialize(response.getData(), AppItem.class);
062  }
063
064  public Authentication getAuth() {
065    return auth;
066  }
067
068  public NetworkSession getNetworkSession() {
069    return networkSession;
070  }
071
072  public static class Builder {
073
074    protected Authentication auth;
075
076    protected NetworkSession networkSession;
077
078    public Builder() {}
079
080    public Builder auth(Authentication auth) {
081      this.auth = auth;
082      return this;
083    }
084
085    public Builder networkSession(NetworkSession networkSession) {
086      this.networkSession = networkSession;
087      return this;
088    }
089
090    public SharedLinksAppItemsManager build() {
091      if (this.networkSession == null) {
092        this.networkSession = new NetworkSession();
093      }
094      return new SharedLinksAppItemsManager(this);
095    }
096  }
097}