baapi

package module
v0.0.0-...-66248cb Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: MIT Imports: 7 Imported by: 0

README

BotsArchive API Wrapper for Go

Reference:

BotsArchive API Wrapper for Go aims to provide a simple interface to access botsarchive.com's API protocol with Go in a easy and fast manner.

Why?

Using the original BotsArchive's API directly with Go is a pain in the butt: numbers as strings, values that sometimes are there and sometimes aren't, bools as integers, parameters that disappear...

With this package, my goal is to simplify everything so you don't have to deal with all this bullcrap.

To achieve my goal, I've decided to completely change the API return values instead of keeping the original ones. Read the docs for this package to know where to find everything.

How to use

Install the package:

go get github.com/MassiveBox/botsarchive_api

and refer to the docs or the wiki for a detailed explanation. You can find some examples in the wiki as well.

Technical details

To improve performances and memory usage, instead of net/http, I'm using FastHTTP and instead of encoding/json, I'm using JSON Iterator.

This package will send data to the host api.botsarchive.com - Please make sure you aren't blocking it with a firewall.

Coverage

This package is supposed to be 100% compatible with BotsArchive's public API. If you find something isn't working as intended, open an issue.

I also have plans for the future to support BotsArchive's private API, the one that is used in the website to gather information about the bots, top bots, categories, etc.

All the data you get with this package comes from BotsArchive's API. It's exclusively BotsArchive's responsibility if you find something that violates the law.

Documentation

Index

Constants

View Source
const (
	FailedRequest            = "request failed"
	InvalidResponse          = "invalid response. Response is not JSON-decodable."
	UnexpectedError          = "unexpected error"
	MissingUsernameParameter = "username GET parameter required"
	MissingParameters        = "bot_id and user_id GET parameters required"
	BotNotFound              = "bot not found"
)

The constants below are set to simplify error handling. Please consult the appropriate page on the wiki to learn more about this topic.

Variables

This section is empty.

Functions

func GetUserRatingByBotID

func GetUserRatingByBotID(botid, userid int) (bool, int, error)

GetUserRatingByBotID returns a boolean telling if the user has voted and an integer expressing the number of stars selected by the user. It might return one of the following errors: FailedRequest, InvalidResponse, UnexpectedError, MissingParameters, BotNotFound

func GetUserRatingByBotUsername

func GetUserRatingByBotUsername(username string, userid int) (bool, int, error)

GetUserRatingByBotUsername returns a boolean telling if the user has voted and an integer expressing the number of stars selected by the user. Please note: this method sends two API calls instead of one as GetUserRatingByBotID. If you have to get ratings for one bot only, it's better if you save the ID of the bot somewhere and you use GetUserRatingByBotID. It might return one of the following errors: FailedRequest, InvalidResponse, UnexpectedError, MissingParameters, BotNotFound

Types

type BotInfo

type BotInfo struct {
	Rating struct {
		AverageRating          float64
		TotalStars, VotesCount int
	}
	Infos struct {
		Name, Username, Description                                 string
		Languages, Tags                                             []string
		HasPhoto, SupportsGroups, SupportsInline, HasCopyrightAlert bool
	}
	ID, DeveloperID int
	ChannelLink     string
}

BotInfo contains bot informations. If field ChannelLink is == "", the bot hasn't been published yet. If DeveloperID == 0, the bot wasn't claimed by its developer.

func GetBotInfo

func GetBotInfo(username string) (BotInfo, error)

GetBotInfo returns a struct containing informations about a bot present in BotsArchive. It might return one of the following errors: FailedRequest, InvalidResponse, UnexpectedError, MissingUsernameParameter, BotNotFound

Jump to

Keyboard shortcuts

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