Documentation
¶
Overview ¶
Package ukpolice is the library behind the ukpolice command line: the HTTP client, request shaping, and the typed data models for the UK Police Data API (https://data.police.uk/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.
Index ¶
- Constants
- type Client
- func (c *Client) BaseURL() string
- func (c *Client) Categories(ctx context.Context, date string) ([]*CrimeCategory, error)
- func (c *Client) Crimes(ctx context.Context, lat, lng, date, category string) ([]*Crime, error)
- func (c *Client) Force(ctx context.Context, forceID string) (*ForceDetail, error)
- func (c *Client) Forces(ctx context.Context) ([]*Force, error)
- func (c *Client) StopSearches(ctx context.Context, forceID, date string) ([]*StopSearch, error)
- type Config
- type Crime
- type CrimeCategory
- type CrimeLocation
- type Domain
- type EngagementMethod
- type Force
- type ForceDetail
- type OutcomeStatus
- type StopSearch
- type Street
Constants ¶
const Host = "data.police.uk"
Host is the API host.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the UK Police Data API over HTTP.
func NewClientWithConfig ¶
NewClientWithConfig returns a Client with the given Config.
func (*Client) Categories ¶
Categories returns the list of crime categories for a given YYYY-MM date. If date is empty the API uses its latest available month.
func (*Client) Crimes ¶
Crimes returns street-level crimes near the given latitude/longitude for the given YYYY-MM date and crime category (use "all-crime" for all categories). If date is empty the API uses its latest available month.
func (*Client) StopSearches ¶
StopSearches returns stop-and-search records for a force for the given YYYY-MM date. If date is empty the API uses its latest available month.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds the client configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for the UK Police Data API client.
type Crime ¶
type Crime struct {
ID string `json:"persistent_id" kit:"id"`
Category string `json:"category"`
Month string `json:"month"`
Location *CrimeLocation `json:"location"`
LocationType string `json:"location_type,omitempty"`
Context string `json:"context,omitempty"`
OutcomeStatus *OutcomeStatus `json:"outcome_status"`
}
Crime is a single street-level crime record.
type CrimeCategory ¶
type CrimeCategory struct {
URL string `json:"url" kit:"id"`
Name string `json:"name" kit:"title"`
}
CrimeCategory is a crime classification returned by /crime-categories.
type CrimeLocation ¶
type CrimeLocation struct {
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
Street *Street `json:"street"`
}
CrimeLocation is the approximate location of a crime.
type Domain ¶
type Domain struct{}
Domain is the ukpolice 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 EngagementMethod ¶
type EngagementMethod struct {
URL string `json:"url,omitempty"`
Type string `json:"type"`
Description string `json:"description,omitempty"`
Title string `json:"title,omitempty"`
}
EngagementMethod is a contact / social-media channel for a force.
type ForceDetail ¶
type ForceDetail struct {
ID string `json:"id" kit:"id"`
Name string `json:"name" kit:"title"`
Description string `json:"description,omitempty" kit:"body"`
URL string `json:"url,omitempty"`
Telephone string `json:"telephone,omitempty"`
EngagementMethods []EngagementMethod `json:"engagement_methods,omitempty"`
}
ForceDetail is the full detail for a single UK police force.
type OutcomeStatus ¶
OutcomeStatus is the most recent recorded outcome of a crime.
type StopSearch ¶
type StopSearch struct {
Type string `json:"type"`
DateTime string `json:"datetime,omitempty"`
Outcome string `json:"outcome,omitempty"`
ObjectOfSearch string `json:"object_of_search,omitempty"`
AgeRange string `json:"age_range,omitempty"`
Gender string `json:"gender,omitempty"`
SelfDefinedEthnicity string `json:"self_defined_ethnicity,omitempty"`
}
StopSearch is a single stop-and-search record.