예제 #1
0
        public async Task <BulkStatusResponse> ExecuteAsync(ManageBulkStatusExecuteContext context, UpdateStatusRequest bodyObject)
        {
            using (var client = HttpClientProvider.GetHttpClient(configuration))
            {
                NameValueCollection queryParameters = HttpUtility.ParseQueryString(string.Empty);
                SetQueryParamIfNotNull(queryParameters, "bulkId", context.BulkId);

                string queryString = queryParameters.ToString();
                string endpoint    = path + "?" + queryString;

                string      requestJson = JsonConvert.SerializeObject(bodyObject, Settings);
                HttpContent content     = new StringContent(requestJson, Encoding.UTF8, "application/json");

                var response = await client.PutAsync(endpoint, content);

                string contents = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(JsonConvert.DeserializeObject <BulkStatusResponse>(contents, Settings));
                }
                else
                {
                    throw new InfobipApiException(
                              response.StatusCode,
                              JsonConvert.DeserializeObject <ApiErrorResponse>(contents, Settings)
                              );
                }
            }
        }
        private static async void CancelBulkStatusAsync(String bulkId)
        {
            UpdateStatusRequest updateStatusRequest = new UpdateStatusRequest {
                Status = BulkStatus.CANCELED
            };
            ManageBulkStatusExecuteContext context = new ManageBulkStatusExecuteContext {
                BulkId = bulkId
            };

            await new ManageBulkStatus(BASIC_AUTH_CONFIGURATION).ExecuteAsync(context, updateStatusRequest);
        }