client

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

README

Go Go Reference

go-habbo

Library to deal with unofficial Habbo API.

Installation

go get github.com/go-habbo/habbo

Usage

Create a parser and a Habbo API client. Then you can fetch Habbos by name or by HHID.

parser := client.NewParser(http.DefaultClient)
api := client.NewHabboAPI(parser)

habbo, err := api.GetHabboByName(ctx, "com", "myHabboName")
if err != nil {
    // handle error
}

When you have a Habbo object, you can use it to get more information about the Habbo.

Make sure to use the hhid (Habbo Unique ID).

profile, err := api.GetProfile(ctx, "com", "hhus-123456789")
if err != nil {
    // handle error
}

Habbo CLI

This projects also comes with a small command-line interface to fetch Habbos information as JSON.

$ go build -o go-habbo cmd/cli/main.go 
$ ./go-habbo <hotel> <habboName>

You can also run it straight from the source.

$ go run cmd/cli/main.go <hotel> <habboName>

The JSON is indented for readability and can be piped to a file or jq for further processing.

$ go run cmd/cli/main.go <hotel> <habboName> | jq .motto

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHotel         = errors.New("invalid hotel")
	ErrInvalidUniqueID      = errors.New("invalid unique ID")
	ErrUnexpectedStatusCode = errors.New("unexpected status code")
	ErrHabboNotFound        = errors.New("habbo not found")
)

Functions

This section is empty.

Types

type HabboAPI

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

HabboAPI is a Habbo API client.

func NewHabboAPI

func NewHabboAPI(parser HabboParser) *HabboAPI

NewHabboAPI creates a new Habbo API client.

func (*HabboAPI) GetHabbo

func (c *HabboAPI) GetHabbo(ctx context.Context, hotel string, habboID string) (*habbo.Habbo, error)

GetHabbo fetches a Habbo by ID.

func (*HabboAPI) GetHabboByName

func (c *HabboAPI) GetHabboByName(ctx context.Context, hotel string, habboName string) (*habbo.Habbo, error)

GetHabboByName fetches a Habbo by name.

func (*HabboAPI) GetProfile

func (c *HabboAPI) GetProfile(ctx context.Context, hotel string, habboID string) (*habbo.Profile, error)

GetProfile fetches a Habbo's profile.

type HabboParser

type HabboParser interface {
	// contains filtered or unexported methods
}

HabboParser is an interface that the Habbo API uses to fetch data.

type Parser

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

Parser is a Habbo API parser

func NewParser

func NewParser(httpClient *http.Client) *Parser

NewParser creates a new Habbo API parser

func (*Parser) WithUserAgent

func (p *Parser) WithUserAgent(userAgent string)

WithUserAgent sets the user agent for the parser

type ParserMock

type ParserMock struct {
	HabboResponse   *habbo.Habbo
	HabboError      error
	ProfileResponse *habbo.Profile
	ProfileError    error
}

func NewParserMock

func NewParserMock() *ParserMock

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

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