peclapi

package
v0.0.0-...-f459114 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

peclapi package implements a HTTP-based client for the REST API initially used by pecl. It only supports the default pecl channel served at https://pecl.php.net/rest/. Note that this API is quite dated and might return some unexpected results (eg. redis extension is in the Database category but ListPackagesInCategory("Database") won't return redis).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents the HTTP-based client for https://pecl.php.net/rest/.

func NewClient

func NewClient(opts ...ClientOpt) Client

NewClient creates a new HTTP-based client for the API hosted at pecl.php.net/rest/. It takes ClientOpt as arguments. These could be used to set Client's internal properties (baseURI or httpClient).

func (Client) DescribePackage

func (c Client) DescribePackage(pkgName string) (Package, error)

DescribePackage returns the details of a given package as served by the endpoint /p/{packageName}/info.xml. It returns an error if the request fails or if the endpoint returns a non-200 status code.

func (Client) DescribeRelease

func (c Client) DescribeRelease(pkgName, pkgVersion string) (Release, error)

DescribeRelease returns the details about a given release of a given package, as served by the endpoint /r/{packageName}/{release}.xml. It returns an error if the request fails or if the endpoint returns a non-200 status code.

func (Client) DownloadRelease

func (c Client) DownloadRelease(release Release) (io.Reader, error)

DownloadRelease downloads a given package release and returns an io.ReadCloser from which a tgz can be read. An error is returned if the HTTP request fails, if a bad status code is returned or if the downloaded file is not an application/x-gzip.

func (Client) ListPackages

func (c Client) ListPackages() ([]string, error)

ListPackages returns the list of packages available at the endpoint /p/packages.xml. It returns an error if the HTTP request fails or if the endpoint returns a non-200 status code.

func (Client) ListPackagesInCategory

func (c Client) ListPackagesInCategory(category string) ([]string, error)

ListPackagesInCategory returns the list of packages in the given category, as served by the endpoint /c/{category}/package.xml. It returns an error if the request fails or if th endpoint returns a non-200 status code.

func (Client) ListReleases

func (c Client) ListReleases(pkgName string) (PackageReleases, error)

ListReleases returns the list of releases associated with their stability for a given package, as served by the endpoint /r/{packageName}/allreleases.xml. It returns an error if the request fails or if the endpoint returns a non-200 status code.

type ClientOpt

type ClientOpt func(*Client)

ClientOpt are functions used by NewClient() to set Clients' internal properties.

func WithBaseURI

func WithBaseURI(baseURI string) ClientOpt

WithBaseURI returns a ClientOpt that could be passed to NewClient to set the API base URI.

func WithHttpClient

func WithHttpClient(httpClient *http.Client) ClientOpt

WithHttpClient returns a ClientOpt that could be passed to NewClient to set the HTTP client used to query the API.

type Package

type Package struct {
	Name               string `xml:"n"`
	Category           string `xml:"ca"`
	License            string `xml:"l"`
	Summary            string `xml:"s"`
	Description        string `xml:"d"`
	ReleasesLocation   string `xml:"r"`
	ParentPackage      string `xml:"pa"`
	DeprecatingPackage string `xml:"dp"`
	DeprecatingChannel string `xml:"dc"`
}

Package represents a detailed package as returned by DescribePackage(). See https://pear.php.net/dtd/rest.package.xsd.

type PackageReleases

type PackageReleases map[string]Stability

PackageReleases is the list of releases associated to their stability for a given package. It supports sorting.

func (PackageReleases) Sort

func (pr PackageReleases) Sort() []string

Sort returns a slice containing the releases of the package sorted in descending order.

type Release

type Release struct {
	Package      string `xml:"p"`
	Version      string `xml:"v"`
	Stability    string `xml:"st"`
	License      string `xml:"l"`
	Maintainer   string `xml:"m"`
	Summary      string `xml:"s"`
	Description  string `xml:"d"`
	ReleaseDate  string `xml:"da"`
	ReleaseNotes string `xml:"n"`
	PartialURI   string `xml:"g"`
	PackageXML   string `xml:"x"`
}

Release represents the details of a specific release of a package. See https://pear.php.net/dtd/rest.release.xsd.

type Stability

type Stability int
const (
	Unknown Stability = iota
	Snapshot
	Devel
	Alpha
	Beta
	Stable
)

func StabilityFromString

func StabilityFromString(s string) Stability

func (Stability) String

func (s Stability) String() string

Jump to

Keyboard shortcuts

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