Documentation
¶
Overview ¶
Package goforces provides tructs and functions for accessing the codeforces API. If the API query is successful, return Go struct.
Queries ¶
Executing queries on Codeforces API is very simple. Almost all of the methods don't require authentication.
logger := log.New(os.Stderr, "*** ", log.LstdFlags)
api, _ := goforces.NewClient(logger)
ctx := context.Background()
problems, _ := api.GetProblemSetProblems(ctx, &goforces.ProblemSetProblemsOptions{Tags:[]string{"dp", "math"}})
for _, problem := range problems.Problems {
fmt.Printf("%+v\n", problem)
}
Endpoints ¶
Goforces implements almost all of the endpoints defined in the Codeforces API(http://codeforces.com/api/help) More detailed information about the behavior of endpoint and the parameters can be found at the official Codeforces API documentation.
Index ¶
- type BlogEntry
- type Client
- func (c *Client) GetBlogEntryComments(ctx context.Context, blogEntryID int) ([]Comment, error)
- func (c *Client) GetBlogEntryView(ctx context.Context, blogEntryID int) (*BlogEntry, error)
- func (c *Client) GetContestHacks(ctx context.Context, contestID int) ([]Hack, error)
- func (c *Client) GetContestList(ctx context.Context, options *ContestListOptions) ([]Contest, error)
- func (c *Client) GetContestRatingChanges(ctx context.Context, contestID int) ([]RatingChange, error)
- func (c *Client) GetContestStandings(ctx context.Context, contestID int, options *ContestStatndingsOptions) (*Standings, error)
- func (c *Client) GetContestStatus(ctx context.Context, contestID int, options *ContestStatusOptions) ([]Submission, error)
- func (c *Client) GetProblemSetProblems(ctx context.Context, options *ProblemSetProblemsOptions) (*Problems, error)
- func (c *Client) GetProblemSetRecentStatus(ctx context.Context, count int) ([]Submission, error)
- func (c *Client) GetRecentActions(ctx context.Context, maxCount int) ([]RecentAction, error)
- func (c *Client) GetUserBlogEntries(ctx context.Context, handle string) ([]BlogEntry, error)
- func (c *Client) GetUserFriends(ctx context.Context, options *UserFriendsOptions) ([]string, error)
- func (c *Client) GetUserInfo(ctx context.Context, handles []string) ([]User, error)
- func (c *Client) GetUserRatedList(ctx context.Context, options *UserRatedListOptions) ([]User, error)
- func (c *Client) GetUserRating(ctx context.Context, handle string) ([]RatingChange, error)
- func (c *Client) GetUserStatus(ctx context.Context, handle string, options *UserStatusOptions) ([]Submission, error)
- func (c *Client) SetAPIKey(apiKey string)
- func (c *Client) SetAPISecret(apiSecret string)
- type Comment
- type Contest
- type ContestListOptions
- type ContestStatndingsOptions
- type ContestStatusOptions
- type Hack
- type JudgeProtocol
- type Member
- type Party
- type Problem
- type ProblemResult
- type ProblemSetProblemsOptions
- type ProblemSetRecentStatus
- type ProblemStatistics
- type Problems
- type RanklistRow
- type RatingChange
- type RecentAction
- type Standings
- type Submission
- type User
- type UserFriendsOptions
- type UserRatedListOptions
- type UserStatusOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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"`
Content string `json:"content"`
Tags []string `json:"tags"`
}
BlogEntry represents a Codeforces BlogEntry
type Client ¶
type Client struct {
APIKey string
APISecret string
URL *url.URL
HTTPClient *http.Client
Logger *log.Logger
}
Client manages the access for the Codeforces API.
func NewClient ¶
NewClient takes a logger and return a Client struct. The Client struct can be use for accessing the endpoints
func (*Client) GetBlogEntryComments ¶
GetBlogEntryComments implements /blogEntry.comments
func (*Client) GetBlogEntryView ¶
GetBlogEntryView implements /blogEntry.view
func (*Client) GetContestHacks ¶
GetContestHacks implements /contest.hacks
func (*Client) GetContestList ¶
func (c *Client) GetContestList(ctx context.Context, options *ContestListOptions) ([]Contest, error)
GetContestList implements /contest.list
func (*Client) GetContestRatingChanges ¶
func (c *Client) GetContestRatingChanges(ctx context.Context, contestID int) ([]RatingChange, error)
GetContestRatingChanges implements /contest.ratingChanges
func (*Client) GetContestStandings ¶
func (c *Client) GetContestStandings(ctx context.Context, contestID int, options *ContestStatndingsOptions) (*Standings, error)
GetContestStandings implements /contest.standings
func (*Client) GetContestStatus ¶
func (c *Client) GetContestStatus(ctx context.Context, contestID int, options *ContestStatusOptions) ([]Submission, error)
GetContestStatus implements /contest.status
func (*Client) GetProblemSetProblems ¶
func (c *Client) GetProblemSetProblems(ctx context.Context, options *ProblemSetProblemsOptions) (*Problems, error)
GetProblemSetProblems implements /problemset.problems
func (*Client) GetProblemSetRecentStatus ¶
GetProblemSetRecentStatus implements /problemset.recentStatus
func (*Client) GetRecentActions ¶
GetRecentActions implements /recentActions
func (*Client) GetUserBlogEntries ¶
GetUserBlogEntries implements /user.blogEntries
func (*Client) GetUserFriends ¶
GetUserFriends implements /user.friends You must your api key and secret key before call this method.
func (*Client) GetUserInfo ¶
GetUserInfo implements /user.info
func (*Client) GetUserRatedList ¶
func (c *Client) GetUserRatedList(ctx context.Context, options *UserRatedListOptions) ([]User, error)
GetUserRatedList implements /user.ratedList
func (*Client) GetUserRating ¶
GetUserRating implements /user.rating
func (*Client) GetUserStatus ¶
func (c *Client) GetUserStatus(ctx context.Context, handle string, options *UserStatusOptions) ([]Submission, error)
GetUserStatus implements /user.status
func (*Client) SetAPIKey ¶
SetAPIKey takes an user api key. If you use authorized methods, you must set it.
func (*Client) SetAPISecret ¶
SetAPISecret takes an user key secret. If you use authorized methods, you must set it.
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"`
}
Comment represents a Codeforces comment
type Contest ¶
type Contest struct {
DurationSeconds int64 `json:"durationSeconds"`
Frozen bool `json:"frozen"`
ID int64 `json:"id"`
Name string `json:"name"`
Phase string `json:"phase"`
RelativeTimeSeconds int64 `json:"relativeTimeSeconds"`
StartTimeSeconds int64 `json:"startTimeSeconds"`
Type string `json:"type"`
}
Contest represents a Codeforces Contest
func (Contest) ContestURL ¶
ContestURL returns the contest's url.
type ContestListOptions ¶
type ContestListOptions struct {
Gym bool `url:"gym"`
}
ContestListOptions represents the option of /contest.list
type ContestStatndingsOptions ¶
type ContestStatndingsOptions struct {
From int
Count int
Handles []string
Room int
ShowUnofficial bool
}
ContestStatndingsOptions represents the option of /contest.standings
type ContestStatusOptions ¶
ContestStatusOptions represents the option of /contest.status
type Hack ¶
type Hack struct {
CreationTimeSeconds int64 `json:"creationTimeSeconds"`
Defender Party `json:"defender"`
Hacker Party `json:"hacker"`
ID int64 `json:"id"`
JudgeProtocol JudgeProtocol `json:"judgeProtocol"`
Problem Problem `json:"problem"`
Test string `json:"test"`
Verdict string `json:"verdict"`
}
Hack represents Codeforces Hack
type JudgeProtocol ¶
type JudgeProtocol struct {
Manual string `json:"manual"`
Protocol string `json:"protocol"`
Verdict string `json:"verdict"`
}
JudgeProtocol represents Codefoces JudgeProtocol
type Member ¶
type Member struct {
Handle string `json:"handle"`
}
Member represents Codeforces Member
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"`
}
Party represents Codeforces Party
type Problem ¶
type Problem struct {
ContestID int `json:"contestId"`
Index string `json:"index"`
Name string `json:"name"`
Type string `json:"type"`
Points float32 `json:"points"`
Rating int `json:"rating"`
Tags []string `json:"tags"`
}
Problem represents Codeforces problem
type ProblemResult ¶
type ProblemResult struct {
Points float64 `json:"points"`
Penalty int `json:"penalty,omitempty"`
RejectedAttemptCount int64 `json:"rejectedAttemptCount"`
Type string `json:"type"`
BestSubmissionTimeSeconds int64 `json:"bestSubmissionTimeSeconds"`
}
ProblemResult represents codeforces ProblemResult
type ProblemSetProblemsOptions ¶
type ProblemSetProblemsOptions struct {
Tags []string
}
ProblemSetProblemsOptions specifies the optional parameters of the problemset.problems
type ProblemSetRecentStatus ¶
type ProblemSetRecentStatus struct {
Count int
}
ProblemSetRecentStatus specifies the optional parameters of the problemset.recentStatus
type ProblemStatistics ¶
type ProblemStatistics struct {
ContestID int `json:"contestId"`
Index string `json:"index"`
SolvedCount int `json:"solvedCount"`
}
ProblemStatistics represents Codeforces ProblemStatistics
type Problems ¶
type Problems struct {
Problems []Problem `json:"problems"`
ProblemStatistics []ProblemStatistics `json:"problemStatistics"`
}
Problems represents the response from /problemset.problems
type RanklistRow ¶
type RanklistRow struct {
Party Party `json:"party"`
Rank int64 `json:"rank"`
Points float64 `json:"points"`
Penalty int64 `json:"penalty"`
SuccessfulHackCount int64 `json:"successfulHackCount"`
UnsuccessfulHackCount int64 `json:"unsuccessfulHackCount"`
ProblemResults []ProblemResult `json:"problemResults"`
LastSubmissionTimeSeconds int64 `json:"lastSubmissionTimeSeconds"`
}
RanklistRow represents Codeforces RanklistRow
type RatingChange ¶
type RatingChange struct {
ContestID int64 `json:"contestId"`
ContestName string `json:"contestName"`
Handle string `json:"handle"`
NewRating int `json:"newRating"`
OldRating int `json:"oldRating"`
Rank int64 `json:"rank"`
RatingUpdateTimeSeconds int64 `json:"ratingUpdateTimeSeconds"`
}
RatingChange represents Codeforces RatingChange
func (RatingChange) RatingDiff ¶
func (r RatingChange) RatingDiff() int
RatingDiff returns NewRating - OldRating
type RecentAction ¶
type RecentAction struct {
TimeSeconds int `json:"timeSeconds"`
BlogEntry BlogEntry `json:"blogEntry"`
Comment Comment `json:"comment,omitempty"`
}
RecentAction represents Codeforces RecentAction
type Standings ¶
type Standings struct {
Contest Contest `json:"contest"`
Problems []Problem `json:"problems"`
Rows []RanklistRow `json:"rows"`
}
Standings represents Codeforces Standings
type Submission ¶
type Submission struct {
ID int `json:"id"`
ContestID int `json:"contestId"`
CreationTimeSeconds int64 `json:"creationTimeSeconds"`
RelativeTimeSeconds int64 `json:"relativeTimeSeconds"`
Problem Problem `json:"problem"`
Author Party `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"`
}
Submission represents a Codeforces Submission
func (*Submission) AC ¶
func (s *Submission) AC() bool
AC returns boolean whether submission passed all test cases
type User ¶
type User struct {
LastName string `json:"lastName"`
Country string `json:"country"`
LastOnlineTimeSeconds int `json:"lastOnlineTimeSeconds"`
City string `json:"city"`
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"`
}
User represents Codeforces User
func (User) Color ¶
Color returns user's color of rating. http://codeforces.com/blog/entry/20638
type UserFriendsOptions ¶
type UserFriendsOptions struct {
OnlyOnline bool
}
UserFriendsOptions represents the opetions of /user.friends
type UserRatedListOptions ¶
type UserRatedListOptions struct {
ActiveOnly bool
}
UserRatedListOptions represents the options of /user.ratedlist
type UserStatusOptions ¶
UserStatusOptions represents the opetions of /user.status