tatsumakigo

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

Tatsumaki Go

CircleCI Code Quality Documentation GitHub release (latest by date) Discord

A Go wrapper for Tatsumaki's external API.

If you have any queries about the API or this wrapper, please visit the api channel in our official support server.

How do I get an API key

To get an API key, run the following command with Tatsumaki in a server: t!apikey

Tutorial

To use the lib, first create an instance of the Tatsumaki client which will be your interface to interact with the API.

Then, call your desired endpoint methods on the client.

// Create client.
tatsumakiClient := tatsumakigo.New("YOUR API TOKEN")

// Get a user.
user, err := tatsumakiClient.User("User ID")

if err == nil {
	// Do stuff with the user response here.
	fmt.Println("User's required XP until next level up: %d", user.LevelProgress.RequiredXp)
}
...
// Get a user using a context.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
user, err = tatsumakiClient.UserWithContext(ctx, "User ID")
...

License

Copyright ©2019 Tatsu Works.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Overview

Package tatsumakigo provides a wrapper to consume the external Tatsumaki API.

Index

Constants

This section is empty.

Variables

View Source
var ErrAdjustBounds = xerrors.New("tatsumakigo: the amount to adjust must be between 0 and 50,000 (inclusive)")

ErrAdjustBounds is returned by the adjust guild points and score methods if the amount to adjust is invalid.

View Source
var ErrAdjustInvalid = xerrors.New("tatsumakigo: the amount to adjust for add and remove actions must be above 0")

ErrAdjustInvalid is returned by the adjust guild points and score methods if the amount to adjust for an action is invalid.

View Source
var ErrLeaderboardLimit = xerrors.New("tatsumakigo: guild leaderboard limit cannot be less than -1")

ErrLeaderboardLimit is returned by the guild leaderboard endpoint if the limit is not valid.

Functions

This section is empty.

Types

type Action

type Action string

Action is the action type for updating a user's guild points or score.

const (
	// ActionAdd is the action for adding a user's guild points or score.
	ActionAdd Action = "add"
	// ActionRemove is the action for removing a user's guild points or score.
	ActionRemove Action = "remove"
	// ActionSet is the action for setting a user's guild points or score.
	ActionSet Action = "set"
)

type Background

type Background struct {
	ImageURL string
	Name     string
}

Background is the struct for a profile background.

type Badge

type Badge struct {
	ImageURL string
	Name     string
}

Badge is the struct for a profile badge.

type BadgeSlot

type BadgeSlot struct {
	Badge  *Badge
	SlotNo int
}

BadgeSlot is the struct for a profile badge slot. If the badge slot does not contain an equipped badge, the badge is nil.

type Client

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

Client is the main interface to interact with the API.

func New

func New(token string) *Client

New creates a new instance of the Tatsumaki client.

func (*Client) AdjustGuildUserPoints

func (t *Client) AdjustGuildUserPoints(guildID string, userID string, amount int, action Action) (*GuildUserPoints, error)

AdjustGuildUserPoints wraps AdjustGuildUserPointsWithContext using the background context.

func (*Client) AdjustGuildUserPointsWithContext

func (t *Client) AdjustGuildUserPointsWithContext(ctx context.Context, guildID string, userID string, amount int,
	action Action) (*GuildUserPoints, error)

AdjustGuildUserPointsWithContext adjusts a user's points in a guild. The amount must be between 0 and 50,000 (inclusive) and must be above 0 if the action is add or remove.

func (*Client) AdjustGuildUserScore

func (t *Client) AdjustGuildUserScore(guildID string, userID string, amount int,
	action Action) (*GuildUserScore, error)

AdjustGuildUserScore wraps AdjustGuildUserScoreWithContext using the background context.

func (*Client) AdjustGuildUserScoreWithContext

func (t *Client) AdjustGuildUserScoreWithContext(ctx context.Context, guildID string, userID string, amount int,
	action Action) (*GuildUserScore, error)

AdjustGuildUserScoreWithContext adjusts a user's score in a guild. The amount must be between 0 and 50,000 (inclusive) and must be above 0 if the action is add or remove.

func (*Client) GuildLeaderboard

func (t *Client) GuildLeaderboard(guildID string, limit int) ([]*GuildRankedUser, error)

GuildLeaderboard wraps GuildLeaderboardWithContext using the background context. To get all guild member rankings for the leaderboard, set limit to -1. If limit is set to 0, the default value will be used as per the API.

func (*Client) GuildLeaderboardWithContext

func (t *Client) GuildLeaderboardWithContext(ctx context.Context, guildID string, limit int) ([]*GuildRankedUser, error)

GuildLeaderboardWithContext gets the leaderboard for a guild. To get all guild member rankings for the leaderboard, set limit to -1. If limit is set to 0, the default value will be used as per the API.

func (*Client) GuildUserStats

func (t *Client) GuildUserStats(guildID string, userID string) (*GuildUserStats, error)

GuildUserStats wraps GuildUserStatsWithContext using the background context.

func (*Client) GuildUserStatsWithContext

func (t *Client) GuildUserStatsWithContext(ctx context.Context, guildID string, userID string) (*GuildUserStats, error)

GuildUserStatsWithContext gets a user's stats for a guild. @me is accepted for the user ID, which will retrieve stats for the owner of the API token.

func (*Client) User

func (t *Client) User(userID string) (*User, error)

User wraps UserWithContext using the background context.

func (*Client) UserWithContext

func (t *Client) UserWithContext(ctx context.Context, userID string) (*User, error)

UserWithContext gets a Tatsumaki user profile.

type GuildRankedUser

type GuildRankedUser struct {
	Rank   int64  `json:"rank"`
	Score  int64  `json:"score,string"`
	UserID string `json:"user_id"`
}

GuildRankedUser is the struct for a ranked user in a guild leaderboard.

type GuildUserPoints

type GuildUserPoints struct {
	Points int64 `json:"points,string"`
}

GuildUserPoints is the struct for a user's adjusted points in a guild.

type GuildUserScore

type GuildUserScore struct {
	Score int64 `json:"score,string"`
}

GuildUserScore is the struct for a user's adjusted score in a guild.

type GuildUserStats

type GuildUserStats struct {
	GuildID string `json:"guild_id"`
	Points  int64  `json:"points,string"`
	Score   int64  `json:"score,string"`
	UserID  int64  `json:"user_id,string"`
}

GuildUserStats is the struct for a user's stats in a guild.

type LevelProgress

type LevelProgress struct {
	CurrentXp  int64
	RequiredXp int64
}

LevelProgress is the struct for a user's current level progress.

type Ping

type Ping struct {
	Pong bool `json:"pong"`
}

Ping is the struct for a ping response.

type User

type User struct {
	AvatarURL     string
	Background    *Background
	BadgeSlots    []*BadgeSlot
	Credits       int64
	InfoBox       string
	Level         int64
	LevelProgress *LevelProgress
	Name          string
	Rank          int64
	Reputation    int64
	Title         string
	TotalXp       int64
}

User is the struct for a Tatsumaki user profile.

Jump to

Keyboard shortcuts

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