metacpan_client

package
v0.0.0-...-4a44868 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: ISC Imports: 17 Imported by: 0

README

Due to aliased generic types not being supported until 1.20, I've done a few weird things to get around this. Fortunately, we won't have to do this for very long.

Documentation

Overview

Package metacpan_client is a client for the MetaCPAN API, equivalent to MetaCPAN::Client. It is written to mirror the API and behavior as closely as possible, although the implementation varies in some places.

Index

Constants

View Source
const (
	DefaultScrollSize = 100
	DefaultScrollTime = 5 * time.Minute
	APIVersion        = "v1"
	UserAgent         = "perl_utils.metacpan.client/" + pui.PackageVersion
	MetaCPANURL       = "https://metacpan.org"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author struct {
	Blog []struct {
		URL  string `json:"url"`
		Feed string `json:"feed"`
	} `json:"blog"`
	Donation []struct {
		Name string `json:"name"`
		ID   string `json:"id"`
	} `json:"donation"`
	Links struct {
		BackCPANDirectory  string `json:"backpan_directory"`
		CPANDirectory      string `json:"cpan_directory"`
		CPANTS             string `json:"cpants"`
		CPANTestersMatrix  string `json:"cpantesters_matrix"`
		CPANTestersReports string `json:"cpantesters_reports"`
		MetaCPANExplorer   string `json:"metacpan_explorer"`
	} `json:"links"`
	PerlMongers []struct {
		Name string `json:"name"`
		ID   string `json:"id"`
	} `json:"perl_mongers"`
	Profile []struct {
		Name string `json:"name"`
		ID   string `json:"id"`
	} `json:"profile"`
	ASCIIName    string            `json:"ascii_name"`
	City         string            `json:"city"`
	Country      string            `json:"country"`
	Directory    string            `json:"dir"`
	Email        []string          `json:"email"`
	Extra        map[string]string `json:"extra"`
	GravatarUrl  string            `json:"gravatar_url"`
	Name         string            `json:"name"`
	PauseID      string            `json:"pauseid"`
	Region       string            `json:"region"`
	ReleaseCount map[string]int    `json:"release_count"`
	Updated      string            `json:"updated"`
	User         string            `json:"user"`
	Website      []string          `json:"website"`
	// contains filtered or unexported fields
}

func (*Author) MetaCPANURL

func (a *Author) MetaCPANURL() string

func (*Author) Releases

func (a *Author) Releases() (ResultSet[*Release], error)

func (*Author) UnmarshalJSON

func (a *Author) UnmarshalJSON(data []byte) error

type Client

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

Client is the main interface to the MetaCPAN API. It is equivalent to MetaCPAN::Client in Perl. It is thread-safe.

func NewClient

func NewClient(scrollSize uint16, scrollTime time.Duration, debug bool,
	domains []string) (*Client, error)

NewClient returns a new MetaCPAN client. If domain is empty, the default domain is used ("https://fastapi.metacpan.org").

func (*Client) AllAuthors

func (mc *Client) AllAuthors() (ResultSet[*Author], error)

func (*Client) AllDistributions

func (mc *Client) AllDistributions() (ResultSet[*Distribution], error)

func (*Client) AllFavorites

func (mc *Client) AllFavorites() (ResultSet[*Favorite], error)

func (*Client) AllModules

func (mc *Client) AllModules() (ResultSet[*Module], error)

func (*Client) AllReleases

func (mc *Client) AllReleases() (ResultSet[*Release], error)

func (*Client) Author

func (mc *Client) Author(s string) (*Author, error)

func (*Client) AuthorSearch

func (mc *Client) AuthorSearch(args map[string]interface{}) (
	ResultSet[*Author], error)

func (*Client) Autocomplete

func (mc *Client) Autocomplete(s string) ([]*File, error)

func (*Client) AutocompleteSuggest

func (mc *Client) AutocompleteSuggest(s string) ([]*File, error)

func (*Client) Close

func (mc *Client) Close() error

func (*Client) Cover

func (mc *Client) Cover(s string) (*Cover, error)

func (*Client) Debug

func (mc *Client) Debug() bool

func (*Client) Distribution

func (mc *Client) Distribution(s string) (*Distribution, error)

func (*Client) DistributionSearch

func (mc *Client) DistributionSearch(args map[string]interface{}) (
	ResultSet[*Distribution], error)

func (*Client) Domains

func (mc *Client) Domains() []string

func (*Client) DownloadURL

func (mc *Client) DownloadURL(release string, r *version.Range,
	dev bool) (*DownloadURL, error)

func (*Client) Favorite

func (mc *Client) Favorite(args map[string]interface{}) (ResultSet[*Favorite],
	error)

func (*Client) File

func (mc *Client) File(s string) (*File, error)

func (*Client) Mirror

func (mc *Client) Mirror(s string) (*Mirror, error)

func (*Client) Module

func (mc *Client) Module(s string) (*Module, error)

func (*Client) ModuleSearch

func (mc *Client) ModuleSearch(args map[string]interface{}) (
	ResultSet[*Module], error)

func (*Client) Package

func (mc *Client) Package(s string) (*Package, error)

func (*Client) Permission

func (mc *Client) Permission(s string) (*Permission, error)

func (*Client) Pod

func (mc *Client) Pod(s string) (*Pod, error)

func (*Client) Rating

func (mc *Client) Rating(args map[string]interface{}) (ResultSet[*Rating],
	error)

func (*Client) Recent

func (mc *Client) Recent(count int) (ResultSet[*Release], error)

func (*Client) Release

func (mc *Client) Release(s string) (*Release, error)

func (*Client) ReleaseSearch

func (mc *Client) ReleaseSearch(args map[string]interface{}) (
	ResultSet[*Release], error)

func (*Client) ReleasedToday

func (mc *Client) ReleasedToday() (ResultSet[*Release], error)

func (*Client) ReverseDependencies

func (mc *Client) ReverseDependencies(s string) (ResultSet[*Release], error)

func (*Client) UserAgent

func (mc *Client) UserAgent() string

type Cover

type Cover struct {
	Criteria struct {
		Branch     string `json:"branch"`
		Condition  string `json:"condition"`
		Statement  string `json:"statement"`
		Subroutine string `json:"subroutine"`
		Total      string `json:"total"`
	} `json:"criteria"`
	Distribution string       `json:"Distribution"`
	Release      string       `json:"release"`
	Version      version.JSON `json:"version"`
}

type Distribution

type Distribution struct {
	Name  string                            `json:"name"`
	Bugs  map[string]map[string]interface{} `json:"bugs"`
	River struct {
		Bucket    int `json:"bucket"`
		Immediate int `json:"storm"`
		Total     int `json:"total"`
	} `json:"river"`
	// contains filtered or unexported fields
}

func (*Distribution) Github

func (d *Distribution) Github() map[string]interface{}

func (*Distribution) RT

func (d *Distribution) RT() map[string]interface{}

type DownloadURL

type DownloadURL struct {
	ChecksumSHA256 string       `json:"checksum_sha256"`
	ChecksumMD5    string       `json:"checksum_md5"`
	Date           string       `json:"date"`
	DownloadURL    string       `json:"download_url"`
	Status         Status       `json:"status"`
	Version        version.JSON `json:"version"`
}

type Favorite

type Favorite struct {
	Author       string       `json:"author"`
	Date         iso8601.Time `json:"date"`
	Distribution string       `json:"distribution"`
	ID           string       `json:"id"`
	Release      string       `json:"release"`
	User         string       `json:"user"`
	// contains filtered or unexported fields
}

type File

type File struct {
	Module []struct {
		Name            string       `json:"name"`
		Indexed         bool         `json:"indexed"`
		Authorized      bool         `json:"authorized"`
		Version         version.JSON `json:"version"`
		VersionNumified float64      `json:"version_numified"`
		AssociatedPod   string       `json:"associated_pod"`
	} `json:"module"`
	Stat struct {
		MTime int `json:"mtime"`
		Mode  int `json:"mode"`
		Size  int `json:"size"`
	} `json:"stat"`
	Abstract        string       `json:"abstract"`
	Author          string       `json:"author"`
	Authorized      bool         `json:"authorized"`
	Binary          bool         `json:"binary"`
	Date            iso8601.Time `json:"date"`
	Deprecated      bool         `json:"deprecated"`
	Description     string       `json:"description"`
	Directory       bool         `json:"directory"`
	Distribution    string       `json:"distribution"`
	Documentation   string       `json:"documentation"`
	DownloadURL     string       `json:"download_url"`
	ID              string       `json:"id"`
	Indexed         bool         `json:"indexed"`
	Level           int          `json:"level"`
	Maturity        Maturity     `json:"maturity"`
	Mime            string       `json:"mime"`
	Name            string       `json:"name"`
	Path            string       `json:"path"`
	PodLines        [][]int      `json:"pod_lines"`
	Release         string       `json:"release"`
	SLOC            int          `json:"sloc"`
	Status          string       `json:"status"`
	Version         version.JSON `json:"version"`
	VersionNumified float64      `json:"version_numified"`
	// contains filtered or unexported fields
}

func (*File) MetaCPANURL

func (f *File) MetaCPANURL() string

func (*File) Pod

func (f *File) Pod(kind string) (string, error)

func (*File) Source

func (f *File) Source() (string, error)

type Maturity

type Maturity int
const (
	MaturityUndef Maturity = iota
	MaturityReleased
	MaturityDeveloper
)

func (*Maturity) MarshalJSON

func (m *Maturity) MarshalJSON() ([]byte, error)

func (*Maturity) String

func (m *Maturity) String() string

func (*Maturity) UnmarshalJSON

func (m *Maturity) UnmarshalJSON(b []byte) error

type Mirror

type Mirror struct {
	AKAName      string    `json:"aka_name"`
	AOrCName     string    `json:"A_or_CNAME"`
	CCode        string    `json:"ccode"`
	City         string    `json:"city"`
	Contact      []string  `json:"contact"`
	Country      string    `json:"country"`
	DNSRR        string    `json:"dnsrr"`
	FTP          string    `json:"ftp"`
	Freq         string    `json:"freq"`
	HTTP         string    `json:"http"`
	InceptDate   time.Time `json:"inceptdate"`
	Location     []string  `json:"location"`
	Name         string    `json:"name"`
	Note         string    `json:"note"`
	Organization string    `json:"org"`
	RSync        string    `json:"rsync"`
	Region       string    `json:"region"`
	ReitreDate   time.Time `json:"reitredate"`
	Src          string    `json:"src"`
	Tz           string    `json:"tz"`
}

type Module

type Module File

func (*Module) MetaCPANURL

func (m *Module) MetaCPANURL() string

func (*Module) Package

func (m *Module) Package() (*Package, error)

func (*Module) Permission

func (m *Module) Permission() (*Permission, error)

type Package

type Package struct {
	ModuleName   string       `json:"module_name"`
	Distribution string       `json:"distribution"`
	Version      version.JSON `json:"version"`
	DistVersion  version.JSON `json:"dist_version"`
	Author       string       `json:"author"`
}

type Permission

type Permission struct {
	ModuleName    string   `json:"module_name"`
	Owner         string   `json:"owner"`
	CoMaintainers []string `json:"co_maintainers"`
}

type Phase

type Phase int
const (
	PhaseUndef Phase = iota
	PhaseConfigure
	PhaseBuild
	PhaseRuntime
	PhaseTest
	PhaseDevelop
	PhaseXSpec
	PhaseXMentions
)

func (*Phase) MarshalJSON

func (p *Phase) MarshalJSON() ([]byte, error)

func (*Phase) String

func (p *Phase) String() string

func (*Phase) UnmarshalJSON

func (p *Phase) UnmarshalJSON(b []byte) error

type Pod

type Pod struct {
	Name      string `json:"name"`
	URLPrefix string `json:"url_prefix"`
	XPod      string `json:"x_pod"`
	HTML      string `json:"html"`
	XMarkdown string `json:"x_markdown"`
	Plain     string `json:"plain"`
	// contains filtered or unexported fields
}

func NewPod

func NewPod(name, urlPrefix string, mc *Client) (*Pod, error)

type Rating

type Rating struct {
	Date         string `json:"date"`
	Release      string `json:"release"`
	Author       string `json:"author"`
	Details      string `json:"details"`
	Rating       string `json:"rating"`
	Distribution string `json:"distribution"`
	Helpful      int    `json:"helpful"`
	User         string `json:"user"`
	// contains filtered or unexported fields
}

type Relationship

type Relationship int
const (
	RelationshipUndef Relationship = iota
	RelationshipRequires
	RelationshipRecommends
	RelationshipSuggests
	RelationshipConflicts
	RelationshipXSpec
	RelationshipXMentions
)

func (*Relationship) MarshalJSON

func (r *Relationship) MarshalJSON() ([]byte, error)

func (*Relationship) String

func (r *Relationship) String() string

func (*Relationship) UnmarshalJSON

func (r *Relationship) UnmarshalJSON(b []byte) error

type Release

type Release struct {
	Dependency []struct {
		Phase        Phase        `json:"phase"`
		Relationship Relationship `json:"relationship"`
		Module       string       `json:"module"`
		Version      version.JSON `json:"version"`
	} `json:"dependency"`
	Stat struct {
		MTime int `json:"mtime"`
		Mode  int `json:"mode"`
		Size  int `json:"size"`
	} `json:"stat"`
	Tests struct {
		Unknown int `json:"unknown"`
		Pass    int `json:"pass"`
		Fail    int `json:"fail"`
		NA      int `json:"na"`
	} `json:"tests"`
	Abstract        string       `json:"abstract"`
	Archive         string       `json:"archive"`
	Author          string       `json:"author"`
	Authorized      bool         `json:"authorized"`
	ChecksumMD5     string       `json:"checksum_md5"`
	ChecksumSHA256  string       `json:"checksum_sha256"`
	Date            string       `json:"date"`
	Deprecated      bool         `json:"deprecated"`
	Distribution    string       `json:"Distribution"`
	DownloadURL     string       `json:"download_url"`
	First           bool         `json:"first"`
	License         []string     `json:"license"`
	MainModule      string       `json:"main_module"`
	Maturity        Maturity     `json:"maturity"`
	Metadata        cm.Spec      `json:"metadata"`
	Name            string       `json:"name"`
	Provides        []string     `json:"provides"`
	Resources       cm.Resources `json:"resources"`
	Status          Status       `json:"status"`
	Version         version.JSON `json:"version"`
	VersionNumified float64      `json:"version_numified"`
	// contains filtered or unexported fields
}

func (*Release) Changes

func (r *Release) Changes() (string, error)

func (*Release) MetaCPANURL

func (r *Release) MetaCPANURL() string

func (*Release) UnmarshalJSON

func (r *Release) UnmarshalJSON(data []byte) error

type Request

type Request[T result] struct {
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest[T result](domain, baseURL string, debug bool,
	mc *Client) *Request[T]

func (*Request[T]) DisableDebug

func (r *Request[T]) DisableDebug()

func (*Request[T]) EnableDebug

func (r *Request[T]) EnableDebug()

func (*Request[T]) Fetch

func (r *Request[T]) Fetch(s string, m map[string]interface{}) (T, error)

func (*Request[T]) IsDebug

func (r *Request[T]) IsDebug() bool

func (*Request[T]) SSearch

func (r *Request[T]) SSearch(params map[string]interface{}) (*Scroll[T],
	error)

func (*Request[T]) SetClient

func (r *Request[T]) SetClient(mc *Client) error

type ResultSet

type ResultSet[T result] interface {
	json.Unmarshaler
	HasScroller() bool
	Scroller() *Scroll[T]
	Items() []T
	Aggregations() map[string]interface{}
	Next() (T, error)
	Total() int
	// contains filtered or unexported methods
}

type Scroll

type Scroll[T result] struct {
	// contains filtered or unexported fields
}

func NewScroll

func NewScroll[T result](time time.Duration, size uint16) *Scroll[T]

func (*Scroll[T]) Next

func (s *Scroll[T]) Next() (T, error)

func (*Scroll[T]) Total

func (s *Scroll[T]) Total() int

func (*Scroll[T]) UnmarshalJSON

func (s *Scroll[T]) UnmarshalJSON(data []byte) error

type Stat

type Stat struct {
	MTime int `json:"mtime"`
	Mode  int `json:"mode"`
	Size  int `json:"size"`
}

func (*Stat) UnmarshalJSON

func (s *Stat) UnmarshalJSON(data []byte) error

type Status

type Status int
const (
	ReleaseStatusUndef Status = iota
	ReleaseStatusLatest
	ReleaseStatusCPAN
	ReleaseStatusBackpan
)

func (*Status) MarshalJSON

func (s *Status) MarshalJSON() ([]byte, error)

func (*Status) String

func (s *Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) error

type Type

type Type int
const (
	TypeUndef Type = iota
	TypeAuthor
	TypeDistribution
	TypeFavorite
	TypeFile
	TypeModule
	TypeRating
	TypeRelease
)

func (*Type) MarshalJSON

func (r *Type) MarshalJSON() ([]byte, error)

func (*Type) String

func (r *Type) String() string

func (*Type) UnmarshalJSON

func (r *Type) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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