codeforces

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 10 Imported by: 0

README

Codeforces

Unit tests codecov

Implements all the methods mentioned in the codeforces api. Creating a client is really simple, all you have to do is:

package main

import (
	"fmt"
	"os"

	"github.com/michelececcacci/codeforces"
)

func main() {
	key := os.Getenv("CF_API_KEY")
	secret := os.Getenv("CF_API_SECRET")
	c := codeforces.NewClient(key, secret)
	resp, err := c.User.Friends(false)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(resp)
	}
}

You can also leave the key and secret parameters empty, but you wont be able to access methods that require authentication such as c.Client.Friends(). For examples refer to the examples folder

Documentation

Overview

Utility package that allows access to the codeforces API. Some functions require authentication. For more informations on how to get your API key and secret, please refer here: https://codeforces.com/apiHelp

Index

Constants

View Source
const (
	Version = "v.0.0.2"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author struct {
	ContestID        int      `json:"contestId"`
	Members          []Member `json:"members"`
	ParticipantType  string   `json:"participantType"`
	Ghost            bool     `json:"ghost"`
	StartTimeSeconds int      `json:"startTimeSeconds"`
}

type BlogEntry

type BlogEntry struct {
	OriginalLocale          string   `json:"originalLocale"`
	AllowViewHistory        bool     `json:"allowViewHistory"`
	CreationTimeSeconds     int      `json:"creationTimeSeconds"`
	Rating                  int      `json:"rating"`
	AuthorHandle            string   `json:"authorHandle"`
	ModificationTimeSeconds int      `json:"modificationTimeSeconds"`
	ID                      int      `json:"id"`
	Title                   string   `json:"title"`
	Locale                  string   `json:"locale"`
	Tags                    []string `json:"tags"`
}

type Client

type Client struct {
	Blog     *blogService
	User     *userService
	Contest  *contestService
	Problems *problemService
	Actions  *actionsService
}

holds a shared httpclient (could change) and the services responsible for communicating with the various parts of the api

func NewClient

func NewClient(apiKey, apiSecret string) *Client

func NewCustomClient

func NewCustomClient(apiKey, apiSecret string, c *httpClientWrapper) *Client

type Comment

type Comment struct {
	ID                  int    `json:"id"`
	CreationTimeSeconds int    `json:"creationTimeSeconds"`
	CommentatorHandle   string `json:"commentatorHandle"`
	Locale              string `json:"locale"`
	Text                string `json:"text"`
	Rating              int    `json:"rating"`
	ParentCommentID     int    `json:"parentCommentId,omitempty"`
}

type Contest

type Contest struct {
	ID                  int    `json:"id"`
	Name                string `json:"name"`
	Type                string `json:"type"`
	Phase               string `json:"phase"` // this could be represented with an enum
	Frozen              bool   `json:"frozen"`
	DurationSeconds     int    `json:"durationSeconds"`
	StartTimeSeconds    int    `json:"startTimeSeconds"`
	RelativeTimeSeconds int    `json:"relativeTimeSeconds"`
}

type ContestHack

type ContestHack []struct {
	ID                  int           `json:"id"`
	CreationTimeSeconds int           `json:"creationTimeSeconds"`
	Hacker              Hacker        `json:"hacker"`
	Defender            Defender      `json:"defender"`
	Verdict             string        `json:"verdict"`
	Problem             Problem       `json:"problem"`
	JudgeProtocol       JudgeProtocol `json:"judgeProtocol"`
}

type ContestStandings

type ContestStandings struct {
	Contest  Contest   `json:"contest"`
	Problems []Problem `json:"problems"`
	Rows     []Row     `json:"rows"`
}

type ContestStatus

type ContestStatus struct {
	ID                  int     `json:"id"`
	ContestID           int     `json:"contestId"`
	CreationTimeSeconds int     `json:"creationTimeSeconds"`
	RelativeTimeSeconds int64   `json:"relativeTimeSeconds"`
	Problem             Problem `json:"problem"`
	Author              Author  `json:"author"`
	ProgrammingLanguage string  `json:"programmingLanguage"`
	Verdict             string  `json:"verdict"`
	Testset             string  `json:"testset"`
	PassedTestCount     int     `json:"passedTestCount"`
	TimeConsumedMillis  int     `json:"timeConsumedMillis"`
	MemoryConsumedBytes int     `json:"memoryConsumedBytes"`
}

type Defender

type Defender struct {
	ContestID        int      `json:"contestId"`
	Members          []Member `json:"members"`
	ParticipantType  string   `json:"participantType"`
	Ghost            bool     `json:"ghost"`
	Room             int      `json:"room"`
	StartTimeSeconds int      `json:"startTimeSeconds"`
}

type FailedRequest

type FailedRequest struct {
	Status  string `json:"status"`
	Comment string `json:"comment"`
}

type Hacker

type Hacker struct {
	ContestID        int      `json:"contestId"`
	Members          []Member `json:"members"`
	ParticipantType  string   `json:"participantType"`
	Ghost            bool     `json:"ghost"`
	Room             int      `json:"room"`
	StartTimeSeconds int      `json:"startTimeSeconds"`
}

type JudgeProtocol

type JudgeProtocol struct {
	Protocol string `json:"protocol"`
	Manual   string `json:"manual"`
	Verdict  string `json:"verdict"`
}

type Member

type Member struct {
	Handle string `json:"handle"`
}

type Party

type Party struct {
	ContestID        int      `json:"contestId"`
	Members          []Member `json:"members"`
	ParticipantType  string   `json:"participantType"`
	Ghost            bool     `json:"ghost"`
	StartTimeSeconds int      `json:"startTimeSeconds"`
}

type Problem

type Problem struct {
	ContestID int      `json:"contestId"`
	Index     string   `json:"index"`
	Name      string   `json:"name"`
	Type      string   `json:"type"`
	Points    float64  `json:"points"`
	Rating    int      `json:"rating"`
	Tags      []string `json:"tags"`
}

type ProblemResult

type ProblemResult struct {
	Points                    float64 `json:"points"`
	RejectedAttemptCount      int     `json:"rejectedAttemptCount"`
	Type                      string  `json:"type"`
	BestSubmissionTimeSeconds int     `json:"bestSubmissionTimeSeconds,omitempty"`
}

type ProblemStatistic

type ProblemStatistic struct {
	ContestID   int    `json:"contestId"`
	Index       string `json:"index"`
	SolvedCount int    `json:"solvedCount"`
}

type Problemset

type Problemset struct {
	Problems          []Problem          `json:"problems"`
	ProblemStatistics []ProblemStatistic `json:"problemStatistics"`
}

type RatingChange

type RatingChange struct {
	ContestID               int    `json:"contestId"`
	ContestName             string `json:"contestName"`
	Handle                  string `json:"handle"`
	Rank                    int    `json:"rank"`
	RatingUpdateTimeSeconds int    `json:"ratingUpdateTimeSeconds"`
	OldRating               int    `json:"oldRating"`
	NewRating               int    `json:"newRating"`
}

type RecentAction

type RecentAction struct {
	TimeSeconds int       `json:"timeSeconds"`
	BlogEntry   BlogEntry `json:"blogEntry"`
	Comment     Comment   `json:"comment"`
}

type ResultWrapper

type ResultWrapper[T any] struct {
	Status string `json:"status"`
	Result T      `json:"result"`
}

used to parse away the status, and isolate the result

type Row

type Row struct {
	Party                 Party           `json:"party"`
	Rank                  int             `json:"rank"`
	Points                float64         `json:"points"`
	Penalty               int             `json:"penalty"`
	SuccessfulHackCount   int             `json:"successfulHackCount"`
	UnsuccessfulHackCount int             `json:"unsuccessfulHackCount"`
	ProblemResults        []ProblemResult `json:"problemResults"`
}

type User

type User struct {
	Country                 string `json:"country"`
	City                    string `json:"city"`
	LastName                string `json:"lastName"`
	LastOnlineTimeSeconds   int    `json:"lastOnlineTimeSeconds"`
	Rating                  int    `json:"rating"`
	FriendOfCount           int    `json:"friendOfCount"`
	TitlePhoto              string `json:"titlePhoto"`
	Handle                  string `json:"handle"`
	Avatar                  string `json:"avatar"`
	FirstName               string `json:"firstName"`
	Contribution            int    `json:"contribution"`
	Organization            string `json:"organization"`
	Rank                    string `json:"rank"`
	MaxRating               int    `json:"maxRating"`
	RegistrationTimeSeconds int    `json:"registrationTimeSeconds"`
	MaxRank                 string `json:"maxRank"`
}

func (*User) CurrentDivision

func (u *User) CurrentDivision() uint

supposed to be called only on rated users

func (*User) IsRated

func (u *User) IsRated() bool

func (*User) MaxDivision

func (u *User) MaxDivision() uint

supposed to be called only on rated users returns the best division the user reached

Directories

Path Synopsis
examples
blog
nolint
nolint
contest/hacks
nolint
nolint
nolint
user/friends
nolint
nolint
user/info
nolint
nolint
user/rating
nolint
nolint

Jump to

Keyboard shortcuts

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