コード例 #1
0
        /// <summary>
        /// Get Models for a Make and Year from the NHTSA. <seealso cref="https://vpic.nhtsa.dot.gov/api/vehicles/getmodelsformake/honda?format=xml"/>
        /// </summary>
        /// <param name="make">The Make that you want models for.</param>
        /// <returns><see cref="Schema.ModelsForMake.Response"/> for the NHTSAAPI.</returns>
        public static Schema.GetModelsForMake GetModels(string make)
        {
            const string Method = "getmodelsformake";

            if (string.IsNullOrWhiteSpace(make))
            {
                throw new ArgumentException("The parameter for the make cannot be an empty string.", nameof(make));
            }

            string url       = string.Join(string.Empty, VehicleAPI, Method, "/" + make, "?" + Format);
            string pathToXML = DownloadXML(url);

            return(SerializeConfig <Schema.GetModelsForMake> .DeserializeUsingXmlSerializer(pathToXML));
        }
コード例 #2
0
        /// <summary>
        /// Get Models for a Make and Year from the NHTSA <seealso cref="https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeId/440?format=xml"/>.
        /// </summary>
        /// <param name="makeId">The Make ID that you want Models for.</param>
        /// <returns><see cref="Schema.ModelsForMakeId.Response"/> for the NHTSAAPI.</returns>
        public static Schema.GetModelsForMake GetModels(int makeId)
        {
            const string Method = "GetModelsForMakeId";

            if (makeId < 0)
            {
                throw new ArgumentException("The parameter for the makeId must be greather than 0.", nameof(makeId));
            }

            string url       = string.Join(string.Empty, VehicleAPI, Method, "/" + makeId, "?" + Format);
            string pathToXML = DownloadXML(url);

            return(SerializeConfig <Schema.GetModelsForMake> .DeserializeUsingXmlSerializer(pathToXML));
        }
コード例 #3
0
        /// <summary>
        /// Get Models for a Make and Year from the NHTSA. <seealso cref="https://vpic.nhtsa.dot.gov/api/vehicles/getmodelsformakeyear/make/honda/modelyear/2015?format=xml"/>
        /// </summary>
        /// <param name="make">The Make that you want models for.</param>
        /// <param name="year">The year of models.</param>
        /// <returns><see cref="Schema.ModelsForMakeYear.Response"/> for the NHTSAAPI.</returns>
        public static Schema.GetMakeModels GetModels(string make, int year)
        {
            const string Method = "getmodelsformakeyear";

            const int MinimumYear = 1879;
            int       nextYear    = DateTime.Now.Year + 1;

            if (string.IsNullOrWhiteSpace(make))
            {
                throw new ArgumentException("The parameter for the make cannot be an empty string.", nameof(make));
            }
            else if (year < MinimumYear || year > nextYear)
            {
                throw new ArgumentException(string.Format("The parameter for the year must be between {0} and {1}.", MinimumYear, nextYear), nameof(year));
            }

            string url       = string.Join(string.Empty, VehicleAPI, Method, "/make/" + make, "/modelyear/" + year, "?" + Format);
            string pathToXML = DownloadXML(url);

            return(SerializeConfig <Schema.GetMakeModels> .DeserializeUsingXmlSerializer(pathToXML));
        }