go_eudic

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

README

CI

EUDIC SDK for Go

REST endpoint

This SDK only supports for the part of reciting with the API host: https://api.frdic.com

General HTTP Headers:

  • Content-Type: application/json;charset=utf-8
  • User-Agent: /eusoft_eudic_en_mac/4.0.2/A4:83:E7:90:13:5D/explain/
export EUDIC_USERNAME="change me"
export EUDIC_PASSWORD="change me"
go test ./...

Usage

go get -u github.com/Lonor/go-eudic
package main

import (
	eudic "github.com/Lonor/go-eudic"
)

func main() {
	client, _ := eudic.NewEudicClientByPassword(
		"mail address",
		"your password",
	)
	book, _, _ := client.LastBookService.GetLastBook()
}

LICENSE

This project is under the GPLv3.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BaseURL   = "https://api.frdic.com"
	UserAgent = "/eusoft_eudic_en_mac/4.0.0/A4:83:E7:90:13:D5/explain/"
)

Functions

func CheckHTTPResponse

func CheckHTTPResponse(httpResponse *http.Response) error

func GetTheFirstNumberFromString

func GetTheFirstNumberFromString(stringContainsNumber string) string

获取字符串参数中的首个数字

func StructToString

func StructToString(v interface{}) (string, error)

Types

type AnswerCardRequest

type AnswerCardRequest struct {
	AnswerEase    int64  `json:"answer_ease"`
	BookID        string `json:"book_id"`
	BookName      string `json:"book_name"`
	BookUUID      string `json:"book_uuid"`
	CardID        int64  `json:"card_id"`
	Cookie        string `json:"cookie"`
	DailyCount    int64  `json:"daily_count"`
	EudicTimezone int64  `json:"eudic_timezone"`
	Lang          string `json:"lang"`
	ListType      int64  `json:"list_type"`
	Meta          string `json:"meta"`
	Token         string `json:"token"`
	UseReciteUa   bool   `json:"use_recite_ua"`
	Userid        string `json:"userid"`
}

type AnswerCardService

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

func (*AnswerCardService) AnswerCard

func (service *AnswerCardService) AnswerCard(bookId, bookName string, cardId, answerEase int64) (*ReciteResponse, error)

type CheckInInfoResponse

type CheckInInfoResponse struct {
	CheckinDate string `json:"checkin_date"`
	Continuous  int64  `json:"continuous"`
	Count       int64  `json:"count"`
	Goldcount   int64  `json:"goldcount"`
	Ischeckin   bool   `json:"ischeckin"`
}

type CheckInRequest added in v0.1.0

type CheckInRequest struct {
	Cookie        string `json:"cookie"`
	EudicTimezone int64  `json:"eudic_timezone"`
	Lang          string `json:"lang"`
	Token         string `json:"token"`
	UseReciteUa   bool   `json:"use_recite_ua"`
	Userid        string `json:"userid"`
}

type CheckInResponse added in v0.1.0

type CheckInResponse struct {
	CheckinDate string `json:"checkin_date"`
	Continuous  int64  `json:"continuous"`
	Count       int64  `json:"count"`
	Goldcount   int64  `json:"goldcount"`
	Ischeckin   bool   `json:"ischeckin"`
	Reward      int64  `json:"reward"`
}

type CheckInService added in v0.1.0

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

func (*CheckInService) CheckIn added in v0.1.0

func (service *CheckInService) CheckIn() (*CheckInResponse, error)

func (*CheckInService) GetCheckInInfo added in v0.1.0

func (service *CheckInService) GetCheckInInfo() (*CheckInInfoResponse, *string, error)

type EudicClient

type EudicClient struct {
	BaseURL   string
	UserAgent string
	UserId    string
	Token     string

	Response *Response

	LoginService       *LoginService
	UserInfoService    *UserInfoService
	CheckInService     *CheckInService
	LastBookService    *LastBookService
	SyncReciteService  *SyncReciteService
	StartReciteService *StartReciteService
	AnswerCardService  *AnswerCardService
	// contains filtered or unexported fields
}

func NewEudicClient

func NewEudicClient(userId, token string) *EudicClient

func NewEudicClientByPassword

func NewEudicClientByPassword(username, password string) (*EudicClient, error)

func (*EudicClient) Do

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

v: response

func (*EudicClient) NewRequest

func (eudic *EudicClient) NewRequest(method string, uri string, body string) (*http.Request, error)

type LastBodyResponse

type LastBodyResponse struct {
	BookName string `json:"bookName"`
	Meta     struct {
		Bookid    string `json:"bookid"`
		Lang      string `json:"lang"`
		Meta      string `json:"meta"`
		Timestamp string `json:"timestamp"`
		Userid    string `json:"userid"`
		Version   string `json:"version"`
	} `json:"meta"`
	StatisticData struct {
		AverageDailyLearningCardCount float64 `json:"averageDailyLearningCardCount"`
		DailyHistory                  []struct {
			Day             int64   `json:"day"`
			LevelDifference int64   `json:"levelDifference"`
			NewCount        int64   `json:"newCount"`
			Progress        float64 `json:"progress"`
			ReciteCount     int64   `json:"reciteCount"`
			ReciteDuration  int64   `json:"reciteDuration"`
		} `json:"dailyHistory"`
		LearningCardCount int64   `json:"learningCardCount"`
		MatureCardCount   int64   `json:"matureCardCount"`
		NewCardCount      int64   `json:"newCardCount"`
		Progress          float64 `json:"progress"`
		TotalCardCount    int64   `json:"totalCardCount"`
	} `json:"statisticData"`
	TodayProgress struct {
		PendingDueCardCount int64 `json:"pendingDueCardCount"`
		PendingNewCardCount int64 `json:"pendingNewCardCount"`
		TodayFinishedCount  int64 `json:"todayFinishedCount"`
		TodayTouchedCount   int64 `json:"todayTouchedCount"`
	} `json:"todayProgress"`
}

type LastBookRequest

type LastBookRequest struct {
	Cookie      string `json:"cookie"`
	DailyCount  int64  `json:"daily_count"`
	Lang        string `json:"lang"`
	Token       string `json:"token"`
	UseReciteUa bool   `json:"use_recite_ua"`
	Userid      string `json:"userid"`
}

type LastBookService

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

func (*LastBookService) GetLastBook

func (service *LastBookService) GetLastBook() (*LastBodyResponse, *string, error)

type LoginRequest

type LoginRequest struct {
	Password string `json:"password"`
	Username string `json:"username"`
}

type LoginResponse

type LoginResponse struct {
	CreationDate            string      `json:"creation_date"`
	Expirein                int64       `json:"expirein"`
	HasOldPassword          bool        `json:"has_old_password"`
	LastPasswordChangedDate interface{} `json:"last_password_changed_date"`
	OpenidDesc              interface{} `json:"openid_desc"`
	OpenidType              interface{} `json:"openid_type"`
	Profile                 struct {
		Email        string      `json:"email"`
		Gender       string      `json:"gender"`
		Nickname     string      `json:"nickname"`
		Password     interface{} `json:"password"`
		Vocabularies struct{}    `json:"vocabularies"`
	} `json:"profile"`
	RedirectURL interface{} `json:"redirect_url"`
	Roles       interface{} `json:"roles"`
	Token       string      `json:"token"`
	Userid      string      `json:"userid"`
	Username    string      `json:"username"`
}

type LoginService

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

func (*LoginService) Login

func (service *LoginService) Login(username, password string) (*LoginResponse, error)

type ReciteResponse

type ReciteResponse struct {
	Card struct {
		AddTime       int64  `json:"addTime"`
		Answer        string `json:"answer"`
		AnswerHistory []struct {
			DueTimeInterval int64   `json:"dueTimeInterval"`
			EaseFactor      float64 `json:"easeFactor"`
			EaseLevel       int64   `json:"easeLevel"`
			Level           int64   `json:"level"`
			Meta            string  `json:"meta"`
			ReciteDuration  int64   `json:"reciteDuration"`
			ReciteTime      int64   `json:"reciteTime"`
		} `json:"answerHistory"`
		CandidateExplains []struct {
			Answer   string `json:"answer"`
			Question string `json:"question"`
		} `json:"candidateExplains"`
		CardID                 int64       `json:"card_id"`
		CurrentReciteEndTime   int64       `json:"currentReciteEndTime"`
		CurrentReciteStartTime int64       `json:"currentReciteStartTime"`
		DueTime                int64       `json:"dueTime"`
		EaseFactor             float64     `json:"easeFactor"`
		FirstReciteTime        int64       `json:"firstReciteTime"`
		LastDueTime            int64       `json:"lastDueTime"`
		LastEaseFactor         float64     `json:"lastEaseFactor"`
		Level                  int64       `json:"level"`
		LocalTimestamp         int64       `json:"local_timestamp"`
		LocalUpdate            bool        `json:"local_update"`
		Question               string      `json:"question"`
		Rating                 int64       `json:"rating"`
		ResInfo                interface{} `json:"resInfo"`
		Status                 int64       `json:"status"`
		Timezone               int64       `json:"timezone"`
		Tombstone              bool        `json:"tombstone"`
		TotalBrowseTime        int64       `json:"totalBrowseTime"`
		TotalReciteTime        int64       `json:"totalReciteTime"`
		Unit                   int64       `json:"unit"`
	} `json:"card"`
	Explain struct {
		Phonukurl string `json:"phonukurl"`
		Phonusurl string `json:"phonusurl"`
		Word      string `json:"word"`
	} `json:"explain"`
	StatisticData struct {
		AverageDailyLearningCardCount float64 `json:"averageDailyLearningCardCount"`
		DailyHistory                  []struct {
			Day             int64   `json:"day"`
			LevelDifference int64   `json:"levelDifference"`
			NewCount        int64   `json:"newCount"`
			Progress        float64 `json:"progress"`
			ReciteCount     int64   `json:"reciteCount"`
			ReciteDuration  int64   `json:"reciteDuration"`
		} `json:"dailyHistory"`
		LearningCardCount int64   `json:"learningCardCount"`
		MatureCardCount   int64   `json:"matureCardCount"`
		NewCardCount      int64   `json:"newCardCount"`
		Progress          float64 `json:"progress"`
		TotalCardCount    int64   `json:"totalCardCount"`
	} `json:"statisticData"`
	TaskFinished  bool   `json:"taskFinished"`
	TaskInfo      string `json:"taskInfo"`
	TodayProgress struct {
		PendingDueCardCount int64 `json:"pendingDueCardCount"`
		PendingNewCardCount int64 `json:"pendingNewCardCount"`
		TodayFinishedCount  int64 `json:"todayFinishedCount"`
		TodayTouchedCount   int64 `json:"todayTouchedCount"`
	} `json:"todayProgress"`
}

type RequestTokenBody

type RequestTokenBody struct {
	Token         string `json:"token"`
	UserId        string `json:"userid"`
	Cookie        string `json:"cookie"`
	EudicTimeZone int    `json:"eudic_timezone"`
	Lang          string `json:"lang"`
}

type Response

type Response struct {
	HTTPResponse *http.Response
	BodyStrPtr   *string
	Data         interface{}
}

type StartReciteRequest

type StartReciteRequest struct {
	BookID        string `json:"book_id"`
	BookName      string `json:"book_name"`
	BookUUID      string `json:"book_uuid"`
	Cookie        string `json:"cookie"`
	DailyCount    int64  `json:"daily_count"`
	EudicTimezone int64  `json:"eudic_timezone"`
	Lang          string `json:"lang"`
	ListType      int64  `json:"list_type"`
	Meta          string `json:"meta"`
	Token         string `json:"token"`
	UseReciteUa   bool   `json:"use_recite_ua"`
	Userid        string `json:"userid"`
}

type StartReciteService

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

func (*StartReciteService) StartRecite

func (service *StartReciteService) StartRecite(bookId, bookName string) (*ReciteResponse, error)

开始背诵词汇,bookId 为纯数字字符串, 并非 LastBook 返回的 Meta.BookId, 调用时正则取其中的数字,参考测试

type SyncReciteRequest

type SyncReciteRequest struct {
	BookID      string `json:"book_id"`
	BookName    string `json:"book_name"`
	BookUUID    string `json:"book_uuid"`
	Cookie      string `json:"cookie"`
	Lang        string `json:"lang"`
	ListType    int64  `json:"list_type"`
	Token       string `json:"token"`
	UseReciteUa bool   `json:"use_recite_ua"`
	Userid      string `json:"userid"`
}

type SyncReciteService

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

func (*SyncReciteService) SyncRecite

func (service *SyncReciteService) SyncRecite(bookId, bookName string) (bool, error)

Sync the learning records

type UserInfo

type UserInfo struct {
	CreationDate            string      `json:"creation_date"`
	Expirein                int64       `json:"expirein"`
	HasOldPassword          bool        `json:"has_old_password"`
	LastPasswordChangedDate interface{} `json:"last_password_changed_date"`
	OpenidDesc              interface{} `json:"openid_desc"`
	OpenidType              interface{} `json:"openid_type"`
	Profile                 struct {
		Email        string      `json:"email"`
		Gender       string      `json:"gender"`
		Nickname     string      `json:"nickname"`
		Password     interface{} `json:"password"`
		Vocabularies struct{}    `json:"vocabularies"`
	} `json:"profile"`
	RedirectURL interface{} `json:"redirect_url"`
	Roles       interface{} `json:"roles"`
	Token       string      `json:"token"`
	Userid      string      `json:"userid"`
	Username    string      `json:"username"`
}

type UserInfoService

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

func (*UserInfoService) GetUserInfo

func (service *UserInfoService) GetUserInfo() (*UserInfo, *string, error)

Jump to

Keyboard shortcuts

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