示例#1
0
 //The return object will be our response structure later on, the string is just for now
 public IGeocodingResponse GetGeocodes(GeocodingRequest request)
 {
     if (request == null) throw new ArgumentNullException(nameof(request));
     
     using (var client = new WebClient())
     {
         var requestString = GeocodingRequestStringBuilder.Build(request);
         var responseString = client.DownloadString(requestString);            
         var hereResponse = JsonConvert.DeserializeObject<HereResponse>(responseString);       
         return new GeocodingResponseAdapter(hereResponse.Response);             
     }
 }
示例#2
0
        static void Main(string[] args)
        {
            var iamhere = new IAmHere();
            var request = new GeocodingRequest(ConfigurationManager.AppSettings["ApplicationId"], ConfigurationManager.AppSettings["ApplicationCode"])
            {
                Country = "Sweden",
                PostalCode = "504 64",
                Street = "Vevgatan 6",
                ResponseAttributes = new []{ResponseAttribute.MatchCode, ResponseAttribute.MatchQuality, ResponseAttribute.MatchType, }
            };

            var response = iamhere.GetGeocodes(request);

            Console.WriteLine(response);
        }
示例#3
0
        public async Task<string> GetGeocodeAsync(GeocodingRequest request)
        {
            if (request == null) throw new ArgumentNullException(nameof(request));

            using (var client = new HttpClient())
            {
                var requestString = GeocodingRequestStringBuilder.Build(request);

                var response = await client.GetAsync(requestString);
                var body = await response.Content.ReadAsStringAsync();

                //How should we handle http codes that indiciate failure?

                //This is where we will parse into our response data structure

                return body;
            }
        }