예제 #1
0
        }                                          //Repairs, Modifications, Accidents, Number of times it was sold,


        public async Task VinCheck()
        {
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            string jsonResult;

            using (var requestMessage =
                       new HttpRequestMessage(HttpMethod.Get, "http://api.carmd.com/v3.0/decode?vin=1GNALDEK9FZ108495"))
            {
                requestMessage.Headers.Authorization = new AuthenticationHeaderValue("authorization", APIKeys.VinDecoderAuth);

                requestMessage.Headers.Add("partner-token", APIKeys.VinDecoderPartnerToken);


                await client.SendAsync(requestMessage);

                jsonResult = await requestMessage.Content.ReadAsStringAsync();
            }
            VinDecode vinDecode = JsonConvert.DeserializeObject <VinDecode>(jsonResult);
        }
예제 #2
0
        public async Task <IEnumerable <VinDecode> > DecodeVINExtended()
        {
            List <VinDecode> VINList = new List <VinDecode>();
            string           url     = "https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVinExtended/5UXWX7C5*BA?format=json&modelyear=2011";

            _httpClient.BaseAddress = new Uri(url);
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var result = await _httpClient.GetStringAsync(url);

            dynamic   jsonObj = JsonConvert.DeserializeObject(result); //Json.Decode(result);
            VinDecode decode  = null;

            foreach (var node in jsonObj.Results)
            {
                decode = new VinDecode();
                if (node.Variable == "Manufacturer Name")
                {
                    decode.Manufacturer = node.Value;
                }
                ;
                if (node.Variable == "Make")
                {
                    decode.Make = node.Value;
                }
                ;
                if (node.Variable == "Model")
                {
                    decode.Model = node.Value;
                }
                ;
                if (node.Variable == "MakeId")
                {
                    decode.MakeId = node.Value;
                }
                ;
                if (node.Variable == "Trim")
                {
                    decode.Trim = node.Value;
                }
                ;
                if (node.Variable == "Manufacturer Name")
                {
                    decode.Manufacturer = node.Value;
                }
                ;
                if (node.Variable == "VIN")
                {
                    decode.VIN = node.Value;
                }
                ;
                if (node.Variable == "ManufacturerId")
                {
                    decode.ManufacturerId = node.Value;
                }
                ;
                if (node.Variable == "Fuel Type - Primary")
                {
                    decode.FuelType = node.Value;
                }
                ;
                VINList.Add(decode);
            }

            Console.WriteLine("Result from api" + result);
            Console.WriteLine("List" + JsonConvert.SerializeObject(VINList));

            return(VINList);
        }