<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace WorldDomination.Spatial.ApiServices.GoogleMaps
{
    public class GoogleMapsApiService : IGoogleMapsApiService
    {
        private readonly HttpClient _httpClient;

        public GoogleMapsApiService(HttpClient httpClient = null)
        {
            _httpClient = httpClient;
        }

        public async Task<GoogleMapsResponse> GeocodeAsync(string query, ComponentFilters filters = null)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                throw new ArgumentNullException("query");
            }

            var requestUrl = new StringBuilder();
            requestUrl.AppendFormat("http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false",
                Uri.EscapeDataString(query));<commit_msg>Added optional google API key & SSL route.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace WorldDomination.Spatial.ApiServices.GoogleMaps
{
    public class GoogleMapsApiService : IGoogleMapsApiService
    {
        private readonly string _apiKey;
        private readonly HttpClient _httpClient;


        public GoogleMapsApiService() : this(null, null)
        {
        }

        public GoogleMapsApiService(string apiKey) : this(apiKey, null)
        {
        }

        public GoogleMapsApiService(HttpClient httpClient = null) : this(null, httpClient)
        {
        }

        public GoogleMapsApiService(string apiKey,
            HttpClient httpClient)
        {
            if (!string.IsNullOrWhiteSpace(apiKey))
            {
                _apiKey = apiKey.Trim();    
            }
            
            _httpClient = httpClient;
        }

        public async Task<GoogleMapsResponse> GeocodeAsync(string query, ComponentFilters filters = null)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                throw new ArgumentNullException("query");
            }

            var requestUrl = new StringBuilder();
            requestUrl.AppendFormat("https://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false",
                Uri.EscapeDataString(query));

            // Append the API key if it's been provided.
            if (!string.IsNullOrWhiteSpace(_apiKey))
            {
                requestUrl.AppendFormat("&key={0}", _apiKey);
            }
{'fraction_non_alphanumeric': 0.08695652173913043, 'fraction_numerical': 0.0011441647597254005, 'mean_word_length': 2.3160556257901392, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3630577', 'n_tokens_mistral': 697, 'n_tokens_neox': 684, 'n_words': 139}