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