go_groshi

package module
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 8 Imported by: 1

README

go-groshi

go client library for groshi API

Work is still in progress, breaking changes are to be expected!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient added in v0.1.12

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

APIClient represents groshi API client and includes all groshi API methods.

func NewAPIClient added in v0.1.12

func NewAPIClient(baseURL string, token string) *APIClient

NewAPIClient creates a new APIClient instance and returns pointer to it. It is the recommended method to produce APIClient.

func (*APIClient) Auth added in v0.1.12

func (c *APIClient) Auth(username string, password string) error

Auth is a helper function that uses AuthLogin groshi API method to authorize user. It also sets Token field of the `c` to the received token. Example:

client := NewAPIClient("http://localhost:8080", "") err := client.Auth("username-1234", "password-1234") currentUser, _ := client.UserRead() fmt.Printf("Authorized as %v", currentUser.Username)

func (*APIClient) AuthLogin added in v0.1.12

func (c *APIClient) AuthLogin(username string, password string) (*Authorization, error)

func (*APIClient) AuthRefresh added in v0.1.12

func (c *APIClient) AuthRefresh() (*Authorization, error)

func (*APIClient) CurrenciesRead added in v0.1.12

func (c *APIClient) CurrenciesRead() ([]*Currency, error)

CurrenciesRead returns slice of available currencies.

func (*APIClient) SetToken added in v0.1.12

func (c *APIClient) SetToken(token string)

SetToken is a setter method for authorization token. May be useful if you, for example, use APIClient to create a new user and then perform some operations that require authorization. For example:

client := NewAPIClient("http://localhost:8080", "") // create groshi client with empty token _, _ = client.UserCreate("username-1234", "password-1234") auth, _ := client.AuthLogin("username-1234", "password-1234") client.SetToken(auth.Token) currentUser, _ := client.UserRead() fmt.Printf("Authorized as %v", currentUser.Username)

func (*APIClient) TransactionsCreate added in v0.1.12

func (c *APIClient) TransactionsCreate(amount int, currency string, description *string, timestamp *time.Time) (*Transaction, error)

func (*APIClient) TransactionsDelete added in v0.1.12

func (c *APIClient) TransactionsDelete(uuid string) (*Transaction, error)

func (*APIClient) TransactionsReadMany added in v0.1.12

func (c *APIClient) TransactionsReadMany(startTime time.Time, endTime *time.Time, currency *string) ([]*Transaction, error)

func (*APIClient) TransactionsReadOne added in v0.1.12

func (c *APIClient) TransactionsReadOne(uuid string, currency *string) (*Transaction, error)

func (*APIClient) TransactionsReadSummary added in v0.1.12

func (c *APIClient) TransactionsReadSummary(currency string, startTime time.Time, endTime *time.Time) (*TransactionsSummary, error)

func (*APIClient) TransactionsUpdate added in v0.1.12

func (c *APIClient) TransactionsUpdate(
	uuid string, newAmount *int, newCurrency *string, newDescription *string, newTimestamp *time.Time,
) (*Transaction, error)

func (*APIClient) UserCreate added in v0.1.12

func (c *APIClient) UserCreate(username string, password string) (*User, error)

func (*APIClient) UserDelete added in v0.1.12

func (c *APIClient) UserDelete() (*User, error)

func (*APIClient) UserRead added in v0.1.12

func (c *APIClient) UserRead() (*User, error)

func (*APIClient) UserUpdate added in v0.1.12

func (c *APIClient) UserUpdate(newUsername *string, newPassword *string) (*User, error)

type APIError added in v0.1.12

type APIError struct {
	HTTPStatusCode int

	ErrorMessage string
	ErrorDetails []string
}

APIError represents groshi API error.

func (APIError) Error added in v0.1.12

func (e APIError) Error() string

type Authorization added in v0.1.1

type Authorization struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expires_at"`
}

Authorization represents successful response containing JWT to the authorization request.

type Currency added in v0.1.10

type Currency struct {
	Code   string `json:"code"`
	Symbol string `json:"symbol"`
}

Currency represents currency code along with its respective symbol.

type Error added in v0.1.1

type Error struct {
	ErrorMessage string   `json:"error_message"`
	ErrorDetails []string `json:"error_details"`
}

Error represents response containing information about API error.

type Transaction added in v0.1.1

type Transaction struct {
	UUID string `json:"uuid"`

	Amount      int       `json:"amount"`
	Currency    string    `json:"currency"`
	Description string    `json:"description"`
	Timestamp   time.Time `json:"timestamp"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Transaction represents response containing transaction information.

type TransactionsSummary added in v0.1.1

type TransactionsSummary struct {
	Currency string `json:"currency"`

	Income  int `json:"income"`
	Outcome int `json:"outcome"`
	Total   int `json:"total"`

	TransactionsCount int `json:"transactions_count"`
}

TransactionsSummary represents summary of transactions, returned by transactionsReadSummary handler.

type User added in v0.1.1

type User struct {
	Username string `json:"username"`
}

User represents response containing information about user.

Jump to

Keyboard shortcuts

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