monobank

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: MIT Imports: 9 Imported by: 0

README

go-monobank

Godoc Reference

Monobank REST API client. Currently supported only personal authorization(with Token).

Usage

import (
    "github.com/vtopc/go-monobank"
)

func main(){
    client := monobank.New(nil, monobank.NewPersonalAuthorizer(os.Getenv("TOKEN")))
    response, err := client.ClientInfo()
}

Official docs

Similar projects

TODO

  • Corporate Authorization
  • Corporate API(init/check auth)
  • More unit tests
  • Linter
  • CI for tests

Documentation

Overview

Package mono - is MonoBank API client https://api.monobank.ua/docs/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	AccountID    string `json:"id"`
	Balance      int64  `json:"balance"`
	CreditLimit  int64  `json:"creditLimit"`
	CurrencyCode int    `json:"currencyCode"`
	CashbackType string `json:"cashbackType"` // enum: None, UAH, Miles
}

type Accounts

type Accounts []Account

type Authorizer

type Authorizer interface {
	// SetAuth modifies http.Request and sets authorization tokens
	SetAuth(*http.Request)
}

type Client

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

func New

func New(client *http.Client) Client

New - returns new monobank Client

func (Client) ClientInfo

func (c Client) ClientInfo() (*ClientInfo, error)

func (Client) Currency

func (c Client) Currency() (Currencies, error)

func (Client) Do

func (c Client) Do(req *http.Request, expectedStatusCode int, v interface{}) error

Do does request. Stores JSON response in the value pointed to by v.

func (Client) SetWebHook

func (c Client) SetWebHook(uri string) error

func (Client) Transactions added in v0.2.0

func (c Client) Transactions(accountID string, from, to time.Time) (Transactions, error)

TODO: make `to` optional

func (Client) WithAuth

func (c Client) WithAuth(auth Authorizer) Client

WithAuth returns copy of Client with authorizer

func (Client) WithBaseURL

func (c Client) WithBaseURL(uri string) Client

WithAuth returns copy of Client with overridden baseURL

type ClientInfo

type ClientInfo struct {
	Name     string   `json:"name"`
	Accounts Accounts `json:"accounts"`
}

ClientInfo - client/user info

type Currencies

type Currencies []Currency

type Currency

type Currency struct {
	CurrencyCodeA int     `json:"currencyCodeA"`
	CurrencyCodeB int     `json:"currencyCodeB"`
	Date          Time    `json:"date"`
	RateSell      float64 `json:"rateSell"`
	RateBuy       float64 `json:"rateBuy"`
	RateCross     float64 `json:"rateCross"`
}

type PersonalAPI added in v0.2.0

type PersonalAPI interface {
	PublicAPI

	// ClientInfo - https://api.monobank.ua/docs/#/definitions/UserInfo
	ClientInfo() (*ClientInfo, error)

	// Transactions - gets bank account statements(transations)
	// https://api.monobank.ua/docs/#/definitions/StatementItems
	Transactions(accountID string, from, to time.Time) (Transactions, error)

	// SetWebHook - sets webhook for statements
	SetWebHook(uri string) error
}

type PersonalAuthorizer

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

func NewPersonalAuthorizer

func NewPersonalAuthorizer(token string) PersonalAuthorizer

func (PersonalAuthorizer) SetAuth

func (a PersonalAuthorizer) SetAuth(req *http.Request)

type PublicAPI added in v0.2.0

type PublicAPI interface {
	// Currency https://api.monobank.ua/docs/#/definitions/CurrencyInfo
	Currency() (Currencies, error)
}

type PublicAuthorizer

type PublicAuthorizer struct{}

func NewPublicAuthorizer

func NewPublicAuthorizer() PublicAuthorizer

func (PublicAuthorizer) SetAuth

func (a PublicAuthorizer) SetAuth(req *http.Request)

type Time

type Time struct {
	time.Time // embeding with inheritance
}

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

type Transaction added in v0.2.0

type Transaction struct {
	ID              string `json:"id"`
	Time            Time   `json:"time"`
	Description     string `json:"description"`
	MCC             int32  `json:"mcc"`
	Hold            bool   `json:"hold"`
	Amount          int64  `json:"amount"`
	OperationAmount int64  `json:"operationAmount"`
	CurrencyCode    int    `json:"currencyCode"`
	CommissionRate  int64  `json:"commissionRate"`
	CashbackAmount  int64  `json:"cashbackAmount"`
	Balance         int64  `json:"balance"`
	Comment         string `json:"comment"`
}

Transaction - bank account statement

type Transactions added in v0.2.0

type Transactions []Transaction

Transactions - transactions

type WebHookData

type WebHookData struct {
	AccountID string `json:"account"`
	// TODO: rename to Transaction:
	Statement Transaction `json:"statementItem"`
}

type WebHookRequest

type WebHookRequest struct {
	WebHookURL string `json:"webHookUrl"`
}

type WebHookResponse

type WebHookResponse struct {
	Type string      `json:"type"` // "StatementItem"
	Data WebHookData `json:"data"`
}

Jump to

Keyboard shortcuts

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