wikifeatured

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package wikifeatured is the library behind the wikifeatured command line: the HTTP client, request shaping, and the typed data models for the Wikipedia Featured Content REST API (https://en.wikipedia.org/api/rest_v1/feed/).

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 DefaultUserAgent = "wikifeatured-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to Wikipedia.

View Source
const Host = "en.wikipedia.org"

Host is the Wikipedia API host this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	Rank    int    `json:"rank" kit:"id"`
	Title   string `json:"title"`
	Views   int    `json:"views"`
	Extract string `json:"extract"`
}

Article is one entry in the most-read list.

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	BaseURL   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 Wikipedia Featured Content REST API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func (*Client) Get

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

Get fetches a URL and returns the body. It paces and retries according to the client's settings.

func (*Client) GetFeatured

func (c *Client) GetFeatured(ctx context.Context, date string) (*Featured, error)

GetFeatured fetches the featured article for the given date (YYYY/MM/DD).

func (*Client) GetMostRead

func (c *Client) GetMostRead(ctx context.Context, date string) ([]*Article, error)

GetMostRead fetches the most-read articles for the given date (YYYY/MM/DD).

func (*Client) GetNews

func (c *Client) GetNews(ctx context.Context, date string) ([]*NewsItem, error)

GetNews fetches current news items for the given date (YYYY/MM/DD).

func (*Client) GetOnThisDay

func (c *Client) GetOnThisDay(ctx context.Context, date string) ([]*Event, error)

GetOnThisDay fetches historical events for the given month/day (MM/DD).

type Domain

type Domain struct{}

Domain is the Wikipedia Featured Content driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify satisfies kit.Domain. This domain does not classify arbitrary URLs into addressable resource URIs, so we return a usage error for any input.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, host, and identity.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate satisfies kit.Domain.

func (Domain) Register

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

Register installs the client factory and every operation onto app.

type Event

type Event struct {
	Year int    `json:"year" kit:"id"`
	Text string `json:"text"`
}

Event is a historical event from the on-this-day feed.

type Featured struct {
	Title   string `json:"title" kit:"id"`
	Extract string `json:"extract"`
	Date    string `json:"date"`
}

Featured is the today's featured article record.

type NewsItem

type NewsItem struct {
	Story     string `json:"story" kit:"id"`
	LinkCount int    `json:"link_count"`
}

NewsItem is one news story from Wikipedia's current events.

Jump to

Keyboard shortcuts

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