icefire

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: 12 Imported by: 0

Documentation

Overview

Package icefire is the library behind the icefire command line: the HTTP client, request shaping, and typed data models for An API of Ice and Fire (https://anapioficeandfire.com/api).

No API key is required. The Client paces requests, sets a real User-Agent, and retries transient failures (429 and 5xx).

Index

Constants

View Source
const BaseURL = "https://" + Host + "/api"

BaseURL is the root every API request is built from.

View Source
const DefaultUserAgent = "icefire-cli/0.1.0 (github.com/tamnd/icefire-cli)"

DefaultUserAgent identifies the client to the Ice and Fire API.

View Source
const Host = "anapioficeandfire.com"

Host is the API hostname.

Variables

This section is empty.

Functions

func ExtractID

func ExtractID(rawURL string) int

ExtractID extracts the numeric ID from an API resource URL. For example: https://anapioficeandfire.com/api/characters/583 -> 583

Types

type Book

type Book struct {
	ID        int      `json:"id"`
	Name      string   `json:"name"`
	ISBN      string   `json:"isbn"`
	Authors   []string `json:"authors"`
	Pages     int      `json:"pages"`
	Publisher string   `json:"publisher"`
	Released  string   `json:"released"`
	URL       string   `json:"url"`
}

Book holds the public data about a single ASOIAF book.

type Character

type Character struct {
	ID       int      `json:"id"`
	Name     string   `json:"name"`
	Gender   string   `json:"gender,omitempty"`
	Culture  string   `json:"culture,omitempty"`
	Born     string   `json:"born,omitempty"`
	Died     string   `json:"died,omitempty"`
	Titles   []string `json:"titles,omitempty"`
	Aliases  []string `json:"aliases,omitempty"`
	TvSeries []string `json:"tv_series,omitempty"`
	PlayedBy []string `json:"played_by,omitempty"`
	URL      string   `json:"url"`
}

Character holds the public data about a single ASOIAF character.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the An API of Ice and Fire API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given configuration.

func (*Client) GetBook

func (c *Client) GetBook(ctx context.Context, id int) (*Book, error)

GetBook fetches a single book by numeric ID.

func (*Client) GetCharacter

func (c *Client) GetCharacter(ctx context.Context, id int) (*Character, error)

GetCharacter fetches a single character by numeric ID.

func (*Client) GetHouse

func (c *Client) GetHouse(ctx context.Context, id int) (*House, error)

GetHouse fetches a single house by numeric ID.

func (*Client) ListBooks

func (c *Client) ListBooks(ctx context.Context, limit int) ([]Book, error)

ListBooks returns books up to the given limit.

func (*Client) ListCharacters

func (c *Client) ListCharacters(ctx context.Context, name string, limit int) ([]Character, error)

ListCharacters lists or searches characters. If name is non-empty, it filters by name.

func (*Client) ListHouses

func (c *Client) ListHouses(ctx context.Context, name string, limit int) ([]House, error)

ListHouses lists or searches houses. If name is non-empty, it filters by name.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the icefire driver.

func (Domain) Classify

func (Domain) Classify(input string) (string, string, error)

Classify turns a URL or ID into (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, hostnames, and binary identity.

func (Domain) Locate

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

Locate returns the live https URL for a (type, id).

func (Domain) Register

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

Register installs the client factory and every operation onto app.

type House

type House struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Region      string `json:"region,omitempty"`
	Words       string `json:"words,omitempty"`
	Seat        string `json:"seat,omitempty"`
	CoatOfArms  string `json:"coat_of_arms,omitempty"`
	CurrentLord string `json:"current_lord,omitempty"`
	URL         string `json:"url"`
}

House holds the public data about a single ASOIAF house.

Jump to

Keyboard shortcuts

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