001package com.box.sdkgen.managers.devicepinners;
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.devicepinner.DevicePinner;
015import com.box.sdkgen.schemas.devicepinners.DevicePinners;
016import com.box.sdkgen.serialization.json.JsonManager;
017import java.util.Map;
018
019public class DevicePinnersManager {
020
021  public Authentication auth;
022
023  public NetworkSession networkSession;
024
025  public DevicePinnersManager() {
026    this.networkSession = new NetworkSession();
027  }
028
029  protected DevicePinnersManager(Builder builder) {
030    this.auth = builder.auth;
031    this.networkSession = builder.networkSession;
032  }
033
034  /**
035   * Retrieves information about an individual device pin.
036   *
037   * @param devicePinnerId The ID of the device pin. Example: "2324234"
038   */
039  public DevicePinner getDevicePinnerById(String devicePinnerId) {
040    return getDevicePinnerById(devicePinnerId, new GetDevicePinnerByIdHeaders());
041  }
042
043  /**
044   * Retrieves information about an individual device pin.
045   *
046   * @param devicePinnerId The ID of the device pin. Example: "2324234"
047   * @param headers Headers of getDevicePinnerById method
048   */
049  public DevicePinner getDevicePinnerById(
050      String devicePinnerId, GetDevicePinnerByIdHeaders headers) {
051    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
052    FetchResponse response =
053        this.networkSession
054            .getNetworkClient()
055            .fetch(
056                new FetchOptions.Builder(
057                        String.join(
058                            "",
059                            this.networkSession.getBaseUrls().getBaseUrl(),
060                            "/2.0/device_pinners/",
061                            convertToString(devicePinnerId)),
062                        "GET")
063                    .headers(headersMap)
064                    .responseFormat(ResponseFormat.JSON)
065                    .auth(this.auth)
066                    .networkSession(this.networkSession)
067                    .build());
068    return JsonManager.deserialize(response.getData(), DevicePinner.class);
069  }
070
071  /**
072   * Deletes an individual device pin.
073   *
074   * @param devicePinnerId The ID of the device pin. Example: "2324234"
075   */
076  public void deleteDevicePinnerById(String devicePinnerId) {
077    deleteDevicePinnerById(devicePinnerId, new DeleteDevicePinnerByIdHeaders());
078  }
079
080  /**
081   * Deletes an individual device pin.
082   *
083   * @param devicePinnerId The ID of the device pin. Example: "2324234"
084   * @param headers Headers of deleteDevicePinnerById method
085   */
086  public void deleteDevicePinnerById(String devicePinnerId, DeleteDevicePinnerByIdHeaders headers) {
087    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
088    FetchResponse response =
089        this.networkSession
090            .getNetworkClient()
091            .fetch(
092                new FetchOptions.Builder(
093                        String.join(
094                            "",
095                            this.networkSession.getBaseUrls().getBaseUrl(),
096                            "/2.0/device_pinners/",
097                            convertToString(devicePinnerId)),
098                        "DELETE")
099                    .headers(headersMap)
100                    .responseFormat(ResponseFormat.NO_CONTENT)
101                    .auth(this.auth)
102                    .networkSession(this.networkSession)
103                    .build());
104  }
105
106  /**
107   * Retrieves all the device pins within an enterprise.
108   *
109   * <p>The user must have admin privileges, and the application needs the "manage enterprise" scope
110   * to make this call.
111   *
112   * @param enterpriseId The ID of the enterprise. Example: "3442311"
113   */
114  public DevicePinners getEnterpriseDevicePinners(String enterpriseId) {
115    return getEnterpriseDevicePinners(
116        enterpriseId,
117        new GetEnterpriseDevicePinnersQueryParams(),
118        new GetEnterpriseDevicePinnersHeaders());
119  }
120
121  /**
122   * Retrieves all the device pins within an enterprise.
123   *
124   * <p>The user must have admin privileges, and the application needs the "manage enterprise" scope
125   * to make this call.
126   *
127   * @param enterpriseId The ID of the enterprise. Example: "3442311"
128   * @param queryParams Query parameters of getEnterpriseDevicePinners method
129   */
130  public DevicePinners getEnterpriseDevicePinners(
131      String enterpriseId, GetEnterpriseDevicePinnersQueryParams queryParams) {
132    return getEnterpriseDevicePinners(
133        enterpriseId, queryParams, new GetEnterpriseDevicePinnersHeaders());
134  }
135
136  /**
137   * Retrieves all the device pins within an enterprise.
138   *
139   * <p>The user must have admin privileges, and the application needs the "manage enterprise" scope
140   * to make this call.
141   *
142   * @param enterpriseId The ID of the enterprise. Example: "3442311"
143   * @param headers Headers of getEnterpriseDevicePinners method
144   */
145  public DevicePinners getEnterpriseDevicePinners(
146      String enterpriseId, GetEnterpriseDevicePinnersHeaders headers) {
147    return getEnterpriseDevicePinners(
148        enterpriseId, new GetEnterpriseDevicePinnersQueryParams(), headers);
149  }
150
151  /**
152   * Retrieves all the device pins within an enterprise.
153   *
154   * <p>The user must have admin privileges, and the application needs the "manage enterprise" scope
155   * to make this call.
156   *
157   * @param enterpriseId The ID of the enterprise. Example: "3442311"
158   * @param queryParams Query parameters of getEnterpriseDevicePinners method
159   * @param headers Headers of getEnterpriseDevicePinners method
160   */
161  public DevicePinners getEnterpriseDevicePinners(
162      String enterpriseId,
163      GetEnterpriseDevicePinnersQueryParams queryParams,
164      GetEnterpriseDevicePinnersHeaders headers) {
165    Map<String, String> queryParamsMap =
166        prepareParams(
167            mapOf(
168                entryOf("marker", convertToString(queryParams.getMarker())),
169                entryOf("limit", convertToString(queryParams.getLimit())),
170                entryOf("direction", convertToString(queryParams.getDirection()))));
171    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
172    FetchResponse response =
173        this.networkSession
174            .getNetworkClient()
175            .fetch(
176                new FetchOptions.Builder(
177                        String.join(
178                            "",
179                            this.networkSession.getBaseUrls().getBaseUrl(),
180                            "/2.0/enterprises/",
181                            convertToString(enterpriseId),
182                            "/device_pinners"),
183                        "GET")
184                    .params(queryParamsMap)
185                    .headers(headersMap)
186                    .responseFormat(ResponseFormat.JSON)
187                    .auth(this.auth)
188                    .networkSession(this.networkSession)
189                    .build());
190    return JsonManager.deserialize(response.getData(), DevicePinners.class);
191  }
192
193  public Authentication getAuth() {
194    return auth;
195  }
196
197  public NetworkSession getNetworkSession() {
198    return networkSession;
199  }
200
201  public static class Builder {
202
203    protected Authentication auth;
204
205    protected NetworkSession networkSession;
206
207    public Builder() {}
208
209    public Builder auth(Authentication auth) {
210      this.auth = auth;
211      return this;
212    }
213
214    public Builder networkSession(NetworkSession networkSession) {
215      this.networkSession = networkSession;
216      return this;
217    }
218
219    public DevicePinnersManager build() {
220      if (this.networkSession == null) {
221        this.networkSession = new NetworkSession();
222      }
223      return new DevicePinnersManager(this);
224    }
225  }
226}