예제 #1
0
파일: Verification.cs 프로젝트: byteinc/API
        /// <summary>
        /// User Address Verification API
        /// </summary>
        /// <param name="Models.UserAddressVerificationInput">Object containing request parameters</param>
        /// <return>Returns the Models.VerifyAddressResponse response from the API call</return>
        public Models.VerifyAddressResponse UserAddressVerification(Models.UserAddressVerificationInput input)
        {
            Task <Models.VerifyAddressResponse> t = UserAddressVerificationAsync(input);

            APIHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
예제 #2
0
파일: Verification.cs 프로젝트: byteinc/API
        /// <summary>
        /// User Address Verification API
        /// </summary>
        /// <param name="Models.UserAddressVerificationInput">Object containing request parameters</param>
        /// <return>Returns the Models.VerifyAddressResponse response from the API call</return>
        public async Task <Models.VerifyAddressResponse> UserAddressVerificationAsync(Models.UserAddressVerificationInput input)
        {
            //validating required parameters
            if (null == input.User)
            {
                throw new ArgumentNullException("user", "The property \"User\" in the input object cannot be null.");
            }

            if (null == input.A)
            {
                throw new ArgumentNullException("a", "The property \"A\" in the input object cannot be null.");
            }

            if (null == input.Sa)
            {
                throw new ArgumentNullException("sa", "The property \"Sa\" in the input object cannot be null.");
            }

            if (null == input.C)
            {
                throw new ArgumentNullException("c", "The property \"C\" in the input object cannot be null.");
            }

            if (null == input.S)
            {
                throw new ArgumentNullException("s", "The property \"S\" in the input object cannot be null.");
            }

            //the base uri for api requests
            string _baseUri = Configuration.GetBaseURI(Configuration.Servers.PATH);

            //prepare query string for API call
            StringBuilder _queryBuilder = new StringBuilder(_baseUri);

            _queryBuilder.Append("/v/a");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "user", input.User },
                { "a", input.A },
                { "sa", input.Sa },
                { "c", input.C },
                { "s", input.S },
                { "z", input.Z },
                { "address", input.Address }
            }, ArrayDeserializationFormat, ParameterSeparator);


            //validate and preprocess url
            string _queryUrl = APIHelper.CleanUrl(_queryBuilder);

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "SMASH" }
            };

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Get(_queryUrl, _headers);

            //Custom Authentication to be added for authorization
            AuthUtility.AppendCustomAuthParams(_request);

            //invoke request and get response
            HttpStringResponse _response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(_request).ConfigureAwait(false);

            HttpContext _context = new HttpContext(_request, _response);

            //return null on 404
            if (_response.StatusCode == 404)
            {
                return(null);
            }

            //handle errors defined at the API level
            base.ValidateResponse(_response, _context);

            try
            {
                return(APIHelper.JsonDeserialize <Models.VerifyAddressResponse>(_response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }