Пример #1
0
        public async Task <GoogleApiResponse> Get(GoogleApiRequest request)
        {
            string url = this.BuildRequestUrl(request);
            HttpResponseMessage response = await this.client.GetAsync(url);

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            GoogleApiResponse jsonResponse = JsonConvert.DeserializeObject <GoogleApiResponse>(responseBody);

            return(jsonResponse);
        }
Пример #2
0
        private string BuildRequestUrl(GoogleApiRequest request)
        {
            string url = $"{GoogleApiUrlBase}{request.Api}/";

            if (!string.IsNullOrEmpty(request.SubApi))
            {
                url = url + request.SubApi + "/";
            }

            url = $"{url}json?key={this.apiKey}";

            for (int i = 0; i < request.QueryParams.Count(); i++)
            {
                string queryParamKey = request.QueryParams.Keys.ToList()[i];
                url = $"{url}&{queryParamKey}={request.QueryParams[queryParamKey]}";
            }

            return(url);
        }