metron

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 14 Imported by: 0

README

go-metron

go-metron is an API client enabling Go programs to interact with Metron.

Features

Caching

go-metron can optionally use heuristic caching.

Filtering

go-metron supports all filtering capabilities of Metron's API.

Pagination

go-metron will automatically fetch the next page while iterating over results.

Rate Limiting

go-metron will at most make 30 requests per minute, adhering to Metron's API guidelines.

Example Usage

package main

import (
	"context"
	"fmt"

	"cloud.google.com/go/civil"
	"github.com/jyggen/go-metron"
)

func main() {
	c := metron.NewClient(
		metron.WithAuthentication("username", "password"),
		metron.WithCaching(""),
	)

	after, _ := civil.ParseDate("2021-06-07")
	before, _ := civil.ParseDate("2021-06-13")

	// Get all Marvel comics for the week of 2021-06-07
	for i, err := range c.Issues(
		context.Background(),
		metron.FilterByStoreDateRangeAfter(after),
		metron.FilterByStoreDateRangeBefore(before),
		metron.FilterByPublisherName("marvel"),
	) {
		if err != nil {
			panic(err)
		}

		fmt.Printf("%d %s\n", i.ID, i.Name)
	}

	// Retrieve the detail for an individual issue
	asm68, err := c.IssueByID(context.Background(), 31660)

	if err != nil {
		panic(err)
	}

	fmt.Println(asm68.Description)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arc

type Arc struct {
	ID          int       `json:"id"`
	Name        string    `json:"name"`
	Description *string   `json:"desc"`
	ImageURL    *URL      `json:"image"`
	ComicVineID *int      `json:"cv_id"`
	ResourceURL URL       `json:"resource_url"`
	Modified    time.Time `json:"modified"`
}

type ArcList

type ArcList struct {
	ID       int       `json:"id"`
	Name     string    `json:"name"`
	Modified time.Time `json:"modified"`
}

type Character

type Character struct {
	ID          int            `json:"id"`
	Name        string         `json:"name"`
	Alias       *[]string      `json:"alias"`
	Description *string        `json:"desc"`
	ImageURL    *URL           `json:"image"`
	Creators    []CreatorList  `json:"creators"`
	Teams       []TeamList     `json:"teams"`
	Universes   []UniverseList `json:"universes"`
	ComicVineID *int           `json:"cv_id"`
	ResourceURL URL            `json:"resource_url"`
	Modified    time.Time      `json:"modified"`
}

type CharacterList

type CharacterList struct {
	ID       int       `json:"id"`
	Name     string    `json:"name"`
	Modified time.Time `json:"modified"`
}

type Client

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

func NewClient

func NewClient(options ...Option) *Client

func (*Client) ArcByID

func (c *Client) ArcByID(ctx context.Context, id int) (Arc, error)

ArcByID returns the information of an individual story arc.

func (*Client) Arcs

func (c *Client) Arcs(ctx context.Context, filters ...Filter) func(func(ArcList, error) bool)

Arcs returns a list of all the story arcs.

func (*Client) CharacterByID

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

CharacterByID returns the information of an individual character.

func (*Client) Characters

func (c *Client) Characters(ctx context.Context, filters ...Filter) func(func(CharacterList, error) bool)

Characters returns a list of all the characters.

func (*Client) CreatorByID

func (c *Client) CreatorByID(ctx context.Context, id int) (Creator, error)

func (*Client) Creators

func (c *Client) Creators(ctx context.Context, filters ...Filter) func(func(CreatorList, error) bool)

func (*Client) ImprintByID

func (c *Client) ImprintByID(ctx context.Context, id int) (Imprint, error)

func (*Client) Imprints

func (c *Client) Imprints(ctx context.Context, filters ...Filter) func(func(ImprintList, error) bool)

func (*Client) IssueByID

func (c *Client) IssueByID(ctx context.Context, id int) (Issue, error)

func (*Client) Issues

func (c *Client) Issues(ctx context.Context, filters ...Filter) func(func(IssueList, error) bool)

func (*Client) IssuesByArcID

func (c *Client) IssuesByArcID(ctx context.Context, id int) func(func(IssueList, error) bool)

IssuesByArcID returns a list of issues for a story arc.

func (*Client) IssuesByCharacterID

func (c *Client) IssuesByCharacterID(ctx context.Context, id int) func(func(IssueList, error) bool)

func (*Client) IssuesBySeriesID

func (c *Client) IssuesBySeriesID(ctx context.Context, id int) func(func(IssueList, error) bool)

func (*Client) IssuesByTeamID

func (c *Client) IssuesByTeamID(ctx context.Context, id int) func(func(IssueList, error) bool)

func (*Client) PublisherByID

func (c *Client) PublisherByID(ctx context.Context, id int) (Publisher, error)

func (*Client) Publishers

func (c *Client) Publishers(ctx context.Context, filters ...Filter) func(func(PublisherList, error) bool)

func (*Client) Roles

func (c *Client) Roles(ctx context.Context, filters ...Filter) func(func(RoleList, error) bool)

func (*Client) Series

func (c *Client) Series(ctx context.Context, filters ...Filter) func(func(SeriesList, error) bool)

func (*Client) SeriesByID

func (c *Client) SeriesByID(ctx context.Context, id int) (Series, error)

func (*Client) SeriesByPublisherID

func (c *Client) SeriesByPublisherID(ctx context.Context, id int) func(func(SeriesList, error) bool)

func (*Client) SeriesTypes

func (c *Client) SeriesTypes(ctx context.Context, filters ...Filter) func(func(SeriesTypeList, error) bool)

func (*Client) TeamByID

func (c *Client) TeamByID(ctx context.Context, id int) (Team, error)

func (*Client) Teams

func (c *Client) Teams(ctx context.Context, filters ...Filter) func(func(TeamList, error) bool)

func (*Client) UniverseByID

func (c *Client) UniverseByID(ctx context.Context, id int) (Universe, error)

func (*Client) Universes

func (c *Client) Universes(ctx context.Context, filters ...Filter) func(func(UniverseList, error) bool)

type Creator

type Creator struct {
	ID          int         `json:"id"`
	Name        string      `json:"name"`
	Birth       *civil.Date `json:"birth"`
	Death       *civil.Date `json:"death"`
	Description *string     `json:"desc"`
	ImageURL    *URL        `json:"image"`
	Alias       *[]string   `json:"alias"`
	ComicVineID *int        `json:"cv_id"`
	ResourceURL URL         `json:"resource_url"`
	Modified    time.Time   `json:"modified"`
}

type CreatorList

type CreatorList struct {
	ID       int       `json:"id"`
	Name     string    `json:"name"`
	Modified time.Time `json:"modified"`
}

type Filter

type Filter func(q *url.Values)

func FilterByComicVineID

func FilterByComicVineID(comicVineID int) Filter

func FilterByCoverHash

func FilterByCoverHash(coverHash string) Filter

func FilterByCoverMonth

func FilterByCoverMonth(month time.Month) Filter

func FilterByCoverYear

func FilterByCoverYear(year int) Filter

func FilterByDesignation

func FilterByDesignation(designation string) Filter

func FilterByImprintID

func FilterByImprintID(id int) Filter

func FilterByImprintName

func FilterByImprintName(name string) Filter

func FilterByMissingComicVineID

func FilterByMissingComicVineID(isMissing bool) Filter

func FilterByModifiedGreaterThan

func FilterByModifiedGreaterThan(modified time.Time) Filter

func FilterByName

func FilterByName(name string) Filter

func FilterByNumber

func FilterByNumber(number string) Filter

func FilterByPublisherID

func FilterByPublisherID(id int) Filter

func FilterByPublisherName

func FilterByPublisherName(name string) Filter

func FilterByRating

func FilterByRating(rating string) Filter

func FilterBySKU

func FilterBySKU(sku string) Filter

func FilterBySeriesID

func FilterBySeriesID(id int) Filter

func FilterBySeriesName

func FilterBySeriesName(name string) Filter

func FilterBySeriesType

func FilterBySeriesType(name string) Filter

func FilterBySeriesTypeID

func FilterBySeriesTypeID(id int) Filter

func FilterBySeriesVolume

func FilterBySeriesVolume(volume int) Filter

func FilterBySeriesYearBegan

func FilterBySeriesYearBegan(year int) Filter

func FilterByStatus

func FilterByStatus(status int) Filter

func FilterByStoreDate

func FilterByStoreDate(date civil.Date) Filter

func FilterByStoreDateRangeAfter

func FilterByStoreDateRangeAfter(date civil.Date) Filter

func FilterByStoreDateRangeBefore

func FilterByStoreDateRangeBefore(date civil.Date) Filter

func FilterByUPC

func FilterByUPC(upc string) Filter

func FilterByVolume

func FilterByVolume(volume int) Filter

func FilterByYearBegan

func FilterByYearBegan(year int) Filter

func FilterByYearEnded

func FilterByYearEnded(year int) Filter

type Imprint

type Imprint struct {
	ID          int       `json:"id"`
	Name        string    `json:"name"`
	Founded     *int      `json:"founded"`
	Description *string   `json:"desc"`
	ImageURL    *URL      `json:"image"`
	ComicVineID *int      `json:"cv_id"`
	Publisher   Reference `json:"publisher"`
	ResourceURL URL       `json:"resource_url"`
	Modified    time.Time `json:"modified"`
}

type ImprintList

type ImprintList struct {
	ID       int       `json:"id"`
	Name     string    `json:"name"`
	Modified time.Time `json:"modified"`
}

type Issue

type Issue struct {
	ID        int        `json:"id"`
	Publisher Reference  `json:"publisher"`
	Imprint   *Reference `json:"imprint"`
	Series    struct {
		ID       int         `json:"id"`
		Name     string      `json:"name"`
		SortName string      `json:"sort_name"`
		Volume   int         `json:"volume"`
		Type     Reference   `json:"series_type"`
		Genres   []Reference `json:"genres"`
	} `json:"series"`
	Number      string      `json:"number"`
	Title       *string     `json:"title"`
	Name        []string    `json:"name"`
	CoverDate   civil.Date  `json:"cover_date"`
	StoreDate   *civil.Date `json:"store_date"`
	Price       string      `json:"price"`
	Rating      Reference   `json:"rating"`
	SKU         *string     `json:"sku"`
	ISBN        *string     `json:"isbn"`
	UPC         *string     `json:"upc"`
	PageCount   *int        `json:"page"`
	Description *string     `json:"desc"`
	ImageURL    *URL        `json:"image"`
	CoverHash   *string     `json:"cover_hash"`
	Arcs        []ArcList   `json:"arcs"`
	Credits     []struct {
		ID    int         `json:"id"`
		Name  string      `json:"creator"`
		Roles []Reference `json:"role"`
	} `json:"credits"`
	Characters []CharacterList `json:"characters"`
	Teams      []TeamList      `json:"teams"`
	Universes  []UniverseList  `json:"universes"`
	Reprints   []struct {
		ID    int    `json:"id"`
		Issue string `json:"issue"`
	} `json:"reprints"`
	Variants []struct {
		Name     *string `json:"name"`
		SKU      *string `json:"sku"`
		UPC      *string `json:"upc"`
		ImageURL URL     `json:"image"`
	} `json:"variants"`
	ComicVineID *int      `json:"cv_id"`
	ResourceURL URL       `json:"resource_url"`
	Modified    time.Time `json:"modified"`
}

type IssueList

type IssueList struct {
	ID     int `json:"id"`
	Series struct {
		Name      string `json:"name"`
		Volume    int    `json:"volume"`
		YearBegan int    `json:"year_began"`
	} `json:"series"`
	Number    string      `json:"number"`
	Name      string      `json:"issue"`
	CoverDate civil.Date  `json:"cover_date"`
	StoreDate *civil.Date `json:"store_date"`
	ImageURL  *URL        `json:"image"`
	CoverHash *string     `json:"cover_hash"`
	Modified  time.Time   `json:"modified"`
}

type Option

type Option func(*Client)

func WithAuthentication

func WithAuthentication(username string, password string) Option

WithAuthentication sets the username and password to be used for authentication.

func WithCaching

func WithCaching(cacheDir string) Option

WithCaching enables heuristic caching. If cacheDir is empty, it will use the operating system's default location for user-specific cached data.

func WithClient

func WithClient(client *http.Client) Option

type Publisher

type Publisher struct {
	ID          int       `json:"id"`
	Name        string    `json:"name"`
	Founded     *int      `json:"founded"`
	Description *string   `json:"desc"`
	ImageURL    *URL      `json:"image"`
	ComicVineID *int      `json:"cv_id"`
	ResourceURL URL       `json:"resource_url"`
	Modified    time.Time `json:"modified"`
}

type PublisherList

type PublisherList struct {
	ID       int       `json:"id"`
	Name     string    `json:"name"`
	Modified time.Time `json:"modified"`
}

type Reference

type Reference struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type RoleList

type RoleList struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type Series

type Series struct {
	ID          int         `json:"id"`
	Name        string      `json:"name"`
	SortName    string      `json:"sort_name"`
	Volume      int         `json:"volume"`
	Type        Reference   `json:"series_type"`
	Status      string      `json:"status"`
	Publisher   Reference   `json:"publisher"`
	Imprint     *Reference  `json:"imprint"`
	YearBegan   int         `json:"year_began"`
	YearEnded   *int        `json:"year_end"`
	Description *string     `json:"desc"`
	IssueCount  int         `json:"issue_count"`
	Genres      []Reference `json:"genres"`
	Associated  []struct {
		ID   int    `json:"id"`
		Name string `json:"series"`
	} `json:"associated"`
	ComicVineID *int      `json:"cv_id"`
	ResourceURL URL       `json:"resource_url"`
	Modified    time.Time `json:"modified"`
}

type SeriesList

type SeriesList struct {
	ID         int       `json:"id"`
	Name       string    `json:"series"`
	YearBegan  int       `json:"year_began"`
	Volume     int       `json:"volume"`
	IssueCount int       `json:"issue_count"`
	Modified   time.Time `json:"modified"`
}

type SeriesTypeList

type SeriesTypeList struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type Team

type Team struct {
	ID          int            `json:"id"`
	Name        string         `json:"name"`
	Description *string        `json:"desc"`
	ImageURL    *URL           `json:"image"`
	Creators    []CreatorList  `json:"creators"`
	Universes   []UniverseList `json:"universes"`
	ComicVineID *int           `json:"cv_id"`
	ResourceURL URL            `json:"resource_url"`
	Modified    time.Time      `json:"modified"`
}

type TeamList

type TeamList struct {
	ID       int       `json:"id"`
	Name     string    `json:"name"`
	Modified time.Time `json:"modified"`
}

type URL

type URL struct {
	*url.URL
}

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(b []byte) error

type Universe

type Universe struct {
	ID          int       `json:"id"`
	Publisher   Reference `json:"publisher"`
	Name        string    `json:"name"`
	Designation *string   `json:"designation"`
	Description *string   `json:"desc"`
	ImageURL    *URL      `json:"image"`
	ResourceURL URL       `json:"resource_url"`
	Modified    time.Time `json:"modified"`
}

type UniverseList

type UniverseList struct {
	ID       int       `json:"id"`
	Name     string    `json:"name"`
	Modified time.Time `json:"modified"`
}

Jump to

Keyboard shortcuts

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