예제 #1
0
        private async Task <SendSmsV2Response> SendSMSV2Asycn(SendSmsV2Request infomation, CancellationToken none)
        {
            // Validation Information
            var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(infomation);

            Validator.ValidateObject(infomation, validationContext);

            SendSmsV2Response responseObject;

            // If Configulation is in SMS disable mode
            if (!_configulation.SendSmsApiEnable)
            {
                Log.Information("{ApiClient} Configulation is in SMS disable mode", _clientTitle);

                // Mockup data SMS Response
                var mockUpString = "{\"status\": \"000\",\"detail\": \"OK\",\"language\": \"ENG\",\"usedCredit\": \"1\",\"sumPhone\": \"1\",\"transaction\": \"150605222\"}";
                responseObject = JsonConvert.DeserializeObject <SendSmsV2Response>(mockUpString);
            }
            else
            {
                // Create request
                var request = new RestRequest(_SendSMSV2Endpoint, DataFormat.Json);
                request.AddJsonBody(infomation);

                // Attemp request to Send SMS
                var response = await Task.FromResult(_client.Post <SendSmsV2Response>(request));

                Log.Verbose("{ApiClient} Requested to API", _clientTitle);

                // Check data is valid
                if (response.Data is null)
                {
                    Log.Error(response.ErrorException, "{ApiClient} Got an error [Message={ErrorMessage}]", _clientTitle, response.ErrorMessage);
                    throw response.ErrorException;
                }

                Log.Debug("{ApiClient} [Response={Response}]", _clientTitle, JsonConvert.SerializeObject(response.Data));
                responseObject = response.Data;
            }

            // Return response
            Log.Information("{ApiClient} SMS have been sent [PhoneNo={PhoneNo},Status={Status}, Detail={Detail}, Transaction={Transaction}]", _clientTitle, infomation.PhoneNo, responseObject.Status, responseObject.Detail, responseObject.Transaction);
            return(responseObject);
        }
예제 #2
0
 /// <summary>
 /// Send a single SMS message
 /// </summary>
 /// <param name="infomation">Required parameter for send SMS</param>
 /// <returns>Response of sent SMS</returns>
 /// <exception cref="ValidationException"></exception>
 /// <exception cref="InvalidOperationException"></exception>
 public virtual Task <SendSmsV2Response> SendSMSV2Asycn(SendSmsV2Request infomation)
 {
     Log.Debug("{ApiClient} Attempt to send SMS [PhoneNo={PhoneNo}]", _clientTitle, infomation.PhoneNo);
     return(SendSMSV2Asycn(infomation, System.Threading.CancellationToken.None));
 }