Ejemplo n.º 1
0
        public static async void ExecuteMethods()
        {
            EnderecoJson origin = await GetAddress("05314-000");

            EnderecoJson destination = await GetAddress("04180-112");

            QueryCoordinates coordinatesorigin = await GetCoordinates(GenerateUri(origin));

            QueryCoordinates coordinatesdestination = await GetCoordinates(GenerateUri(destination));

            var distancematrix = await PostDistance(GenerateJsonBody(coordinatesorigin, coordinatesdestination));

            var frete = await ValorDoFrete(GetDistance(distancematrix));

            Console.WriteLine(frete.ValorFrete);
        }
Ejemplo n.º 2
0
        private static async Task <EnderecoJson> GetAddress(string cep)
        {
            string responseData;
            var    baseAddress = new Uri("http://api.frenet.com.br/");

            using (var httpClient = new HttpClient {
                BaseAddress = baseAddress
            })
            {
                httpClient.DefaultRequestHeaders.Add("accept", "application/json");
                httpClient.DefaultRequestHeaders.Add("token", "EFB53FBBRF4CAR4EDARB177R7F076B125EE8");

                using (var response = await httpClient.GetAsync("CEP/Address/" + cep))
                {
                    responseData = await response.Content.ReadAsStringAsync();
                }
            }
            return(EnderecoJson.FromJson(responseData));
        }
Ejemplo n.º 3
0
        public static string GenerateUri(EnderecoJson x)
        {
            string end = x.Street + ", " + x.District + ", " + x.City + " - " + x.Uf + ", " + x.Cep + ", Brazil";

            return(Uri.EscapeDataString(end));
        }