savey

package module
v0.0.0-...-48cc374 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2017 License: MIT Imports: 11 Imported by: 0

README

Savey

Build Status

Export data from your favourite money management tool http://www.savey.co/.

Install

go get github.com/jbub/savey

Example

package main

import (
	"encoding/json"
	"log"

	"github.com/jbub/savey"
)

const (
	userLogin    = "your@login.com"
	userPassword = "yourpassword"
)

func checkErr(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
    // create new savey client with default HTTP client
	client, err := savey.NewClient(nil)
	checkErr(err)
    
    // login user using username and password
	err = client.Login(userLogin, userPassword)
	checkErr(err)
    
    // list payment accounts of current user
	accounts, err := client.Accounts.GetAccounts()
	checkErr(err)
    
    // list categories of current user
	categories, err := client.Categories.GetCategories()
	checkErr(err)
    
    // list all transactions for given accounts of current user
	transactions, err := client.Transactions.GetTransactions(accounts)
	checkErr(err)
    
    // logout user
	err = client.Logout()
	checkErr(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDefaultHTTPClient

func CreateDefaultHTTPClient() (*http.Client, error)

CreateDefaultHTTPClient creates default HTTP with cookie jar.

Types

type Account

type Account struct {
	ID       int64  `json:"id"`
	Title    string `json:"title"`
	Currency string `json:"currency"`
}

Account represents payment account.

type AccountService

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

AccountService provides methods for working with payment accounts.

func (*AccountService) GetAccounts

func (s *AccountService) GetAccounts() ([]Account, error)

GetAccounts lists accounts for current user.

type Category

type Category struct {
	ID    int64  `json:"id"`
	Title string `json:"title"`
	Kind  string `json:"kind"`
}

Category represents transaction category.

type CategoryService

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

CategoryService provides methods for working with categories.

func (*CategoryService) GetCategories

func (s *CategoryService) GetCategories() ([]Category, error)

GetCategories lists categories for current user.

type Client

type Client struct {

	// base url for all requests
	BaseURL *url.URL

	// user agent header
	UserAgent string

	// services
	Categories   *CategoryService
	Accounts     *AccountService
	Transactions *TransactionService
	// contains filtered or unexported fields
}

Client represents savey client.

func NewClient

func NewClient(httpClient *http.Client) (*Client, error)

NewClient creates new Savey client.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do performs HTTP request and returns HTTP response.

func (*Client) Get

func (c *Client) Get(url string) (*http.Request, error)

Get creates a new GET HTTP request.

func (*Client) Login

func (c *Client) Login(username string, password string) error

Login logs in user with provided username and password.

func (*Client) Logout

func (c *Client) Logout() error

Logout logs out currently logged user.

func (*Client) NewRequest

func (c *Client) NewRequest(method string, endpointURL string, body *url.Values) (*http.Request, error)

NewRequest creates a new HTTP request.

func (*Client) Post

func (c *Client) Post(url string, body *url.Values) (*http.Request, error)

Post creates a new POST HTTP request.

type Transaction

type Transaction struct {
	ID         int64     `json:"id"`
	Title      string    `json:"title"`
	Date       time.Time `json:"date"`
	CategoryID int64     `json:"category_id"`
	AccountID  int64     `json:"account_id"`
	Value      float64   `json:"value"`
	Currency   string    `json:"currency"`
	Expense    bool      `json:"expense"`
}

Transaction represents payment transaction.

type TransactionService

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

TransactionService provides methods for working with payment transactions.

func (*TransactionService) GetAccountTransactions

func (s *TransactionService) GetAccountTransactions(acc Account) ([]Transaction, error)

GetAccountTransactions lists transactions for given account.

func (*TransactionService) GetTransactions

func (s *TransactionService) GetTransactions(accounts []Account) ([]Transaction, error)

GetTransactions lists transactions for given accounts.

Jump to

Keyboard shortcuts

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