Documentation
¶
Overview ¶
Package urbandictionary is the library behind the urbandictionary command line: the HTTP client, request shaping, and the typed data models for the Urban Dictionary public API (api.urbandictionary.com).
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) Autocomplete(ctx context.Context, prefix string) ([]*Suggestion, error)
- func (c *Client) DefineWord(ctx context.Context, term string) ([]*Definition, error)
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) RandomDefinitions(ctx context.Context) ([]*Definition, error)
- type Definition
- type Domain
- type Suggestion
Constants ¶
const BaseURL = "https://api.urbandictionary.com/v0"
BaseURL is the root every request is built from.
const DefaultUserAgent = "urbandictionary-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client to Urban Dictionary.
const Host = "api.urbandictionary.com"
Host is the API host for Urban Dictionary.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
BaseURL string
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 Urban Dictionary API over HTTP.
func (*Client) Autocomplete ¶
Autocomplete returns term suggestions for the given prefix.
func (*Client) DefineWord ¶
DefineWord looks up a slang term and returns its definitions.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings.
func (*Client) RandomDefinitions ¶
func (c *Client) RandomDefinitions(ctx context.Context) ([]*Definition, error)
RandomDefinitions returns random Urban Dictionary definitions.
type Definition ¶
type Definition struct {
DefID int `json:"def_id"`
Word string `json:"word"`
Definition string `json:"definition"`
Example string `json:"example"`
Author string `json:"author"`
ThumbsUp int `json:"thumbs_up"`
ThumbsDown int `json:"thumbs_down"`
WrittenOn string `json:"written_on"`
Permalink string `json:"permalink"`
}
Definition is a single Urban Dictionary entry.
type Domain ¶
type Domain struct{}
Domain is the urbandictionary 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 Suggestion ¶
type Suggestion struct {
Term string `json:"term"`
}
Suggestion is a single autocomplete result.