Documentation
¶
Overview ¶
Package vpic is the library behind the vpic command line: the HTTP client, request shaping, and the typed data models for the NHTSA Vehicle Product Information Catalog (VPIC) API.
The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load. Build your endpoint calls and JSON decoding on top of it.
Index ¶
- Constants
- type Client
- func (c *Client) DecodeVIN(ctx context.Context, vin string) (*VINDecode, error)
- func (c *Client) GetModels(ctx context.Context, make string, year int) ([]Model, error)
- func (c *Client) GetVehicleTypes(ctx context.Context, make string) ([]VehicleType, error)
- func (c *Client) ListMakes(ctx context.Context, limit int) ([]Make, error)
- type Domain
- type Make
- type Model
- type VINDecode
- type VehicleType
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "vpic-cli/dev (+https://github.com/tamnd/vpic-cli)"
DefaultUserAgent identifies the client to VPIC.
const Host = "vpic.nhtsa.dot.gov"
Host is the NHTSA VPIC API host.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
// Rate is the minimum gap between requests. Zero means no pacing.
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to the NHTSA VPIC API over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 30s timeout, a 300ms minimum gap between requests, and five retries on transient errors.
func (*Client) DecodeVIN ¶
DecodeVIN decodes a VIN number and returns the key fields. ErrorCode "0" = success, "6" = invalid VIN, "8" = check-digit mismatch (usable), "11" = incomplete VIN (returns error).
func (*Client) GetVehicleTypes ¶
GetVehicleTypes returns vehicle types for a given make.
type Domain ¶
type Domain struct{}
Domain is the VPIC driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type Model ¶
type Model struct {
MakeID int `json:"make_id"`
MakeName string `json:"make_name"`
ModelID int `kit:"id" json:"model_id"`
Name string `json:"model_name"`
}
Model is a vehicle model for a given make and year.
type VINDecode ¶
type VINDecode struct {
VIN string `kit:"id" json:"vin"`
Make string `json:"make"`
Model string `json:"model"`
ModelYear string `json:"model_year"`
BodyClass string `json:"body_class"`
VehicleType string `json:"vehicle_type"`
DriveType string `json:"drive_type"`
FuelTypePrimary string `json:"fuel_type_primary"`
EngineHP string `json:"engine_hp"`
EngineModel string `json:"engine_model"`
Displacement string `json:"displacement_l"`
PlantCity string `json:"plant_city"`
PlantCountry string `json:"plant_country"`
}
VINDecode holds the decoded fields from a VIN lookup.
type VehicleType ¶
VehicleType is a vehicle type for a given make.