api

package
v2.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2016 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownTrack represents an error returned when the track requested does not exist.
	ErrUnknownTrack = errors.New("no such track")
)
View Source
var (
	// UserAgent lets the API know where the call is being made from.
	// It's set from main() so that we have access to the version.
	UserAgent string
)

Functions

This section is empty.

Types

type Client

type Client struct {
	APIHost  string
	XAPIHost string
	APIKey   string
	// contains filtered or unexported fields
}

Client contains the necessary information to contact the Exercism APIs.

func NewClient

func NewClient(c *config.Config) *Client

NewClient returns an Exercism API Client.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do performs an http.Request and optionally parses the response body into the given interface.

func (*Client) Download

func (c *Client) Download(submissionID string) (*Submission, error)

Download fetches a solution by submission key and writes it to disk.

func (*Client) Fetch

func (c *Client) Fetch(args []string) ([]*Problem, error)

Fetch retrieves problems from the API. Most problems consist of a README, some sort of test suite, and any supporting files (header files, test data, boilerplate, skeleton files, etc).

func (*Client) FetchAll

func (c *Client) FetchAll(trackID string) ([]*Problem, error)

FetchAll retrieves all problems for a given language track from the API

func (*Client) List

func (c *Client) List(trackID string) ([]string, error)

List available problems for a language track.

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, body io.Reader) (*http.Request, error)

NewRequest returns an http.Request with information for the Exercism API.

func (*Client) Restore

func (c *Client) Restore() ([]*Problem, error)

Restore fetches the latest revision of a solution and writes it to disk.

func (*Client) Skip

func (c *Client) Skip(trackID, slug string) error

Skip marks the exercise in the given language track as skipped.

func (*Client) Status

func (c *Client) Status(trackID string) (*StatusInfo, error)

Status sends a request to exercism to fetch the user's completion status for the given language track.

func (*Client) SubmissionURL

func (c *Client) SubmissionURL(trackID, slug string) (*Submission, error)

SubmissionURL gets the url of the latest iteration on the given language track id and problem slug.

func (*Client) Submissions

func (c *Client) Submissions() (map[string][]SubmissionInfo, error)

Submissions gets a list of submitted exercises and their current state.

func (*Client) Submit

func (c *Client) Submit(iter *Iteration) (*Submission, error)

Submit posts an iteration to the API.

func (*Client) Tracks

func (c *Client) Tracks() ([]*Track, error)

Tracks gets the current list of active and inactive language tracks.

type Iteration

type Iteration struct {
	Key      string            `json:"key"`
	Code     string            `json:"code"`
	Dir      string            `json:"dir"`
	TrackID  string            `json:"language"`
	Problem  string            `json:"problem"`
	Solution map[string]string `json:"solution"`
	Comment  string            `json:"comment,omitempty"`
}

Iteration represents a version of a particular exercise. This gets submitted to the API.

func NewIteration

func NewIteration(dir string, filenames []string) (*Iteration, error)

NewIteration prepares an iteration of a problem in a track for submission to the API. It takes a dir (from the global config) and a list of files which it will read from disk. All paths are assumed to be absolute paths with symlinks resolved.

func (*Iteration) RelativePath added in v1.7.5

func (iter *Iteration) RelativePath() string

RelativePath returns the iteration's relative path.

type PayloadError

type PayloadError struct {
	Error string `json:"error"`
}

PayloadError represents an error message from the API.

type PayloadProblems

type PayloadProblems struct {
	Problems []*Problem
	PayloadError
}

PayloadProblems represents a response containing problems.

type PayloadSubmission

type PayloadSubmission struct {
	*Submission
	PayloadError
}

PayloadSubmission represents metadata about a successful submission.

type Problem

type Problem struct {
	ID        string            `json:"id"`
	TrackID   string            `json:"track_id"`
	Language  string            `json:"language"`
	Slug      string            `json:"slug"`
	Name      string            `json:"name"`
	Files     map[string]string `json:"files"`
	Submitted bool
}

Problem represents a specific problem in a given language track.

func (*Problem) String

func (p *Problem) String() string

type Recent

type Recent struct {
	Problem     string `json:"problem"`
	SubmittedAt string `json:"submitted_at"`
}

Recent contains information about the user's most recently submitted exercise on a particular language track.

func (*Recent) String

func (r *Recent) String() string

type Slugs

type Slugs []string

Slugs is a collection of slugs, all of which are the names of exercises.

func (Slugs) String

func (s Slugs) String() string

type StatusInfo

type StatusInfo struct {
	TrackID         string `json:"track_id"`
	Recent          *Recent
	FetchedProblems *Slugs `json:"fetched"`
	SkippedProblems *Slugs `json:"skipped"`
}

StatusInfo contains information about a user's status on a particular language track.

func (*StatusInfo) String

func (s *StatusInfo) String() string

type Submission

type Submission struct {
	URL           string            `json:"url"`
	TrackID       string            `json:"track_id"`
	Language      string            `json:"language"`
	Slug          string            `json:"slug"`
	Name          string            `json:"name"`
	Username      string            `json:"username"`
	ProblemFiles  map[string]string `json:"problem_files"`
	SolutionFiles map[string]string `json:"solution_files"`
	Iteration     int               `json:"iteration"`
}

Submission is an iteration that has been submitted to the API.

type SubmissionInfo

type SubmissionInfo struct {
	Slug  string `json:"slug"`
	State string `json:"state"`
}

SubmissionInfo contains state information about a submission.

type Track added in v1.8.0

type Track struct {
	ID       string   `json:"id"`
	Language string   `json:"language"`
	Active   bool     `json:"active"`
	Problems []string `json:"problems"`
}

Track is a collection of problems in a given language.

func (*Track) Len added in v1.8.0

func (t *Track) Len() int

Len lists the number of problems a track has.

func (*Track) String added in v1.8.0

func (t *Track) String() string

Jump to

Keyboard shortcuts

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