urbandictionary

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
const BaseURL = "https://api.urbandictionary.com/v0"

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "urbandictionary-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to Urban Dictionary.

View Source
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 NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func (*Client) Autocomplete

func (c *Client) Autocomplete(ctx context.Context, prefix string) ([]*Suggestion, error)

Autocomplete returns term suggestions for the given prefix.

func (*Client) DefineWord

func (c *Client) DefineWord(ctx context.Context, term string) ([]*Definition, error)

DefineWord looks up a slang term and returns its definitions.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

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.

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Suggestion

type Suggestion struct {
	Term string `json:"term"`
}

Suggestion is a single autocomplete result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL