예제 #1
0
        /// <summary>
        /// Loads specific value
        /// </summary>
        public static async Task <GenderByNameModel> LoadValue(string text)
        {
            string url;

            if (text != ConfigUtils.DefaultName)
            {
                url = $"{ConfigUtils.GenderByNameURL}{ text } ";
            }
            else
            {
                url = $"{ConfigUtils.GenderByNameURL}{ ConfigUtils.DefaultName }";
            }

            // open a call to a client
            // or open a new request of ApiClient as await for response
            using (HttpResponseMessage response = await ApiHelper.ApiClient.
                                                  GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    // there We will read the data
                    // convert json to ValueByNameModel with correct properties
                    GenderByNameModel genderAndProbability = await response.
                                                             Content.ReadAsAsync <GenderByNameModel>();

                    return(genderAndProbability);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
            // there a response is closing and make sure, that Our calls are cleaned up
        }
예제 #2
0
        /// <summary>
        /// Loads the name gender from API
        /// </summary>
        /// <param name="name">Name of person</param>
        /// <returns> array with data </returns>
        public static async Task <string[]> LoadNameGender(string name)
        {
            string[]          genderData = new string[2];
            GenderByNameModel gender     = await GenderByName.
                                           LoadValue(name).ConfigureAwait(false);

            genderData[0] = gender.Gender;
            genderData[1] = gender.Probability.ToString();

            return(genderData);
        }