quizduell

package module
v0.0.0-...-0784cf9 Latest Latest
Warning

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

Go to latest
Published: May 13, 2014 License: MIT Imports: 16 Imported by: 2

README

Quizduell API client

Inofficial API client for the Quizduell REST API written in Go. Inspired by https://github.com/mtschirs/quizduellapi and easysurfer.me

For documentation, see here.

Use cases

This API library supports all functionality that can be found in the official Quizduell app, besides posting new questions. There is also no need to have downloaded, or registered a premium account in order to use features in this client library that would otherwise be unavailable to a normal user (like setting a new avatar and playing more than 8 games simulanously).

Included in the repo is a demo of the API in which an automated player logs into Quizduell and plays active games, accepts game invites and keeps a constant pool of games against random opponents. It also supports things like: adjusting the standard deviation from the correct answer (how often does the player answer correctly), excluding players on your friends list from gameplay against the automated player and a few other things.

To automate the process of starting the player, there is a script included that starts the player every few minutes with a cookie in cookie.gob (which you will have to create yourself). To run it, just do: ./runner.sh

When starting the player for the first time, you'll have to provide your username, password and a name for the cookie file in environmental variables named QD_USERNAME, QD_PASSWORD, QD_COOKIE_FILE, respectively. After this initial run, you'll only ever have to provide the QD_COOKIE_FILE variable, provided the file actually still exists.

Warning: Most calls to the API do not populate all fields of the returned structs. Some may still contain their respective null values. i.e. when retrieving the list of active games from a *quizduell.Status the list of questions for a particular game will be empty.

Note: When calling func (c *Client) UploadRoundAnswers you must also pass all of your previous answers to the questions, in addition to your answers of this round. If you are passing the answers to questions where your opponent choose the category, you must also pass the correct category for those questions/answers (i.e. game.CategoryChoices[len(game.CategoryChoices)-1]).

License

Pubished under the MIT License.

Quizduell is a registered trademark of FEO Media AB, Stockholm, SE registered in Germany and other countries. This project is an independent work and is in no way affiliated with, authorized, maintained, sponsored or endorsed by FEO Media AB.

Documentation

Overview

Package quizduell provides an interface to the REST API used by the Quizduell mobile apps. It supports all functionality that is also possible in the mobile apps. Note: Most calls to the API do _not_ populate all

fields of the returned type.
As an example, Client.GetUserGames() does not
include the full-text of the questions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CategoryStatistic

type CategoryStatistic struct {
	Percent      float64 `json:"percent"`
	CategoryName string  `json:"cat_name"`
}

type Client

type Client struct {

	// We're separating out this cookie jar from
	// the HTTP client, because Go is trying to be
	// peticularly RFC compliant and doesn't allow
	// certain characters in cookies. That's why we
	// have to handle them seperately.
	Jar http.CookieJar
	// contains filtered or unexported fields
}

Client represents a single user's (non-persistent) connection to Quizduell. In fact it just wraps the HTTP client and cookiejar.

func NewClient

func NewClient(cookieJar http.CookieJar) (*Client, error)

NewClient produces a new Quizduell client. It optionally takes a cookiejar, but if there isn't one provided it automatically creates one for you.

func (*Client) AcceptGame

func (c *Client) AcceptGame(gameID int) (bool, error)

AcceptGame accepts a pending game request that has the given gameID. Requires you to be logged in.

func (*Client) AddBlocked

func (c *Client) AddBlocked(userID int) ([]User, error)

AddBlocked puts the user with the provided userID onto your blocked list. Requires you to be logged in.

func (*Client) AddFriend

func (c *Client) AddFriend(userID int) (*Popup, error)

AddFriend puts the user with the provided userID onto your friends list. Requires you to be logged in.

func (*Client) CategoryList

func (c *Client) CategoryList() (map[int]string, error)

CategoryList fetches all possible categories. Requires you to be logged in.

func (*Client) CategoryStatistics

func (c *Client) CategoryStatistics() (*UserCategoryStatistics, error)

CategoryStatistics gives you the performance of the logged in user for all categories. Requires you to be logged in.

func (*Client) CreateTVUser

func (c *Client) CreateTVUser() (*User, error)

CreateTVUser creates a new TV user profile for the current logged in Quizduell users. Requires you to be logged in.

func (*Client) CreateUser

func (c *Client) CreateUser(username, email, password string) (*Status, error)

CreateUser registers a new user with Quizduell, this user is automatically logged in. The email is optional and will be omitted for the call if it is the empty string.

func (*Client) DeclineGame

func (c *Client) DeclineGame(gameID int) (bool, error)

DeclineGame declines a pending game request that has the given gameID. Requires you to be logged in.

func (*Client) FindUser

func (c *Client) FindUser(username string) (*User, error)

FindUser returns the user object of the user with the provided username. Requires you to be logged in.

func (*Client) GameStatistics

func (c *Client) GameStatistics() ([]GameStatistic, error)

GameStatistics returns general game statistic information on a per opponent basis. Requires you to be logged in.

func (*Client) GetGame

func (c *Client) GetGame(gameID int) (*Game, error)

GetGame returns more information about the game with the given gameID. The returned game object also contains the all possible questions of every round. Requires you to be logged in.

func (*Client) GetGames

func (c *Client) GetGames(gameIDs []int) ([]Game, error)

GetGames returns details of the specified games, not including question and answer strings though. Requires you to be logged in.

func (*Client) GetUserGames

func (c *Client) GetUserGames() (*Status, error)

GetUserGames returns a status update, that also contains game data from the user's games. Requires you to be logged in.

func (*Client) GiveUp

func (c *Client) GiveUp(gameID int) (*Game, *Popup, error)

GiveUp ends the game with the provided gameID, you may loose points when giving up. Requires you to be logged in.

func (*Client) Login

func (c *Client) Login(username, password string) (*Status, error)

Login logs in a user to Quizduell and puts the returned cookie (on success) into the cookiejar. You've no need to call login, if you create a new user or provide a new cookiejar with the appropriate cookie in it.

func (*Client) RemoveBlocked

func (c *Client) RemoveBlocked(userID int) ([]User, error)

RemoveBlocked removes the user with the provided userID from your blocked list. Requires you to be logged in.

func (*Client) RemoveFriend

func (c *Client) RemoveFriend(userID int) (*Popup, error)

RemoveFriend removes the user with the provided userID from your friends list. Requires you to be logged in.

func (*Client) SendForgotPasswordEmail

func (c *Client) SendForgotPasswordEmail(email string) (*Popup, error)

SendForgotPasswordEmail sends a forgot password email to the current user. I guess this function requires the current user to have an email set in his profile. Requires you to be logged in.

func (*Client) SendMessage

func (c *Client) SendMessage(gameID int, message string) (*InGameMessage, error)

SendMessage sends a message to the user that is the opponent in the game with the given gameID. All messages to a user are visible in all games against this opponent. Requires you to be logged in.

func (*Client) StartGame

func (c *Client) StartGame(opponentID int) (*Game, error)

StartGame starts a new game against the player with the provided opponentID. Requires you to be logged in.

func (*Client) StartRandomGame

func (c *Client) StartRandomGame() (*Game, error)

StartRandomGame starts a new game against a player that is choosen randomly by the Quizduell server. After some time testing the automatic player, it seems that you can at most play in about 122 games. Requires you to be logged in.

func (*Client) TopPlayers

func (c *Client) TopPlayers() ([]User, error)

TopPlayers gets the list of users that have the highest ranking based on the points won in games. Requires you to be logged in.

func (*Client) TopWriters

func (c *Client) TopWriters() ([]User, error)

TopWriters gets the list of users that have submitted the most questions, that have also been accepted. Requires you to be logged in.

func (*Client) UpdateAvatar

func (c *Client) UpdateAvatar(avatarCode string) (bool, error)

UpdateAvatar sets the current user's avatar to the provided avatar code. An avatar consists of individual mouth, hair, eyes, hats, etc. encoded in a numerical string, e.g. "0010999912" (A skin-colored avatar with a crown). Requires you to be logged in.

func (*Client) UpdateUser

func (c *Client) UpdateUser(username, email, password string) (*Status, error)

UpdateUser sets the user's attributes, if one of them is the empty string that attribute will be omitted from the request. Requires you to be logged in.

func (*Client) UploadRoundAnswers

func (c *Client) UploadRoundAnswers(gameID int, answers []int, categoryID int) (*Game, error)

UploadRoundAnswers sends your provided answers to the Quizduell server. Note: In the answers you must include all answers you gave in the previous rounds of the same game. Requires you to be logged in.

type Game

type Game struct {
	ID              int             `json:"game_id"`
	CategoryChoices []int           `json:"cat_choices"`
	ElapsedMinutes  int             `json:"elapsed_min"`
	Messages        []InGameMessage `json:"messages"`
	Opponent        User            `json:"opponent"`
	OpponentAnswers []int           `json:"opponent_answers"`
	YourAnswers     []int           `json:"your_answers"`
	YourTurn        bool            `json:"your_turn"`
	Questions       []Question      `json:"questions"`
	RatingBonus     int             `json:"rating_bonus"`
	GameState       `json:"state"`
}

type GameState

type GameState int8
const (
	Waiting GameState = iota
	Active
	Finished

	GivenUp
)

func (GameState) String

func (s GameState) String() string

type GameStatistic

type GameStatistic struct {
	AvatarCode string `json:"avatar_code"`
	GamesLost  int    `json:"n_games_lost"`
	GamesTied  int    `json:"n_games_tied"`
	GamesWon   int    `json:"n_games_won"`
	Name       string `json:"name"`
	UserID     int    `json:"user_id,string"`
}

type InGameMessage

type InGameMessage struct {
	CreatedAt string `json:"created_at"`
	From      int    `json:"from"`
	ID        string `json:"id"`
	Text      string `json:"text"`
	To        int    `json:"to"`
}
type Popup struct {
	PopupMessage string `json:"popup_mess"`
	PopupTitle   string `json:"popup_title"`
}

type Question

type Question struct {
	QuestionText string `json:"question"`
	Correct      string `json:"correct"`
	Wrong1       string `json:"wrong1"`
	Wrong2       string `json:"wrong2"`
	Wrong3       string `json:"wrong3"`
	Timestamp    string `json:"timestamp"`
	CategoryName string `json:"cat_name"`
	CategoryID   int    `json:"cat_id"`
	QuestionID   int    `json:"q_id"`
}

type Status

type Status struct {
	LoggedIn bool `json:"logged_in"`
	*User    `json:"user"`
	Settings *struct {
		MaxFreeGames     int     `json:"max_free_games"`
		GiveUpPointLoss  int     `json:"give_up_point_loss"`
		AdProvider       string  `json:"ad_provider"`
		AdmobMedID       string  `json:"ad_mob_med_id"`
		AdmobMedSplashID string  `json:"admob_med_splash_id"`
		Fulmium          bool    `json:"fulmium"`
		Feo              bool    `json:"feo"`
		Feos             float64 `json:"feos"`
		PPF              float64 `json:"ppf"`
		CheckLimboGames  bool    `json:"check_limbo_games"`
		RefreshTableFreq int     `json:"refresh_table_freq"`
		RefreshFreq      int     `json:"refresh_freq"`
		SplashFreq       float64 `json:"splash_freq"`
		// contains filtered or unexported fields
	} `json:"settings"`
}

type TVClient

type TVClient struct {
	UserID int
	// The API seems to be using this auth token (tt)
	// as a validation mechanism, instead of cookies
	// or the like.
	AuthToken string
}

func FromClient

func FromClient(c *Client) (*TVClient, error)

FromClient returns a new TV client based on an already existant (and logged in) Quizduell client. If the user hasn't created a TV profile yet, this will also be done in the process.

func NewTVClient

func NewTVClient(userID int, authToken string) *TVClient

NewTVClient creates a new TV client that can be used to interact with the TV version of Quizduell. The authToken is User.TT

func (*TVClient) AgreeAGBs

func (t *TVClient) AgreeAGBs() (map[string]interface{}, error)

AgreeAGBs makes the current user agree to the AGB put up by the TV quiz broadcaster.

func (*TVClient) DeleteUser

func (t *TVClient) DeleteUser() (map[string]interface{}, error)

func (*TVClient) GetMyProfile

func (t *TVClient) GetMyProfile() (map[string]interface{}, error)

func (*TVClient) GetProfile

func (t *TVClient) GetProfile(userID int) (map[string]interface{}, error)

func (*TVClient) GetRankings

func (t *TVClient) GetRankings() (map[string]interface{}, error)

func (*TVClient) GetState

func (t *TVClient) GetState() (map[string]interface{}, error)

GetState returns the state of the TV quiz

func (*TVClient) PostProfile

func (t *TVClient) PostProfile(profile map[string]string) (map[string]interface{}, error)

func (*TVClient) SelectCategory

func (t *TVClient) SelectCategory(categoryID int) (map[string]interface{}, error)

func (*TVClient) SendAnswer

func (t *TVClient) SendAnswer(questionID, answerID int) (map[string]interface{}, error)

func (*TVClient) SetAvatarAndNickname

func (t *TVClient) SetAvatarAndNickname(nick, avatarCode string) (map[string]interface{}, error)

func (*TVClient) UploadProfileImage

func (t *TVClient) UploadProfileImage(r io.Reader) (map[string]interface{}, error)

type User

type User struct {
	AvatarCode           string `json:"avatar_code"`
	Name                 string `json:"name"`
	ID                   int    `json:"user_id,string"`
	TT                   string `json:"tt"`
	QC                   bool   `json:"qc"`
	QuestionReviewer     int    `json:"q_reviewer"`
	NumApprovedQuestions int    `json:"n_approved_questions"`
	Key                  int    `json:"key"`
	Rating               int    `json:"rating"`
	Friends              []User `json:"friends"`
	FacebookID           int    `json:"facebook_id,string"`
	Games                []Game `json:"games"`
	Email                string `json:"email"`
}

type UserCategoryStatistics

type UserCategoryStatistics struct {
	CategoryStatistics []CategoryStatistic `json:"cat_stats"`
	GamesLost          int                 `json:"n_games_lost"`
	GamesPlayed        int                 `json:"n_games_played"`
	GamesTied          int                 `json:"n_games_tied"`
	GamesWon           int                 `json:"n_games_won"`
	PerfectGames       int                 `json:"n_perfect_games"`
	QuestionsAnswered  int                 `json:"n_questions_answered"`
	QuestionsCorrect   int                 `json:"n_questions_correct"`
	NumUsers           int                 `json:"n_users"`
	Rank               int                 `json:"rank"`
	Rating             int                 `json:"rating"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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