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
- func ExtractID(rawURL string) int
- type Book
- type Character
- type Client
- func (c *Client) GetBook(ctx context.Context, id int) (*Book, error)
- func (c *Client) GetCharacter(ctx context.Context, id int) (*Character, error)
- func (c *Client) GetHouse(ctx context.Context, id int) (*House, error)
- func (c *Client) ListBooks(ctx context.Context, limit int) ([]Book, error)
- func (c *Client) ListCharacters(ctx context.Context, name string, limit int) ([]Character, error)
- func (c *Client) ListHouses(ctx context.Context, name string, limit int) ([]House, error)
- type Config
- type Domain
- type House
Constants ¶
const BaseURL = "https://" + Host + "/api"
BaseURL is the root every API request is built from.
const DefaultUserAgent = "icefire-cli/0.1.0 (github.com/tamnd/icefire-cli)"
DefaultUserAgent identifies the client to the Ice and Fire API.
const Host = "anapioficeandfire.com"
Host is the API hostname.
Variables ¶
This section is empty.
Functions ¶
func ExtractID ¶
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 (*Client) GetCharacter ¶
GetCharacter fetches a single character by numeric ID.
func (*Client) ListCharacters ¶
ListCharacters lists or searches characters. 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) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, hostnames, and binary identity.
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.