/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { PhoneNumberValidateResponse response = new PhoneNumberValidateResponse(); var unmarshaller = NumberValidateResponseUnmarshaller.Instance; response.NumberValidateResponse = unmarshaller.Unmarshall(context); return(response); }
public async Task <bool> ValidateNumber(string phoneNumber) { if (string.IsNullOrWhiteSpace(phoneNumber)) { return(false); } var phone = FormatPhoneNumber(phoneNumber); if (string.IsNullOrEmpty(phone)) { return(false); } var creds = new BasicAWSCredentials(_configuration["SMSAWSCredsAccess"], _configuration["SMSAWSCredsSecret"]); AmazonPinpointClient pinpointClient = null; //with proxy var proxyConfig = _configuration.GetValue <string>("ProxyAddress"); if (string.IsNullOrEmpty(proxyConfig)) { var config = new AmazonPinpointConfig { ProxyHost = proxyConfig, RegionEndpoint = Amazon.RegionEndpoint.USEast1 }; pinpointClient = new AmazonPinpointClient(creds, config); } else { //without proxy pinpointClient = new AmazonPinpointClient(creds, Amazon.RegionEndpoint.USEast1); } PhoneNumberValidateRequest phoneValidateRequest = new PhoneNumberValidateRequest { NumberValidateRequest = new NumberValidateRequest() { PhoneNumber = phone, IsoCountryCode = "US" } }; PhoneNumberValidateResponse phoneValidateResponse = await pinpointClient.PhoneNumberValidateAsync(phoneValidateRequest); if (phoneValidateResponse.HttpStatusCode == HttpStatusCode.OK) { var numberValidateResponse = phoneValidateResponse.NumberValidateResponse; return(numberValidateResponse != null && numberValidateResponse.PhoneTypeCode == 0); } return(false); }