api

package
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package api is a client for the minepkg API https://api.minepkg/docs

Index

Constants

View Source
const (
	// TypeMod indicates a mod
	TypeMod = "mod"
	// TypeModpack indicates a modpack
	TypeModpack = "modpack"
)

Variables

View Source
var (
	// ErrNotFound gets returned when a 404 occurred
	ErrNotFound = errors.New("resource not found")
	// ErrBadRequest gets returned when a 400 occurred
	ErrBadRequest = errors.New("bad Request")
	// DefaultURL is "https://api.preview.minepkg.io/v1"
	DefaultURL = "https://api.preview.minepkg.io/v1"
)
View Source
var (
	ErrNoReleasesForPlatform        = errors.New("project has no releases for this platform")
	ErrProjectDoesNotExist          = errors.New("project does not exist")
	ErrNoReleaseForMinecraftVersion = errors.New("no release exists for the wanted Minecraft version")
	ErrNoReleaseForVersion          = errors.New("no release exists for the wanted Version")
	ErrNoReleaseWithConstrains      = errors.New("no release exists for the given version/minecraft requirement")
)
View Source
var ErrInvalidMinecraftRequirement = errors.New("minecraft requirement is invalid. Only * or a version number is allowed. No semver")

ErrInvalidMinecraftRequirement is returned if an invalid minecraft requirement was passed

Functions

This section is empty.

Types

type CrashReport

type CrashReport struct {
	Package          CrashReportPackage       `json:"package"`
	Fabric           *CrashReportFabricDetail `json:"fabric,omitempty"`
	Forge            *CrashReportForgeDetail  `json:"forge,omitempty"`
	MinecraftVersion string                   `json:"minecraftVersion"`
	Server           bool                     `json:"server"`
	Mods             map[string]string        `json:"mods"`
	Logs             string                   `json:"logs,omitempty"`
	OS               string                   `json:"os,omitempty"`
	Arch             string                   `json:"arch,omitempty"`
	JavaVersion      string                   `json:"javaVersion,omitempty"`
	ExitCode         int                      `json:"exitCode,omitempty"`
}

CrashReport is a crash report

type CrashReportFabricDetail

type CrashReportFabricDetail struct {
	Loader  string `json:"loader"`
	Mapping string `json:"mapping"`
}

CrashReportFabricDetail is a the fabric part of the crash report

type CrashReportForgeDetail

type CrashReportForgeDetail struct {
	Loader string `json:"loader"`
}

CrashReportForgeDetail is a the forge part of the crash report

type CrashReportPackage

type CrashReportPackage struct {
	Name     string `json:"name"`
	Platform string `json:"platform"`
	Version  string `json:"version"`
}

CrashReportPackage is a package in a crash report

type Dependency

type Dependency struct {
	// Provider is only minepkg for now. Kept for future extensions
	Provider string `json:"provider"`
	// Name is the name of the package (eg. storage-drawers)
	Name string `json:"name"`
	// VersionRequirement is a semver version Constraint
	// Example: `^2.9.22` or `5.x.x`
	VersionRequirement string `json:"versionRequirement"`
}

Dependency in verbose form

type ErrNoMatchingRelease

type ErrNoMatchingRelease struct {
	// Package is the name of the package that can not be resolved
	Package string
	// Requirements are the requirements for this package to resolve (eg. minecraft version)
	Requirements *RequirementQuery
	// Err is the underlying error that describes why there is no matching release
	Err error
}

ErrNoMatchingRelease is returned if a wanted package (release) could not be resolved given the requirements

func (*ErrNoMatchingRelease) Error

func (e *ErrNoMatchingRelease) Error() string

type ErrNoQueryResult added in v0.0.64

type ErrNoQueryResult struct {
	// Query is the query that did not resolve
	Query *ReleasesQuery
	// Err is the underlying error that describes why there was no package found
	Err error
}

ErrNoMatchingRelease is returned if a wanted package query could not be resolved

func (*ErrNoQueryResult) Error added in v0.0.64

func (e *ErrNoQueryResult) Error() string

type ForgeVersion

type ForgeVersion struct {
	Branch      string     `json:"branch"`
	Build       int        `json:"build"`
	Files       [][]string `json:"files"`
	McVersion   string     `json:"mcversion"`
	Modified    int        `json:"modified"`
	Version     string     `json:"version"`
	Recommended bool       `json:"recommended"`
}

ForgeVersion is a release of forge

type GetProjectsQuery

type GetProjectsQuery struct {
	Type     string `json:"type"`
	Platform string `json:"platform"`
	Simple   bool   `json:"simple"`
}

GetProjectsQuery are the query parameters for the GetProjects function

type MinepkgClient added in v0.1.23

type MinepkgClient struct {
	// HTTP is the internal http client
	HTTP *http.Client
	// BaseAPI is the API url used. defaults to `https://api.preview.minepkg.io/v1`
	APIUrl string
	APIKey string
	JWT    string
	User   *User
}

MinepkgClient contains credentials and methods to talk to the minepkg api

func New

func New() *MinepkgClient

New returns a new MinepkgAPI client

func NewWithCustomHTTP added in v0.1.23

func NewWithCustomHTTP(client *http.Client) *MinepkgClient

NewWithCustomHTTP returns a new MinepkgAPI client using a custom http client supplied as a first parameter

func (*MinepkgClient) CreateProject added in v0.1.23

func (m *MinepkgClient) CreateProject(p *Project) (*Project, error)

CreateProject creates a new project

func (*MinepkgClient) DecorateRequest added in v0.1.23

func (m *MinepkgClient) DecorateRequest(req *http.Request)

DecorateRequest decorates a provided http request with the User-Agent header and a auth header if set

func (*MinepkgClient) DeleteRelease added in v0.1.23

func (m *MinepkgClient) DeleteRelease(ctx context.Context, platform string, identifier string) (*Release, error)

DeleteRelease gets a single release from a project `identifier` is a project@version string

func (*MinepkgClient) FindRelease added in v0.1.23

func (m *MinepkgClient) FindRelease(ctx context.Context, project string, reqs *RequirementQuery) (*Release, error)

FindRelease gets the latest release matching the passed requirements via `RequirementQuery`

func (*MinepkgClient) GetAccount added in v0.1.23

func (m *MinepkgClient) GetAccount(ctx context.Context) (*User, error)

GetAccount gets the account information of the current user

func (*MinepkgClient) GetProject added in v0.1.23

func (m *MinepkgClient) GetProject(ctx context.Context, name string) (*Project, error)

GetProject gets a single project

func (*MinepkgClient) GetProjectStats added in v0.1.23

func (m *MinepkgClient) GetProjectStats(ctx context.Context, name string) (*ProjectStats, error)

GetProjectStats gets the statistics for a project

func (*MinepkgClient) GetProjects added in v0.1.23

func (m *MinepkgClient) GetProjects(ctx context.Context, opts *GetProjectsQuery) ([]Project, error)

GetProjects gets all projects matching a query

func (*MinepkgClient) GetRelease added in v0.1.23

func (m *MinepkgClient) GetRelease(ctx context.Context, platform string, identifier string) (*Release, error)

GetRelease gets a single release from a project `identifier` is a project@version string

func (*MinepkgClient) GetReleaseList added in v0.1.23

func (m *MinepkgClient) GetReleaseList(ctx context.Context, project string) ([]*Release, error)

GetReleaseList gets a all available releases for a project

func (*MinepkgClient) HasCredentials added in v0.1.23

func (m *MinepkgClient) HasCredentials() bool

HasCredentials returns true if a jwt or api is set

func (*MinepkgClient) NewRelease added in v0.1.23

func (a *MinepkgClient) NewRelease(m *manifest.Manifest) *Release

NewRelease returns a `Release` object. Only exists locally. Can be used to POST a new release to the API

func (*MinepkgClient) NewUnpublishedRelease added in v0.1.23

func (a *MinepkgClient) NewUnpublishedRelease(m *manifest.Manifest) *Release

NewUnpublishedRelease returns a `Release` object that has `Meta.published` set to false. should be used if you want to upload an artifact after publishing this release Only exists locally. Can be used to POST a new release to the API

func (*MinepkgClient) OAuthLogin added in v0.1.23

func (m *MinepkgClient) OAuthLogin(c *OAuthLoginConfig) *oauth2.Token

OAuthLogin opens a browser that prompts the user to authorize this app and returns oauth credentials

func (*MinepkgClient) PostCrashReport added in v0.1.23

func (m *MinepkgClient) PostCrashReport(ctx context.Context, report *CrashReport) error

PostCrashReport posts a new crash report

func (*MinepkgClient) PostProjectMedia added in v0.1.23

func (m *MinepkgClient) PostProjectMedia(ctx context.Context, project string, content io.Reader) error

PostProjectMedia uploads a new image to a project

func (*MinepkgClient) Project added in v0.1.23

func (m *MinepkgClient) Project(name string) *Project

Project returns a Project object without fetching it from the API

func (*MinepkgClient) PutRelease added in v0.1.23

func (m *MinepkgClient) PutRelease(project string, version string, reader io.Reader) (*Release, error)

PutRelease uploads a new release

func (*MinepkgClient) ReleasesQuery added in v0.1.23

func (m *MinepkgClient) ReleasesQuery(ctx context.Context, query *ReleasesQuery) (*Release, error)

FindRelease gets the latest release matching the passed requirements via `RequirementQuery`

type MinepkgError

type MinepkgError struct {
	StatusCode uint16 `json:"statusCode"`
	Status     string `json:"error"`
	Message    string `json:"message"`
	// ResolveError is only present for release queries
	ResolveError string `json:"resolveError"`
}

MinepkgError is the json response if the response was not successful

func (MinepkgError) Error

func (m MinepkgError) Error() string

type OAuthLoginConfig

type OAuthLoginConfig struct {
	ClientID     string
	ClientSecret string
	Scopes       []string
}

OAuthLoginConfig describes your oauth app

type Project

type Project struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Description string `json:"description,omitempty"`
	Readme      string `json:"readme,omitempty"`
	Links       struct {
		Source   string `json:"source,omitempty"`
		Homepage string `json:"homepage,omitempty"`
	} `json:"links,omitempty"`
	Categories []string `json:"categories,omitempty"`
	Stats      *struct {
		TotalDownloads uint32 `json:"totalDownloads"`
	} `json:"stats,omitempty"`
	Unofficial bool `json:"unofficial,omitempty"`
	// contains filtered or unexported fields
}

Project is a project

func (*Project) CreateRelease

func (p *Project) CreateRelease(ctx context.Context, r *Release) (*Release, error)

CreateRelease will create a new release

func (*Project) GetReleases

func (p *Project) GetReleases(ctx context.Context, platform string) (ReleaseList, error)

GetReleases gets a all available releases for this project

type ProjectStats

type ProjectStats struct {
	Summary struct {
		TotalDownloads int `json:"totalDownloads"`
		Releases       int `json:"releases"`
		Likes          int `json:"likes"`
	} `json:"summary"`
	Downloads []struct {
		Downloads int       `json:"downloads"`
		Date      time.Time `json:"date"`
	} `json:"downloads"`
}

type Release

type Release struct {
	*manifest.Manifest

	Meta  *ReleaseMeta           `json:"meta,omitempty"`
	Tests map[string]ReleaseTest `json:"tests,omitempty"`
	// contains filtered or unexported fields
}

Release is a released version of a project

func (*Release) DownloadURL

func (r *Release) DownloadURL() string

DownloadURL returns the download url for this release

func (*Release) Filename

func (r *Release) Filename() string

Filename returns this release in a "project@version.jar" format. eg: `fabric@0.2.0.jar`

func (*Release) Identifier

func (r *Release) Identifier() string

Identifier returns this release in a "project@version" format. eg: `fabric@0.2.0`

func (*Release) LatestTestedMinecraftVersion

func (r *Release) LatestTestedMinecraftVersion() string

LatestTestedMinecraftVersion returns the last (highest) tested Minecraft version for this release

func (*Release) SemverVersion

func (r *Release) SemverVersion() *semver.Version

SemverVersion returns the Version as a `semver.Version` struct

func (*Release) Upload

func (r *Release) Upload(reader io.Reader, size int64) (*Release, error)

Upload uploads the jar or zip file for a release

func (*Release) WorksWithManifest

func (r *Release) WorksWithManifest(man *manifest.Manifest) bool

WorksWithManifest returns if this release was tested to the manifest requirements (currently only checks mc version)

type ReleaseList

type ReleaseList []*Release

ReleaseList is a slice of releases with a helper function

func (*ReleaseList) Latest

func (r *ReleaseList) Latest() *Release

Latest returns the latest release from the release list based on the semver version number

type ReleaseMeta

type ReleaseMeta struct {
	IPFSHash   string     `json:"ipfsHash,omitempty"`
	Sha256     string     `json:"sha256,omitempty"`
	Published  bool       `json:"published"`
	Unofficial *bool      `json:"unofficial,omitempty"`
	CreatedAt  *time.Time `json:"createdAt,omitempty"`
}

ReleaseMeta is metadata for a release. found in the `meta` field

type ReleaseTest

type ReleaseTest struct {
	ID        string `json:"_id"`
	Minecraft string `json:"minecraft"`
	Works     bool   `json:"works"`
}

ReleaseTest is a test of the package

type ReleasesQuery added in v0.0.63

type ReleasesQuery struct {
	// Platform can bei either fabric or forge
	Platform string
	// Name should be the name of the wanted package
	Name string
	// Minecraft version for the project. This has to be either ” or a valid version number.
	// a semver string is NOT allowed here
	Minecraft string
	// VersionRange can be any semver string specifying the desired package version
	VersionRange string
}

ReleasesQuery is a query to find a release

type RequirementQuery

type RequirementQuery struct {
	// Version to return. this can be any semver string
	Version string
	// Minecraft version for the project. This has to be either '*' or a valid version number.
	// any semver string is NOT allowed here
	Minecraft string
	// Platform can bei either fabric or forge
	Platform string
}

RequirementQuery is a query for a release describing contained requirements

type Requirements

type Requirements struct {
	Minecraft string `json:"minecraft"`
	Forge     string `json:"forge,omitempty"`
	Fabric    string `json:"fabric,omitempty"`
}

Requirements contains the wanted Minecraft version and either the required Forge or Fabric version

type User

type User struct {
	DisplayName string `json:"displayName"`
	Email       string `json:"email"`
}

User describes a registered user

Jump to

Keyboard shortcuts

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