osu_go_client

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2020 License: MIT Imports: 13 Imported by: 1

README

osu!lazer api client

Features

  1. Lazer version
  2. Thread-safe
  3. Auto refresh access_token
  4. ...

Using

need to import package

"github.com/deissh/osu-go-client"
api := osu_go_client.WithAccessToken(
    os.Getenv("access_token"),
    os.Getenv("refresh_token"),
)

data, err := api.BeatmapSet.Get(23416)
if err != nil {
    // error
    return
}

// data.ID
// data.Title
// ...

You can also use one client in different goroutines

api := osu_go_client.WithAccessToken(
    os.Getenv("access_token"),
    os.Getenv("refresh_token"),
)

beatMapIds := []uint{141515, 514551, 23416, 261441}

// run new goroutines for each beatMapId
for _, id := range beatMapIds {
    go func(beatMapId uint) {
        data, err := api.BeatmapSet.Get(23416)
        if err != nil {
            log.Fatal(err)
        }

        log.Println(data)
    }(id)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default api domain
	// Can be change before create api client
	APIDomain = "https://osu.ppy.sh"
	// OAuth2 client id
	// Required for create access_token or refresh its
	APIClientId = "5"
	// OAuth2 client secret
	APIClientSecret = "FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk"
)

Functions

This section is empty.

Types

type Availability added in v1.1.0

type Availability struct {
	DownloadDisabled bool              `json:"download_disabled"`
	MoreInformation  map[string]string `json:"more_information"`
}

type Beatmap added in v1.1.0

type Beatmap struct {
	ID               int64     `json:"id"`
	BeatmapsetID     int64     `json:"beatmapset_id"`
	Mode             Mode      `json:"mode"`
	ModeInt          int64     `json:"mode_int"`
	Convert          bool      `json:"convert"`
	DifficultyRating float64   `json:"difficulty_rating"`
	Version          string    `json:"version"`
	TotalLength      int64     `json:"total_length"`
	HitLength        int64     `json:"hit_length"`
	BPM              float64   `json:"bpm"`
	CS               float64   `json:"cs"`
	Drain            float64   `json:"drain"`
	Accuracy         float64   `json:"accuracy"`
	Ar               float64   `json:"ar"`
	Playcount        int64     `json:"playcount"`
	Passcount        int64     `json:"passcount"`
	CountCircles     int64     `json:"count_circles"`
	CountSliders     int64     `json:"count_sliders"`
	CountSpinners    int64     `json:"count_spinners"`
	CountTotal       int64     `json:"count_total"`
	IsScoreable      bool      `json:"is_scoreable"`
	LastUpdated      time.Time `json:"last_updated"`
	Ranked           int64     `json:"ranked"`
	Status           Status    `json:"status"`
	URL              string    `json:"url"`
	DeletedAt        time.Time `json:"deleted_at"`
	Failtimes        Failtimes `json:"failtimes"`
	MaxCombo         *int64    `json:"max_combo"`
}

type BeatmapAPI added in v1.1.0

type BeatmapAPI struct {
	*OsuAPI
}

func (*BeatmapAPI) Get added in v1.1.0

func (b *BeatmapAPI) Get(id uint) (*SingleBeatmap, error)

Get general beatmap information by beatmapId

type BeatmapSet added in v1.1.0

type BeatmapSet struct {
	ID                int64        `json:"id"`
	Title             string       `json:"title"`
	Artist            string       `json:"artist"`
	PlayCount         int64        `json:"play_count"`
	FavouriteCount    int64        `json:"favourite_count"`
	HasFavourited     bool         `json:"has_favourited"`
	SubmittedDate     time.Time    `json:"submitted_date"`
	LastUpdated       time.Time    `json:"last_updated"`
	RankedDate        time.Time    `json:"ranked_date"`
	Creator           string       `json:"creator"`
	UserID            int64        `json:"user_id"`
	BPM               float64      `json:"bpm"`
	Source            string       `json:"source"`
	Covers            Covers       `json:"covers"`
	PreviewURL        string       `json:"preview_url"`
	Tags              string       `json:"tags"`
	Video             bool         `json:"video"`
	Storyboard        bool         `json:"storyboard"`
	Ranked            int64        `json:"ranked"`
	Status            Status       `json:"status"`
	IsScoreable       bool         `json:"is_scoreable"`
	DiscussionEnabled bool         `json:"discussion_enabled"`
	DiscussionLocked  bool         `json:"discussion_locked"`
	CanBeHyped        bool         `json:"can_be_hyped"`
	Availability      Availability `json:"availability"`
	Hype              Hype         `json:"hype"`
	Nominations       Hype         `json:"nominations"`
	LegacyThreadURL   string       `json:"legacy_thread_url"`
	Description       Description  `json:"description"`
	Genre             Genre        `json:"genre"`
	Language          Genre        `json:"language"`
	User              User         `json:"user"`

	Beatmaps []Beatmap `json:"beatmaps"`
}

type BeatmapSetAPI

type BeatmapSetAPI struct {
	*OsuAPI
}

func (*BeatmapSetAPI) Get

func (b *BeatmapSetAPI) Get(id uint) (*BeatmapSetFull, error)

type BeatmapSetFull added in v1.1.0

type BeatmapSetFull struct {
	BeatmapSet

	RecentFavourites      []User                `json:"recent_favourites"`
	CurrentUserAttributes CurrentUserAttributes `json:"current_user_attributes"`
	Ratings               []int64               `json:"ratings"`
	Converts              []Beatmap             `json:"converts"`
}

type Covers added in v1.1.0

type Covers struct {
	Cover       string `json:"cover"`
	Cover2X     string `json:"cover@2x"`
	Card        string `json:"card"`
	Card2X      string `json:"card@2x"`
	List        string `json:"list"`
	List2X      string `json:"list@2x"`
	Slimcover   string `json:"slimcover"`
	Slimcover2X string `json:"slimcover@2x"`
}

type CurrentUserAttributes added in v1.1.0

type CurrentUserAttributes struct {
	CanDelete     bool        `json:"can_delete"`
	CanHype       bool        `json:"can_hype"`
	CanHypeReason interface{} `json:"can_hype_reason"`
	CanLove       bool        `json:"can_love"`
	IsWatching    bool        `json:"is_watching"`
	NewHypeTime   interface{} `json:"new_hype_time"`
	RemainingHype int64       `json:"remaining_hype"`
}

type DefaultGroup added in v1.1.0

type DefaultGroup string
const (
	Default DefaultGroup = "default"
)

type Description added in v1.1.0

type Description struct {
	Description string `json:"description"`
}

type Failtimes added in v1.1.0

type Failtimes struct {
	Fail []int64 `json:"fail"`
	Exit []int64 `json:"exit"`
}

type Genre added in v1.1.0

type Genre struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

type Hype added in v1.1.0

type Hype struct {
	Current  int64 `json:"current"`
	Required int64 `json:"required"`
}

type Mode added in v1.1.0

type Mode string
const (
	Fruits Mode = "fruits"
	Mania  Mode = "mania"
	Osu    Mode = "osu"
	Taiko  Mode = "taiko"
)

type OAuth2API added in v1.1.0

type OAuth2API struct {
	*OsuAPI
}

func (*OAuth2API) CreateToken added in v1.1.3

func (b *OAuth2API) CreateToken(username string, password string, scope string) (*Oauth2Token, error)

func (*OAuth2API) TokenRenew added in v1.1.0

func (b *OAuth2API) TokenRenew(scope string, oldAccessToken string, refreshToken string) (*Oauth2Token, error)

type Oauth2Token

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

type OsuAPI

type OsuAPI struct {
	OAuth2     OAuth2API
	Beatmap    BeatmapAPI
	BeatmapSet BeatmapSetAPI
	// contains filtered or unexported fields
}

Package provide a simple interface to osu!api v2.

func WithAccessToken

func WithAccessToken(accessToken string, refreshToken string) *OsuAPI

Create new api client WithAccessToken with enabled auto refreshing access_token by default uses APIDomain, APIClientId, APIClientSecret, variables to set the address and the client_id/client_secret

func WithBasicAuth added in v1.1.3

func WithBasicAuth(username string, password string) (*OsuAPI, error)

type SingleBeatmap added in v1.1.0

type SingleBeatmap struct {
	Beatmap
	Beatmapset BeatmapSet `json:"beatmapset"`
}

type Status added in v1.1.0

type Status string
const (
	Ranked Status = "ranked"
)

type User added in v1.1.0

type User struct {
	ID            int64        `json:"id"`
	Username      string       `json:"username"`
	ProfileColour string       `json:"profile_colour"`
	AvatarURL     string       `json:"avatar_url"`
	CountryCode   string       `json:"country_code"`
	DefaultGroup  DefaultGroup `json:"default_group"`
	IsActive      bool         `json:"is_active"`
	IsBot         bool         `json:"is_bot"`
	IsOnline      bool         `json:"is_online"`
	IsSupporter   bool         `json:"is_supporter"`
	LastVisit     *string      `json:"last_visit"`
	PmFriendsOnly bool         `json:"pm_friends_only"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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