Пример #1
0
        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);
        }
Пример #2
0
        /// <summary>
        /// Validate phone number (basic) Validate a phone number by analyzing the syntax
        /// </summary>
        /// <exception cref="Cloudmersive.APIClient.NETCore.Validate.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="value">Phone number to validate in a PhoneNumberValidateRequest object.  Try a phone number such as \&quot;1.800.463.3339\&quot;, and either leave DefaultCountryCode blank or use \&quot;US\&quot;.</param>
        /// <returns>Task of ApiResponse (PhoneNumberValidationResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <PhoneNumberValidationResponse> > PhoneNumberSyntaxOnlyAsyncWithHttpInfo(PhoneNumberValidateRequest value)
        {
            // verify the required parameter 'value' is set
            if (value == null)
            {
                throw new ApiException(400, "Missing required parameter 'value' when calling PhoneNumberApi->PhoneNumberSyntaxOnly");
            }

            var    localVarPath         = "./validate/phonenumber/basic";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.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"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json",
                "text/json",
                "application/xml",
                "text/xml"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (value != null && value.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(value); // http body (model) parameter
            }
            else
            {
                localVarPostBody = value; // byte array
            }

            // authentication (Apikey) required
            if (!String.IsNullOrEmpty(this.Configuration.GetApiKeyWithPrefix("Apikey")))
            {
                localVarHeaderParams["Apikey"] = this.Configuration.GetApiKeyWithPrefix("Apikey");
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("PhoneNumberSyntaxOnly", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <PhoneNumberValidationResponse>(localVarStatusCode,
                                                                   localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()),
                                                                   (PhoneNumberValidationResponse)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(PhoneNumberValidationResponse))));
        }
Пример #3
0
        /// <summary>
        /// Validate phone number (basic) Validate a phone number by analyzing the syntax
        /// </summary>
        /// <exception cref="Cloudmersive.APIClient.NETCore.Validate.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="value">Phone number to validate in a PhoneNumberValidateRequest object.  Try a phone number such as \&quot;1.800.463.3339\&quot;, and either leave DefaultCountryCode blank or use \&quot;US\&quot;.</param>
        /// <returns>Task of PhoneNumberValidationResponse</returns>
        public async System.Threading.Tasks.Task <PhoneNumberValidationResponse> PhoneNumberSyntaxOnlyAsync(PhoneNumberValidateRequest value)
        {
            ApiResponse <PhoneNumberValidationResponse> localVarResponse = await PhoneNumberSyntaxOnlyAsyncWithHttpInfo(value);

            return(localVarResponse.Data);
        }
Пример #4
0
        /// <summary>
        /// Validate phone number (basic) Validate a phone number by analyzing the syntax
        /// </summary>
        /// <exception cref="Cloudmersive.APIClient.NETCore.Validate.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="value">Phone number to validate in a PhoneNumberValidateRequest object.  Try a phone number such as \&quot;1.800.463.3339\&quot;, and either leave DefaultCountryCode blank or use \&quot;US\&quot;.</param>
        /// <returns>PhoneNumberValidationResponse</returns>
        public PhoneNumberValidationResponse PhoneNumberSyntaxOnly(PhoneNumberValidateRequest value)
        {
            ApiResponse <PhoneNumberValidationResponse> localVarResponse = PhoneNumberSyntaxOnlyWithHttpInfo(value);

            return(localVarResponse.Data);
        }
Пример #5
0
 /// <summary>Starts a new phone number validation request.</summary>
 public async Task <PhoneNumberValidateResult> ValidatePhoneAsync(PhoneNumberValidateRequest request)
 {
     return((await GetResult <PhoneNumberValidateResult>(request)).FirstOrDefault());
 }