api

package
v0.0.0-...-c5339c6 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

type GoHabitsError struct {
	StatusCode int
	Path       string
	// contains filtered or unexported fields
}

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

func NewHabiticaAPI(client *http.Client, hosturl string, logger log.Logger) *HabiticaAPI

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

func (api *HabiticaAPI) SetDueDate(t Task, date time.Time) (Task, error)

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

type ScoreUpDelta struct {
	Mp  float64 `json:"mp"`
	Exp float64 `json:"exp"`
	Gp  float64 `json:"gp"`
}

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 Tag

type Tag struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Tag is struct for tags on tasks

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.

func NewTask

func NewTask(title string, tt TaskType) Task

NewTask creates a new task of a particular Task type.

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.

const (
	HabitType         TaskType = 0
	DailyType         TaskType = 1
	TodoType          TaskType = 2
	RewardType        TaskType = 3
	CompletedTodoType TaskType = 4
)

Constant types that should be used when creating or getting tasks from Habitica server.

func (TaskType) String

func (tt TaskType) String() string

type UserToken

type UserToken struct {
	ID       string `json:"id"`
	APIToken string `json:"apitoken"`
	UserName string `json:"username"`
	Password string `json:"password"`
}

UserToken contains user ID and Token to make API calls.

Jump to

Keyboard shortcuts

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