Documentation ¶
Index ¶
- type APIClient
- func (c *APIClient) Auth(username string, password string) error
- func (c *APIClient) AuthLogin(username string, password string) (*Authorization, error)
- func (c *APIClient) AuthRefresh() (*Authorization, error)
- func (c *APIClient) CurrenciesRead() ([]*Currency, error)
- func (c *APIClient) SetToken(token string)
- func (c *APIClient) TransactionsCreate(amount int, currency string, description *string, timestamp *time.Time) (*Transaction, error)
- func (c *APIClient) TransactionsDelete(uuid string) (*Transaction, error)
- func (c *APIClient) TransactionsReadMany(startTime time.Time, endTime *time.Time, currency *string) ([]*Transaction, error)
- func (c *APIClient) TransactionsReadOne(uuid string, currency *string) (*Transaction, error)
- func (c *APIClient) TransactionsReadSummary(currency string, startTime time.Time, endTime *time.Time) (*TransactionsSummary, error)
- func (c *APIClient) TransactionsUpdate(uuid string, newAmount *int, newCurrency *string, newDescription *string, ...) (*Transaction, error)
- func (c *APIClient) UserCreate(username string, password string) (*User, error)
- func (c *APIClient) UserDelete() (*User, error)
- func (c *APIClient) UserRead() (*User, error)
- func (c *APIClient) UserUpdate(newUsername *string, newPassword *string) (*User, error)
- type APIError
- type Authorization
- type Currency
- type Error
- type Transaction
- type TransactionsSummary
- type User
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
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
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
CurrenciesRead returns slice of available currencies.
func (*APIClient) SetToken ¶ added in v0.1.12
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 (*APIClient) TransactionsDelete ¶ added in v0.1.12
func (c *APIClient) TransactionsDelete(uuid string) (*Transaction, error)
func (*APIClient) TransactionsReadMany ¶ added in v0.1.12
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 (*APIClient) TransactionsUpdate ¶ added in v0.1.12
func (*APIClient) UserCreate ¶ added in v0.1.12
func (*APIClient) UserDelete ¶ added in v0.1.12
type Authorization ¶ added in v0.1.1
Authorization represents successful response containing JWT to the authorization request.
type Currency ¶ added in v0.1.10
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.