osuapi

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = fmt.Errorf("resource not found")
)

Functions

func Do

func Do(req *http.Request) (*http.Response, error)

func DoAndParse

func DoAndParse[T any](req *http.Request) (val T, err error)

func NewAPIv2Request

func NewAPIv2Request(ctx context.Context, method, path string, body io.Reader) (*http.Request, error)

func NewWebRequest

func NewWebRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error)

func SetAuthHeader

func SetAuthHeader(req *http.Request, accessToken string)

func SetDefaultHeaders

func SetDefaultHeaders(req *http.Request)

Types

type BatchResponse

type BatchResponse struct {
	Users []UserFromBatch `json:"users"`
}

type Beatmap

type Beatmap struct {
	ID               int     `json:"id"`
	DifficultyRating float32 `json:"difficulty_rating"`
	TotalLength      int     `json:"total_length"`
	MaxCombo         int     `json:"max_combo"`
}

type BeatmapExtended

type BeatmapExtended struct {
	Beatmap
	AR           float32 `json:"ar"`
	BPM          float32 `json:"bpm"`
	BeatmapSetId int     `json:"beatmapset_id"`
}

type BeatmapSet

type BeatmapSet struct {
	Artist         string `json:"artist"`
	Title          string `json:"title"`
	PreviewURL     string `json:"preview_url"`
	FavouriteCount int    `json:"favourite_count"`
	Covers         Covers `json:"covers"`
}

type Client

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

func NewClient

func NewClient(clientID, clientSecret string) *Client

func (*Client) DownloadReplay

func (c *Client) DownloadReplay(ctx context.Context, accessToken string, scoreId int) ([]byte, error)

func (*Client) ExchangeToken

func (c *Client) ExchangeToken(ctx context.Context, code, redirectUri string) (ExchangeTokenResponse, error)

func (*Client) GetClientAccessToken

func (c *Client) GetClientAccessToken(ctx context.Context) (ClientToken, error)

func (*Client) GetMe

func (c *Client) GetMe(ctx context.Context, accessToken string) (UserExtended, error)

func (*Client) GetMultiRooms

func (c *Client) GetMultiRooms(ctx context.Context, accessToken string) ([]MultiRoom, error)

func (*Client) GetRankings

func (c *Client) GetRankings(ctx context.Context, accessToken string, cursor *Cursor, opts ...RankingsOpts) (Rankings, error)

func (*Client) GetScore

func (c *Client) GetScore(ctx context.Context, accessToken string, scoreId int) (Score, error)

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, accessToken string, userId int) (UserExtended, error)

func (*Client) GetUserScores

func (c *Client) GetUserScores(ctx context.Context, accessToken string, userId int, limit, offset int) ([]Score, error)

func (*Client) GetUsers

func (c *Client) GetUsers(ctx context.Context, accessToken string, userIds []int) (BatchResponse, error)

func (*Client) TokenRefresh

func (c *Client) TokenRefresh(ctx context.Context, refreshToken string) (ExchangeTokenResponse, error)

type ClientToken

type ClientToken struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
}

type Covers

type Covers struct {
	SlimCoverURL string `json:"slimcover"`
}

type Cursor

type Cursor struct {
	Page int `json:"page"`
}

type ExchangeTokenResponse

type ExchangeTokenResponse struct {
	// always "Bearer"
	TokenType    string `json:"token_type"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
}

func (ExchangeTokenResponse) ExpiresAt

func (r ExchangeTokenResponse) ExpiresAt() time.Time

type MultiRoom

type MultiRoom struct {
	RecentParticipants []User `json:"recent_participants"`
}

type Rankings

type Rankings struct {
	Cursor  *Cursor     `json:"cursor"`
	Ranking []UserStats `json:"ranking"`
}

type RankingsOpts

type RankingsOpts struct {
	Country *string
}

type Ruleset

type Ruleset string
var (
	ModeStandard Ruleset = "osu"
	ModeTaiko    Ruleset = "taiko"
	ModeCatch    Ruleset = "fruits"
	ModeMania    Ruleset = "mania"
)

type Score

type Score struct {
	ID           int             `json:"id"`
	PP           float32         `json:"pp"`
	Mods         []ScoreMod      `json:"mods"`
	Accuracy     float32         `json:"accuracy"`
	BeatmapID    int             `json:"beatmap_id"`
	HasReplay    bool            `json:"has_replay"`
	ReplayLegacy bool            `json:"replay"`
	UserId       int             `json:"user_id"`
	User         User            `json:"user"`
	Statistics   ScoreStatistics `json:"statistics"`
	BeatmapSet   BeatmapSet      `json:"beatmapset"`
	Beatmap      BeatmapExtended `json:"beatmap"`
}

func (Score) ModsAcronyms

func (s Score) ModsAcronyms() []string

func (Score) Replay

func (s Score) Replay() bool

type ScoreMod

type ScoreMod struct {
	Acronym string `json:"acronym"`
}

type ScoreStatistics

type ScoreStatistics struct {
	Great *int `json:"great"`
	Ok    *int `json:"ok"`
	Meh   *int `json:"meh"`
	Miss  *int `json:"miss"`
}

type User

type User struct {
	ID          int            `json:"id"`
	Username    string         `json:"username"`
	AvatarURL   string         `json:"avatar_url"`
	CountryCode string         `json:"country_code"`
	IsActive    bool           `json:"is_active"`
	IsBot       bool           `json:"is_bot"`
	IsDeleted   bool           `json:"is_deleted"`
	IsOnline    bool           `json:"is_online"`
	IsSupporter bool           `json:"is_supporter"`
	LastVisit   time.Time      `json:"last_visit"`
	Statistics  UserStatistics `json:"statistics"`
}

type UserExtended

type UserExtended struct {
	User
	// deprecated, use cover.url instead
	CoverURL string `json:"cover_url"`

	Discord      string    `json:"discord"`
	HasSupported bool      `json:"has_supported"`
	Interests    string    `json:"interests"`
	JoinDate     time.Time `json:"join_date"`
	Location     *string   `json:"location"`
	MaxBlocks    int       `json:"max_blocks"`
	MaxFriends   int       `json:"max_friends"`
	Occupation   *string   `json:"occupation"`
	Playmode     string    `json:"playmode"`
	Playstyle    []string  `json:"playstyle"`
	PostCount    int       `json:"post_count"`
	ProfileHue   *int      `json:"profile_hue"`
	// TODO: dont really care about these, maybe add them later if needed
	ProfileOrder []string `json:"profile_order"`
	Title        *string  `json:"title"`
	TitleURL     *string  `json:"title_url"`
	Twitter      *string  `json:"twitter"`
	Website      *string  `json:"website"`
}

type UserFromBatch

type UserFromBatch struct {
	ID                 int       `json:"id"`
	Username           string    `json:"username"`
	AvatarURL          string    `json:"avatar_url"`
	CountryCode        string    `json:"country_code"`
	IsActive           bool      `json:"is_active"`
	IsBot              bool      `json:"is_bot"`
	IsDeleted          bool      `json:"is_deleted"`
	IsOnline           bool      `json:"is_online"`
	IsSupporter        bool      `json:"is_supporter"`
	LastVisit          time.Time `json:"last_visit"`
	StatisticsRulesets struct {
		Standard UserStatistics `json:"osu"`
	} `json:"statistics_rulesets"`
}

TODO

type UserStatistics

type UserStatistics struct {
	PP         float32 `json:"pp"`
	GlobalRank int     `json:"global_rank"`
}

type UserStats

type UserStats struct {
	GlobalRank int     `json:"global_rank"`
	PP         float32 `json:"pp"`
	User       User    `json:"user"`
}

Jump to

Keyboard shortcuts

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