pouet

package
v1.5.16 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package pouet provides production, user voting data sourced from the Pouet website API.

Index

Constants

View Source
const (
	ProdURL     = "https://api.pouet.net/v1/prod/?id=" // ProdURL is the base URL for the Pouet production API.
	StarRounder = 0.5                                  // StarRounder is the rounding value for the stars rating.
	Sanity      = 200000                               // Sanity is to check the maximum permitted production ID.

)

Variables

View Source
var (
	ErrID      = errors.New("id is invalid")
	ErrSuccess = errors.New("not found")
	ErrStatus  = errors.New("status is not ok")
)

Functions

func PlatformsValid

func PlatformsValid(s string) bool

func Stars

func Stars(up, ok, down uint64) float64

Stars returns the number of stars for the average votes. The value of votesAvg must be a valid float64 value and not greater than 1.0.

func TypesValid

func TypesValid(s string) bool

Types

type Platform

type Platform struct {
	Name string `json:"name"`
	Slug string `json:"slug"`
}

Platform is the production platform data from the Pouet API.

type Platforms

type Platforms struct {
	DosGus  Platform `json:"69"` // MS-Dos with GUS
	Windows Platform `json:"68"` // Windows
	MSDos   Platform `json:"67"` // MS-Dos
}

Platforms are the supported platforms from the Pouet API.

func (Platforms) String

func (p Platforms) String() string

func (Platforms) Valid

func (p Platforms) Valid() bool

type Production

type Production struct {
	ID          int    `json:"id"`           // ID is the prod ID.
	Title       string `json:"title"`        // Title is the prod title.
	ReleaseDate string `json:"release_date"` // ReleaseDate is the prod release date.
	Download    string `json:"download"`     // Download is the first download link.
	Demozoo     string `json:"demozoo"`      // Demozoo is the Demozoo identifier.
	Groups      []struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"groups"` // Groups are the releasers that produced the prod.
	Platforms Platforms `json:"platforms"` // Platforms are the platforms the prod runs on.
	Platform  string    `json:"platform"`  // Platform is the prod platforms as a string.
	Types     Types     `json:"types"`     // Types are the prod types.
	Links     []struct {
		Type string `json:"type"`
		Link string `json:"link"`
	} `json:"downloads"` // Downloads are the additional download links.
	Valid bool `json:"valid"` // Valid is true if this prod is a supported type and platform.
}

Production is the production data from the Pouet API. The Pouet API returns values as null or string, so this struct is used to normalize the data types.

func (*Production) Get

func (p *Production) Get(id int) (int, error)

Get requests data for a production record from the Pouet API. It returns an error if the production ID is invalid, when the request reaches a [Timeout] or fails. A status code is returned when the response status is not OK.

func (Production) PlatformType

func (p Production) PlatformType() (tags.Tag, tags.Tag)

PlatformType parses the Pouet "platform" and "type" data and returns the corresponding platform and section tags. It returns -1 for an unknown platform or section.

func (Production) Released

func (p Production) Released() (int16, int16, int16)

Released returns the production's release date as date_issued_ year, month, day values.

func (Production) Releasers

func (p Production) Releasers() (string, string)

Releasers returns the first two names in the production that have is_group as true. The one exception is if the production title contains a reference to a BBS or FTP site name. Then that title will be used as the first group returned.

type Response

type Response struct {
	Prod struct {
		ID          string `json:"id"`          // ID is the prod ID.
		Title       string `json:"name"`        // Title is the prod title.
		ReleaseDate string `json:"releaseDate"` // ReleaseDate is the prod release date.
		Voteup      string `json:"voteup"`      // Voteup is the number of thumbs up votes.
		Votepig     string `json:"votepig"`     // Votepig is the number of meh votes.
		Votedown    string `json:"votedown"`    // Votedown is the number of thumbs down votes.
		Voteavg     string `json:"voteavg"`     // Voteavg is the average votes, the maximum value is 1.0.
		Download    string `json:"download"`    // Download is the first download link.
		Demozoo     string `json:"demozoo"`     // Demozoo is the first Demozoo link.
		Groups      []struct {
			ID   string `json:"id"`
			Name string `json:"name"`
		} `json:"groups"` // Groups are the releasers that produced the prod.
		Platforms     Platforms `json:"platforms"` // Platforms are the platforms the prod runs on.
		Types         Types     `json:"types"`     // Types are the prod types.
		DownloadLinks []struct {
			Type string `json:"type"`
			Link string `json:"link"`
		} `json:"downloadLinks"` // DownloadLinks are the additional download links.
	} `json:"prod"` // Prod is the production data.
	Success bool `json:"success"` // Success is true if the prod data was found.
}

Response is the JSON response from the Pouet API with production voting data.

func (*Response) Get

func (r *Response) Get(id int) (int, error)

Get retrieves the production voting data from the Pouet API. The id value is the Pouet production ID and must be greater than 0.

type Type

type Type string

Type is the production type from the Pouet API.

func (Type) Valid

func (t Type) Valid() bool

type Types

type Types []Type

Types are the production types from the Pouet API.

func (Types) String

func (t Types) String() string

func (Types) Valid

func (t Types) Valid() bool

type Votes

type Votes struct {
	// ID is the production ID.
	ID int `json:"id"`
	// Stars is the production rating using the average votes multiplied by 5.
	Stars float64 `json:"stars"`
	// VotesAvg is the average votes, the maximum value is 1.0.
	VotesAvg float64 `json:"votes_avg"`
	// VotesUp is the number of thumbs up votes.
	VotesUp uint64 `json:"votes_up"`
	// VotesMeh is the number of meh votes otherwise called piggies.
	VotesMeh uint64 `json:"votes_meh"`
	// VotesDown is the number of thumbs down votes.
	VotesDown uint64 `json:"votes_down"`
}

Votes is the production voting data from the Pouet API. The Pouet API returns values as null or string, so this struct is used to normalize the data types.

func (*Votes) Votes

func (v *Votes) Votes(id int) error

Votes retrieves the production voting data from the Pouet API. The id value is the Pouet production ID and must be greater than 0. The data is intended for the Artifact page, Pouët reviews section.

Jump to

Keyboard shortcuts

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