001package com.box.sdkgen.networking.fetchoptions;
002
003import com.box.sdkgen.networking.auth.Authentication;
004import com.box.sdkgen.networking.network.NetworkSession;
005import com.box.sdkgen.serialization.json.EnumWrapper;
006import com.fasterxml.jackson.databind.JsonNode;
007import java.io.InputStream;
008import java.util.List;
009import java.util.Map;
010
011public class FetchOptions {
012
013  /** URL of the request */
014  public final String url;
015
016  /** HTTP verb of the request */
017  public final String method;
018
019  /** HTTP query parameters */
020  public Map<String, String> params;
021
022  /** HTTP headers */
023  public Map<String, String> headers;
024
025  /** Request body of the request */
026  public JsonNode data;
027
028  /** Stream data of the request */
029  public InputStream fileStream;
030
031  /** Multipart data of the request */
032  public List<MultipartItem> multipartData;
033
034  /** Content type of the request body */
035  public String contentType;
036
037  /** Expected response format */
038  public EnumWrapper<ResponseFormat> responseFormat;
039
040  /** Authentication object */
041  public Authentication auth;
042
043  /** Network session object */
044  public NetworkSession networkSession;
045
046  /**
047   * A boolean value indicate if the request should follow redirects. Defaults to True. Not
048   * supported in Browser environment.
049   */
050  public Boolean followRedirects;
051
052  public FetchOptions(String url, String method) {
053    this.url = url;
054    this.method = method;
055    this.contentType = "application/json";
056    this.responseFormat = new EnumWrapper<ResponseFormat>(ResponseFormat.JSON);
057    this.followRedirects = true;
058  }
059
060  protected FetchOptions(Builder builder) {
061    this.url = builder.url;
062    this.method = builder.method;
063    this.params = builder.params;
064    this.headers = builder.headers;
065    this.data = builder.data;
066    this.fileStream = builder.fileStream;
067    this.multipartData = builder.multipartData;
068    this.contentType = builder.contentType;
069    this.responseFormat = builder.responseFormat;
070    this.auth = builder.auth;
071    this.networkSession = builder.networkSession;
072    this.followRedirects = builder.followRedirects;
073  }
074
075  public String getUrl() {
076    return url;
077  }
078
079  public String getMethod() {
080    return method;
081  }
082
083  public Map<String, String> getParams() {
084    return params;
085  }
086
087  public Map<String, String> getHeaders() {
088    return headers;
089  }
090
091  public JsonNode getData() {
092    return data;
093  }
094
095  public InputStream getFileStream() {
096    return fileStream;
097  }
098
099  public List<MultipartItem> getMultipartData() {
100    return multipartData;
101  }
102
103  public String getContentType() {
104    return contentType;
105  }
106
107  public EnumWrapper<ResponseFormat> getResponseFormat() {
108    return responseFormat;
109  }
110
111  public Authentication getAuth() {
112    return auth;
113  }
114
115  public NetworkSession getNetworkSession() {
116    return networkSession;
117  }
118
119  public Boolean getFollowRedirects() {
120    return followRedirects;
121  }
122
123  public static class Builder {
124
125    protected final String url;
126
127    protected final String method;
128
129    protected Map<String, String> params;
130
131    protected Map<String, String> headers;
132
133    protected JsonNode data;
134
135    protected InputStream fileStream;
136
137    protected List<MultipartItem> multipartData;
138
139    protected String contentType;
140
141    protected EnumWrapper<ResponseFormat> responseFormat;
142
143    protected Authentication auth;
144
145    protected NetworkSession networkSession;
146
147    protected Boolean followRedirects;
148
149    public Builder(String url, String method) {
150      this.url = url;
151      this.method = method;
152    }
153
154    public Builder params(Map<String, String> params) {
155      this.params = params;
156      return this;
157    }
158
159    public Builder headers(Map<String, String> headers) {
160      this.headers = headers;
161      return this;
162    }
163
164    public Builder data(JsonNode data) {
165      this.data = data;
166      return this;
167    }
168
169    public Builder fileStream(InputStream fileStream) {
170      this.fileStream = fileStream;
171      return this;
172    }
173
174    public Builder multipartData(List<MultipartItem> multipartData) {
175      this.multipartData = multipartData;
176      return this;
177    }
178
179    public Builder contentType(String contentType) {
180      this.contentType = contentType;
181      return this;
182    }
183
184    public Builder responseFormat(ResponseFormat responseFormat) {
185      this.responseFormat = new EnumWrapper<ResponseFormat>(responseFormat);
186      return this;
187    }
188
189    public Builder responseFormat(EnumWrapper<ResponseFormat> responseFormat) {
190      this.responseFormat = responseFormat;
191      return this;
192    }
193
194    public Builder auth(Authentication auth) {
195      this.auth = auth;
196      return this;
197    }
198
199    public Builder networkSession(NetworkSession networkSession) {
200      this.networkSession = networkSession;
201      return this;
202    }
203
204    public Builder followRedirects(Boolean followRedirects) {
205      this.followRedirects = followRedirects;
206      return this;
207    }
208
209    public FetchOptions build() {
210      if (this.contentType == null) {
211        this.contentType = "application/json";
212      }
213      if (this.responseFormat == null) {
214        this.responseFormat = new EnumWrapper<ResponseFormat>(ResponseFormat.JSON);
215      }
216      if (this.followRedirects == null) {
217        this.followRedirects = true;
218      }
219      return new FetchOptions(this);
220    }
221  }
222}