gopentdb

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: MIT Imports: 2 Imported by: 0

README

Go OpenTDB

Golang API Client for OpenTriviaDatabase

Installation

Install with the following command:

go get github.com/3n3a/gopentdb

Examples

  1. See the example under examples/main.go

  2. Run the example:

    go run examples/main.go
    
  3. See the output on the console

Contributing

Please see the following file

License

Please see the following file

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Categories

type Categories struct {
	Id   int64  `json:"id"`
	Name string `json:"name"`
}

type Config

type Config struct {
	BaseUrl string
}

type Encoding

type Encoding string
const (
	Default     Encoding = ""
	LegacyUrl   Encoding = "urlLegacy"
	UrlEncoding Encoding = "url3986"
	Base64      Encoding = "base64"
)

type OpenTDB

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

func New

func New(c Config) OpenTDB

func (*OpenTDB) GetCategories

func (o *OpenTDB) GetCategories() ([]Categories, error)

Get List of Categories from OpenTDB

func (*OpenTDB) GetCategoryCount

func (o *OpenTDB) GetCategoryCount(category int64) (int64, error)

Gets Question Count for a given category Id

func (*OpenTDB) GetQuestions

func (o *OpenTDB) GetQuestions(params QuestionParams) ([]Question, error)

Get Questions based on Amount, Category, Difficulty and Type

func (*OpenTDB) GetSessionToken

func (o *OpenTDB) GetSessionToken() (string, error)

Retrieve a Session Token

func (*OpenTDB) Ping

func (o *OpenTDB) Ping() (bool, error)

Check if OpenTDB is Up and running.

type Question

type Question struct {
	CategoryName       string             `json:"category"`
	QuestionType       QuestionType       `json:"type"`
	QuestionDifficulty QuestionDifficulty `json:"difficulty"`
	Question           string             `json:"question"`
	CorrectAnswer      string             `json:"correct_answer"`
	IncorrectAnswers   []string           `json:"incorrect_answers"`
}

type QuestionDifficulty

type QuestionDifficulty string
const (
	Easy   QuestionDifficulty = "easy"
	Medium QuestionDifficulty = "medium"
	Hard   QuestionDifficulty = "hard"
)

type QuestionParams

type QuestionParams struct {
	Amount             int64              `default:"10"`
	Category           int64              `default:"-1"`
	QuestionDifficulty QuestionDifficulty `default:""`
	QuestionType       QuestionType       `default:""`
	Encoding           `default:""`
	Token              string `default:""`
}

type QuestionType

type QuestionType string
const (
	Multiple QuestionType = "multiple"
	Boolean  QuestionType = "boolean"
)

type ResponseCode

type ResponseCode int
const (
	Success          ResponseCode = 0
	NoResults        ResponseCode = 1
	InvalidParameter ResponseCode = 2
	TokenNotFound    ResponseCode = 3
	TokenEmpty       ResponseCode = 4
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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