/// <summary> /// Changes account state. /// </summary> /// <param name="accessToken"> /// The access token. /// </param> /// <param name="accountID"> /// The account id. /// </param> /// <param name="accountState"> /// The account state. /// </param> /// <returns> /// The task. /// </returns> private static async Task ChangeAccountState( string accessToken, string accountID, string accountState) { // Please note that the state cannot be changed to the same state, i.e. enabled -> enabled is not allowed. var stateToChange = new StateV1Model(accountState); var accountStateClient = CreateApiAccessor <AccountsStateApi>(accessToken); // See https://cp.serverdata.net/webservices/restapi/docs-ui/index#!/Account_state_(enabled%2Fdisabled)/AccountStateV1_PostState await accountStateClient.AccountStateV1PostStateAsync( accountID, stateToChange); StateV1Model currentState; do { // Due to the API implementation specifics, polling is required. Console.WriteLine("Waiting for the account state change completion..."); Thread.Sleep(10000); // See https://cp.serverdata.net/webservices/restapi/docs-ui/index#!/Account_state_(enabled%2Fdisabled)/AccountStateV1_GetState currentState = await accountStateClient .AccountStateV1GetStateAsync(accountID); // Codegen also implements model equality through IEquatable interface. }while (!Equals(currentState, stateToChange)); }
/// <summary> /// Changes account's state. /// </summary> /// <exception cref="Hosting.PublicAPI.Sample.Generated.Invokers.ApiException">Thrown when fails to make API call</exception> /// <param name="accountID">The account's id.</param> /// <param name="state">The account's state.</param> /// <returns>Task of Object</returns> public async System.Threading.Tasks.Task <Object> AccountStateV1PostStateAsync(string accountID, StateV1Model state) { ApiResponse <Object> localVarResponse = await AccountStateV1PostStateAsyncWithHttpInfo(accountID, state); return(localVarResponse.Data); }
/// <summary> /// Changes account's state. /// </summary> /// <exception cref="Hosting.PublicAPI.Sample.Generated.Invokers.ApiException">Thrown when fails to make API call</exception> /// <param name="accountID">The account's id.</param> /// <param name="state">The account's state.</param> /// <returns>Task of ApiResponse (Object)</returns> public async System.Threading.Tasks.Task <ApiResponse <Object> > AccountStateV1PostStateAsyncWithHttpInfo(string accountID, StateV1Model state) { // verify the required parameter 'accountID' is set if (accountID == null) { throw new ApiException(400, "Missing required parameter 'accountID' when calling AccountsStateApi->AccountStateV1PostState"); } // verify the required parameter 'state' is set if (state == null) { throw new ApiException(400, "Missing required parameter 'state' when calling AccountsStateApi->AccountStateV1PostState"); } var localVarPath = "/v1/api/accounts/{accountID}/state"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new Dictionary <String, String>(); var localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json", "text/json", "application/xml", "text/xml" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json localVarPathParams.Add("format", "json"); if (accountID != null) { localVarPathParams.Add("accountID", Configuration.ApiClient.ParameterToString(accountID)); // path parameter } if (state != null && state.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(state); // http body (model) parameter } else { localVarPostBody = state; // byte array } // authentication (Authorization) required if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("Authorization"))) { localVarHeaderParams["Authorization"] = Configuration.GetApiKeyWithPrefix("Authorization"); } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("AccountStateV1PostState", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (Object)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Object)))); }
/// <summary> /// Changes account's state. /// </summary> /// <exception cref="Hosting.PublicAPI.Sample.Generated.Invokers.ApiException">Thrown when fails to make API call</exception> /// <param name="accountID">The account's id.</param> /// <param name="state">The account's state.</param> /// <returns>Object</returns> public Object AccountStateV1PostState(string accountID, StateV1Model state) { ApiResponse <Object> localVarResponse = AccountStateV1PostStateWithHttpInfo(accountID, state); return(localVarResponse.Data); }