Documentation ¶
Index ¶
- Variables
- type GoHabitsError
- type HabiticaAPI
- func (api *HabiticaAPI) AddTag(name string) (Tag, error)
- func (api *HabiticaAPI) AddTask(t Task) (Task, error)
- func (api *HabiticaAPI) Authenticate(user string, password string) (UserToken, error)
- func (api *HabiticaAPI) ClearTagCache()
- func (api *HabiticaAPI) Delete(route string) error
- func (api *HabiticaAPI) DeleteTask(t Task) error
- func (api *HabiticaAPI) Do(req *http.Request, responseType interface{}) error
- func (api *HabiticaAPI) Get(route string, responseType interface{}) error
- func (api *HabiticaAPI) GetHostURL() string
- func (api *HabiticaAPI) GetServerStatus() (Status, error)
- func (api *HabiticaAPI) GetTag(name string) (Tag, error)
- func (api *HabiticaAPI) GetTagByID(id string) Tag
- func (api *HabiticaAPI) GetTags() ([]Tag, error)
- func (api *HabiticaAPI) GetTasks(tt TaskType) []Task
- func (api *HabiticaAPI) Post(url string, requestObject interface{}, responseObject interface{}) error
- func (api *HabiticaAPI) Put(url string, requestObject interface{}, responseObject interface{}) error
- func (api *HabiticaAPI) ScoreTaskUp(t Task) (ScoreUpDelta, error)
- func (api *HabiticaAPI) SetDueDate(t Task, date time.Time) (Task, error)
- func (api *HabiticaAPI) Stats() (Stats, error)
- func (api *HabiticaAPI) UpdateUserAuth(creds UserToken)
- type ScoreUpDelta
- type Stats
- type Status
- type Tag
- type Task
- type TaskType
- type UserToken
Constants ¶
This section is empty.
Variables ¶
var HabiticaDateExample = "2019-02-15T00:54:00.000Z"
HabiticaDateExample is to be used date.Format to be able to format dates to and from Habitica API timestamps and golang native times.
Functions ¶
This section is empty.
Types ¶
type GoHabitsError ¶
GoHabitsError is simple error struct that holds an error code as int
func NewGoHabitsError ¶
func NewGoHabitsError(message string, code int, path string) *GoHabitsError
NewGoHabitsError is constructor for GoHabitsError that includes program status code, uri/path, and a simple message string.
func (*GoHabitsError) Error ¶
func (err *GoHabitsError) Error() string
type HabiticaAPI ¶
type HabiticaAPI struct {
// contains filtered or unexported fields
}
HabiticaAPI Main client for interacting with Habitica API via HTTP
func NewHabiticaAPI ¶
NewHabiticaAPI is a function for creating a new client api. Can pass in prexisting client for proxies or what not.
func (*HabiticaAPI) AddTag ¶
func (api *HabiticaAPI) AddTag(name string) (Tag, error)
AddTag creates a new tag on the server using the name given
func (*HabiticaAPI) AddTask ¶
func (api *HabiticaAPI) AddTask(t Task) (Task, error)
AddTask will create the task on the server using the task struct as input. Any new task must have a title and type.
func (*HabiticaAPI) Authenticate ¶
func (api *HabiticaAPI) Authenticate(user string, password string) (UserToken, error)
Authenticate will return Habitica ID and APIToken with given username and password.
func (*HabiticaAPI) ClearTagCache ¶
func (api *HabiticaAPI) ClearTagCache()
ClearTagCache will clear out in-memory Tag cache for client
func (*HabiticaAPI) Delete ¶
func (api *HabiticaAPI) Delete(route string) error
Delete will take an url, and response as a struct and output errors for marshalling either.
func (*HabiticaAPI) DeleteTask ¶
func (api *HabiticaAPI) DeleteTask(t Task) error
DeleteTask removes a task from the habits server. Does not complete, cause rewards for removing.
func (*HabiticaAPI) Do ¶
func (api *HabiticaAPI) Do(req *http.Request, responseType interface{}) error
Do is a wrapper function around the api's http.client.Do but Marshals any json struct given to it. Also, it will parse http status errors over 400 and return an error.
func (*HabiticaAPI) Get ¶
func (api *HabiticaAPI) Get(route string, responseType interface{}) error
Get will return response from the passed in route of Habitica Api. It will also return errors in either HTTP Protocol or if status code is equal to or above 400.
func (*HabiticaAPI) GetHostURL ¶
func (api *HabiticaAPI) GetHostURL() string
GetHostURL returns client's hostURL configured.
func (*HabiticaAPI) GetServerStatus ¶
func (api *HabiticaAPI) GetServerStatus() (Status, error)
GetServerStatus will return response from `/status` route of Habitica Api. It will also return errors in either HTTP Protocol or if status code is equal to or above 400.
func (*HabiticaAPI) GetTag ¶
func (api *HabiticaAPI) GetTag(name string) (Tag, error)
GetTag returns a Tag by name, uses a cache to avoid multiple calls to server
func (*HabiticaAPI) GetTagByID ¶
func (api *HabiticaAPI) GetTagByID(id string) Tag
GetTagByID will return a tag by querying the habitica server. Uses a cache to avoid multiple calls
func (*HabiticaAPI) GetTags ¶
func (api *HabiticaAPI) GetTags() ([]Tag, error)
GetTags returns the users list of Tags and updates the tags cache.
func (*HabiticaAPI) GetTasks ¶
func (api *HabiticaAPI) GetTasks(tt TaskType) []Task
GetTasks will return tasks from Habitica as authenticated user. Should call api.Authenticate() before using this.
func (*HabiticaAPI) Post ¶
func (api *HabiticaAPI) Post(url string, requestObject interface{}, responseObject interface{}) error
Post will take in url, request data as a struct, and response as pointer to struct and output errors for marshalling either.
func (*HabiticaAPI) Put ¶
func (api *HabiticaAPI) Put(url string, requestObject interface{}, responseObject interface{}) error
Put will take in url, request data as a struct and repsonse as a struct and output errors for marshaling either
func (*HabiticaAPI) ScoreTaskUp ¶
func (api *HabiticaAPI) ScoreTaskUp(t Task) (ScoreUpDelta, error)
ScoreTaskUp calls api to score a task up. Equvilant to marking the task as completed. This results in a experience, gold, and other reward gain.
func (*HabiticaAPI) SetDueDate ¶
SetDueDate sets the due date for a task using the given date as a time struct
func (*HabiticaAPI) Stats ¶
func (api *HabiticaAPI) Stats() (Stats, error)
Stats returns a Stats object with the currently authenticated Habitica user's basic stats.
func (*HabiticaAPI) UpdateUserAuth ¶
func (api *HabiticaAPI) UpdateUserAuth(creds UserToken)
UpdateUserAuth takes a UserToken object and updates apiclient's user's id and token.
type ScoreUpDelta ¶
ScoreUpDelta contains the positive difference when a task is scored up. This will probably change to ScoreDelta or Delta when we are able to Score a task down.
type Stats ¶
type Stats struct { Level int Health int Mana int Experience int Gold int Class string Points int Strength int Constitution int Intelligence int Perception int ExperienceToNextLevel int MaxHealth int MaxMana int }
Stats struct with User's current stats
type Status ¶
type Status struct {
Status string
}
Status is a string that is usualy 'up' when Habitica API is full available
type Task ¶
type Task struct { Order int Title string `json:"text"` Tags []string `json:"tags"` ID string `json:"id"` Type string `json:"type"` Completed bool `json:"completed"` DueDate time.Time // contains filtered or unexported fields }
Task is a Habitica task.
type TaskType ¶
type TaskType int
TaskType is a int representation of the different types of tasks that Habitica has in it's api. Use the standard String() method to have a string version.