001package com.box.sdkgen.managers.termsofserviceuserstatuses; 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.termsofserviceuserstatus.TermsOfServiceUserStatus; 015import com.box.sdkgen.schemas.termsofserviceuserstatuses.TermsOfServiceUserStatuses; 016import com.box.sdkgen.serialization.json.JsonManager; 017import java.util.Map; 018 019public class TermsOfServiceUserStatusesManager { 020 021 public Authentication auth; 022 023 public NetworkSession networkSession; 024 025 public TermsOfServiceUserStatusesManager() { 026 this.networkSession = new NetworkSession(); 027 } 028 029 protected TermsOfServiceUserStatusesManager(Builder builder) { 030 this.auth = builder.auth; 031 this.networkSession = builder.networkSession; 032 } 033 034 /** 035 * Retrieves an overview of users and their status for a terms of service, including Whether they 036 * have accepted the terms and when. 037 * 038 * @param queryParams Query parameters of getTermsOfServiceUserStatuses method 039 */ 040 public TermsOfServiceUserStatuses getTermsOfServiceUserStatuses( 041 GetTermsOfServiceUserStatusesQueryParams queryParams) { 042 return getTermsOfServiceUserStatuses(queryParams, new GetTermsOfServiceUserStatusesHeaders()); 043 } 044 045 /** 046 * Retrieves an overview of users and their status for a terms of service, including Whether they 047 * have accepted the terms and when. 048 * 049 * @param queryParams Query parameters of getTermsOfServiceUserStatuses method 050 * @param headers Headers of getTermsOfServiceUserStatuses method 051 */ 052 public TermsOfServiceUserStatuses getTermsOfServiceUserStatuses( 053 GetTermsOfServiceUserStatusesQueryParams queryParams, 054 GetTermsOfServiceUserStatusesHeaders headers) { 055 Map<String, String> queryParamsMap = 056 prepareParams( 057 mapOf( 058 entryOf("tos_id", convertToString(queryParams.getTosId())), 059 entryOf("user_id", convertToString(queryParams.getUserId())))); 060 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 061 FetchResponse response = 062 this.networkSession 063 .getNetworkClient() 064 .fetch( 065 new FetchOptions.Builder( 066 String.join( 067 "", 068 this.networkSession.getBaseUrls().getBaseUrl(), 069 "/2.0/terms_of_service_user_statuses"), 070 "GET") 071 .params(queryParamsMap) 072 .headers(headersMap) 073 .responseFormat(ResponseFormat.JSON) 074 .auth(this.auth) 075 .networkSession(this.networkSession) 076 .build()); 077 return JsonManager.deserialize(response.getData(), TermsOfServiceUserStatuses.class); 078 } 079 080 /** 081 * Sets the status for a terms of service for a user. 082 * 083 * @param requestBody Request body of createTermsOfServiceStatusForUser method 084 */ 085 public TermsOfServiceUserStatus createTermsOfServiceStatusForUser( 086 CreateTermsOfServiceStatusForUserRequestBody requestBody) { 087 return createTermsOfServiceStatusForUser( 088 requestBody, new CreateTermsOfServiceStatusForUserHeaders()); 089 } 090 091 /** 092 * Sets the status for a terms of service for a user. 093 * 094 * @param requestBody Request body of createTermsOfServiceStatusForUser method 095 * @param headers Headers of createTermsOfServiceStatusForUser method 096 */ 097 public TermsOfServiceUserStatus createTermsOfServiceStatusForUser( 098 CreateTermsOfServiceStatusForUserRequestBody requestBody, 099 CreateTermsOfServiceStatusForUserHeaders headers) { 100 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 101 FetchResponse response = 102 this.networkSession 103 .getNetworkClient() 104 .fetch( 105 new FetchOptions.Builder( 106 String.join( 107 "", 108 this.networkSession.getBaseUrls().getBaseUrl(), 109 "/2.0/terms_of_service_user_statuses"), 110 "POST") 111 .headers(headersMap) 112 .data(JsonManager.serialize(requestBody)) 113 .contentType("application/json") 114 .responseFormat(ResponseFormat.JSON) 115 .auth(this.auth) 116 .networkSession(this.networkSession) 117 .build()); 118 return JsonManager.deserialize(response.getData(), TermsOfServiceUserStatus.class); 119 } 120 121 /** 122 * Updates the status for a terms of service for a user. 123 * 124 * @param termsOfServiceUserStatusId The ID of the terms of service status. Example: "324234" 125 * @param requestBody Request body of updateTermsOfServiceStatusForUserById method 126 */ 127 public TermsOfServiceUserStatus updateTermsOfServiceStatusForUserById( 128 String termsOfServiceUserStatusId, 129 UpdateTermsOfServiceStatusForUserByIdRequestBody requestBody) { 130 return updateTermsOfServiceStatusForUserById( 131 termsOfServiceUserStatusId, 132 requestBody, 133 new UpdateTermsOfServiceStatusForUserByIdHeaders()); 134 } 135 136 /** 137 * Updates the status for a terms of service for a user. 138 * 139 * @param termsOfServiceUserStatusId The ID of the terms of service status. Example: "324234" 140 * @param requestBody Request body of updateTermsOfServiceStatusForUserById method 141 * @param headers Headers of updateTermsOfServiceStatusForUserById method 142 */ 143 public TermsOfServiceUserStatus updateTermsOfServiceStatusForUserById( 144 String termsOfServiceUserStatusId, 145 UpdateTermsOfServiceStatusForUserByIdRequestBody requestBody, 146 UpdateTermsOfServiceStatusForUserByIdHeaders headers) { 147 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 148 FetchResponse response = 149 this.networkSession 150 .getNetworkClient() 151 .fetch( 152 new FetchOptions.Builder( 153 String.join( 154 "", 155 this.networkSession.getBaseUrls().getBaseUrl(), 156 "/2.0/terms_of_service_user_statuses/", 157 convertToString(termsOfServiceUserStatusId)), 158 "PUT") 159 .headers(headersMap) 160 .data(JsonManager.serialize(requestBody)) 161 .contentType("application/json") 162 .responseFormat(ResponseFormat.JSON) 163 .auth(this.auth) 164 .networkSession(this.networkSession) 165 .build()); 166 return JsonManager.deserialize(response.getData(), TermsOfServiceUserStatus.class); 167 } 168 169 public Authentication getAuth() { 170 return auth; 171 } 172 173 public NetworkSession getNetworkSession() { 174 return networkSession; 175 } 176 177 public static class Builder { 178 179 protected Authentication auth; 180 181 protected NetworkSession networkSession; 182 183 public Builder() {} 184 185 public Builder auth(Authentication auth) { 186 this.auth = auth; 187 return this; 188 } 189 190 public Builder networkSession(NetworkSession networkSession) { 191 this.networkSession = networkSession; 192 return this; 193 } 194 195 public TermsOfServiceUserStatusesManager build() { 196 if (this.networkSession == null) { 197 this.networkSession = new NetworkSession(); 198 } 199 return new TermsOfServiceUserStatusesManager(this); 200 } 201 } 202}