wk

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 7 Imported by: 0

README

go-wanikani-api

An unofficial API client designed for the WaniKani API.

Install

go get github.com/KaniLeap/go-wanikani-api

Quick start

ctx := context.Background()
cl := wk.NewClient(os.Getenv("WANIKANI_TOKEN"))

// Get current user
u, err := cl.GetUser(ctx)
if err != nil { log.Fatal(err) }
fmt.Println(u.Data.Name, u.Data.Level)

// List subjects (first page)
subs, err := cl.GetSubjects(ctx, wk.WithLevels([]int{1,2,3}))
if err != nil { log.Fatal(err) }
for _, it := range subs.Data.Data {
    fmt.Println(it.Id, it.Data.Slug)
}

// Paginate
for subs.HasNext() {
    if err := subs.Next(); err != nil { break }
}

// Get assignments available for review
asgn, err := cl.GetAssignments(ctx, wk.WithAvailableReviews(true))
if err != nil { log.Fatal(err) }
fmt.Println("assignments count:", asgn.Data.Count)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoNextPage     = errors.New("no next page")
	ErrNoPreviousPage = errors.New("no previous page")
	ErrEmptyURL       = errors.New("url is empty")
)

Functions

This section is empty.

Types

type Assignment

type Assignment struct {
	SubjectType   string     `json:"subject_type"`
	SubjectID     int        `json:"subject_id"`
	Level         int        `json:"level"`
	Stage         int        `json:"srs_stage"`
	UnlockedAt    *time.Time `json:"unlocked_at"`
	StartedAt     *time.Time `json:"started_at"`
	PassedAt      *time.Time `json:"passed_at"`
	BurnedAt      *time.Time `json:"burned_at"`
	AvailableAt   *time.Time `json:"available_at"`
	ResurrectedAt *time.Time `json:"resurrected_at"`
}

type Assignments

type Assignments struct {
	StartedAt time.Time `json:"started_at"`
}

type Client

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

func NewClient

func NewClient(token string) *Client

func NewClientWithHTTP added in v0.2.1

func NewClientWithHTTP(hc *http.Client, token string) *Client

func (*Client) CreateReview added in v0.1.0

func (c *Client) CreateReview(ctx context.Context, payload Reviews, opts ...Option) (*ReviewResponse, error)

func (*Client) GetAssignment

func (c *Client) GetAssignment(ctx context.Context, id int, opts ...Option) (*Resource[Assignment], error)

func (*Client) GetAssignments

func (c *Client) GetAssignments(ctx context.Context, opts ...Option) (*Paginate[Assignment], error)

func (*Client) GetSubject added in v0.1.0

func (c *Client) GetSubject(ctx context.Context, id int, opts ...Option) (*Resource[Subject], error)

func (*Client) GetSubjects added in v0.1.0

func (c *Client) GetSubjects(ctx context.Context, opts ...Option) (*Paginate[Subject], error)

func (*Client) GetUser added in v0.2.0

func (c *Client) GetUser(ctx context.Context, opts ...Option) (*Resource[User], error)

func (*Client) StartAssignment

func (c *Client) StartAssignment(ctx context.Context, payload Assignments, id int, opts ...Option) (*Resource[Assignment], error)

func (*Client) UpdateUser added in v0.2.0

func (c *Client) UpdateUser(ctx context.Context, payload Users, opts ...Option) (*Resource[User], error)

type Collection

type Collection[T any] struct {
	CollectionBase
	Data []Resource[T] `json:"data"`
}

type CollectionBase

type CollectionBase struct {
	Shared
	Pages struct {
		NextURL     string `json:"next_url"`
		PreviousURL string `json:"previous_url"`
		PerPage     int    `json:"per_page"`
	} `json:"pages"`
	Count int `json:"total_count"`
}

type Option

type Option func(*options) error

func WithAvailableAfter

func WithAvailableAfter(t time.Time) Option

func WithAvailableBefore

func WithAvailableBefore(t time.Time) Option

func WithAvailableLessons

func WithAvailableLessons(available bool) Option

func WithAvailableReviews

func WithAvailableReviews(available bool) Option

func WithBurned

func WithBurned(burned bool) Option

func WithHidden

func WithHidden(hidden bool) Option

func WithIDs added in v0.2.1

func WithIDs(ids ...int) Option

func WithLevels

func WithLevels(levels []int) Option

Works on assignments and subjects.

func WithSlugs added in v0.1.0

func WithSlugs(slugs []string) Option

func WithStages added in v0.2.1

func WithStages(stages ...int) Option

func WithSubjectIDs

func WithSubjectIDs(ids []int) Option

func WithSubjectTypes

func WithSubjectTypes(types []string) Option

func WithTypes added in v0.1.0

func WithTypes(types []SubjectType) Option

func WithUnlocked

func WithUnlocked(unlocked bool) Option

func WithUpdatedAfter

func WithUpdatedAfter(t time.Time) Option

type Paginate

type Paginate[T any] struct {
	Data Collection[T]
	// contains filtered or unexported fields
}

func (*Paginate[T]) HasNext added in v0.2.1

func (p *Paginate[T]) HasNext() bool

func (*Paginate[T]) HasPrevious added in v0.2.1

func (p *Paginate[T]) HasPrevious() bool

func (*Paginate[T]) Next

func (p *Paginate[T]) Next() error

func (*Paginate[T]) Previous

func (p *Paginate[T]) Previous() error

type Preferences added in v0.2.0

type Preferences struct {
	DefaultVoiceActorID        int    `json:"default_voice_actor_id"`
	ExtraStudyAutoplayAudio    bool   `json:"extra_study_autoplay_audio"`
	LessonsAutoplayAudio       bool   `json:"lessons_autoplay_audio"`
	LessonsBatchSize           int    `json:"lessons_batch_size"`
	LessonsPresentationOrder   string `json:"lessons_presentation_order"`
	ReviewsAutoplayAudio       bool   `json:"reviews_autoplay_audio"`
	ReviewsDisplaySrsIndicator bool   `json:"reviews_display_srs_indicator"`
	ReviewsPresentationOrder   string `json:"reviews_presentation_order"`
}

type Resource

type Resource[T any] struct {
	ResourceBase
	Data T `json:"data"`
}

type ResourceBase

type ResourceBase struct {
	Shared
	ID int `json:"id"`
}

type Review added in v0.1.0

type Review struct {
	ReviewBase
	SubjectID   int `json:"subject_id"`
	StartingSRS int `json:"starting_srs_stage"`
	EndingSRS   int `json:"ending_srs_stage"`
	SRSID       int `json:"spaced_repetition_system_id"`
}

type ReviewBase added in v0.1.0

type ReviewBase struct {
	AssignmentID      int       `json:"assignment_id"`
	IncorrectMeanings int       `json:"incorrect_meaning_answers"`
	IncorrectReadings int       `json:"incorrect_reading_answers"`
	CreatedAt         time.Time `json:"created_at"`
}

type ReviewResourcesUpdated added in v0.3.0

type ReviewResourcesUpdated struct {
	Assignment Resource[Assignment] `json:"assignment"`
}

type ReviewResponse added in v0.3.0

type ReviewResponse struct {
	Resource[Review]
	ResourcesUpdated ReviewResourcesUpdated `json:"resources_updated"`
}

type Reviews

type Reviews struct {
	Review ReviewBase `json:"review"`
}

type Shared

type Shared struct {
	Object    string    `json:"object"`
	URL       string    `json:"url"`
	UpdatedAt time.Time `json:"data_updated_at"`
}

type StudyMaterials added in v0.1.0

type StudyMaterials struct {
	StudyMaterial struct {
		SubjectID       int      `json:"subject_id"`
		MeaningNote     string   `json:"meaning_note"`
		ReadingNote     string   `json:"reading_note"`
		MeaningSynonyms []string `json:"meaning_synonyms"`
	} `json:"study_material"`
}

type Subject added in v0.1.0

type Subject struct {
	AuxiliaryMeanings []struct {
		Meaning        string `json:"meaning"`
		Primary        bool   `json:"primary"`
		AcceptedAnswer bool   `json:"accepted_answer"`
	}
	Characters      string     `json:"characters"`
	CreatedAt       time.Time  `json:"created_at"`
	DocumentURL     string     `json:"document_url"`
	HiddenAt        *time.Time `json:"hidden_at"`
	Level           int        `json:"level"`
	MeaningMnemonic string     `json:"meaning_mnemonic"`
	Meanings        []struct {
		Meaning string `json:"meaning"`
		Type    string `json:"type"`
	}
	Slug  string `json:"slug"`
	SRSID int    `json:"spaced_repetition_system_id"`
}

type SubjectType added in v0.3.0

type SubjectType string
const (
	SubjectTypeKanaVocabulary SubjectType = "kana_vocabulary"
	SubjectTypeKanji          SubjectType = "kanji"
	SubjectTypeRadical        SubjectType = "radical"
	SubjectTypeVocabulary     SubjectType = "vocabulary"
)

type User

type User struct {
	ID                       string     `json:"id"`
	Name                     string     `json:"username"`
	Level                    int        `json:"level"`
	ProfileURL               string     `json:"profile_url"`
	StartedAt                time.Time  `json:"started_at"`
	CurrentVacationStartedAt *time.Time `json:"current_vacation_started_at"`
	Subscription             struct {
		Active          bool      `json:"active"`
		Type            string    `json:"type"`
		MaxLevelGranted int       `json:"max_level_granted"`
		PeriodEndsAt    time.Time `json:"period_ends_at"`
	} `json:"subscription"`
	Preferences Preferences `json:"preferences"`
}

type Users added in v0.1.0

type Users struct {
	User struct {
		Preferences Preferences `json:"preferences"`
	} `json:"user"`
}

Jump to

Keyboard shortcuts

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