seed

package module
v0.0.0-...-3f0a92b Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2017 License: MIT Imports: 9 Imported by: 0

README

Seed-Go

A Go client for the Seed API

GoDoc Build Status Go Report Card

Usage

// to obtain an access token go to https://api.seed.co/v1/public/auth/token in a browser and enter in your seed username/password

accessToken := "1.iap2H-4qQ-WR9sy55555uaytQ.o5A32LYL5-87a_60kcQiX1Lp878GVbx8xfVvTfp5tpc.orsHbAqao-5KfsH8SdglQFltK7Ii8ktL7xo8tls3HAB"

client := seed.New(accessToken)

getTransactionsReq := TransactionsRequest{
	Client: client,
}
// The two options are between getting all transactions or using an iterator for pagination

// All transcations

transactions, err := getTransactionsReq.Get()

// Using an iterator for pagination

iterator := getTransactionsReq.Iterator()

iterator.SetBatchSize(10)

for iterator.HasNext() {
	var transactions []seed.Transaction
	var err error
	if transactions, err = iterator.Next(); err != nil {
		panic(err.Error())
	}
	fmt.Printf("Transactions:\n%v", transactions)
}

// previous will get the previous page of transactions

previousTransactions, err = iterator.Previous()

Documentation

Index

Constants

View Source
const (
	// ApiBase is the base url for the seed api
	ApiBase = "https://api.seed.co/v1/public"
)
View Source
const (
	// MaxBatchSize is the maximum pagination limit for a transaction query
	MaxBatchSize = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Balance

type Balance struct {
	// Checking Account ID specifies the id of the checking account that this balance belongs to
	CheckingAccountID string `json:"checking_account_id"`
	// Total Available refers to the balance that is safely usable
	// this number is calculated in the following way TotalAvailable = Accessible - PendingDebits - ScheduledDebits
	TotalAvailable int64 `json:"total_available"`
	// Settled refers to the total amount of transactions that have settled
	Settled int64 `json:"settled"`
	// PendingCredits refers to credits that are pending
	PendingCredits uint64 `json:"pending_credits"`
	// PendingDebits refers to debits that are pending
	PendingDebits uint64 `json:"pending_debits"`
	// ScheduledDebits refers to debits that are scheduled
	ScheduledDebits uint64 `json:"scheduled_debits"`
	// Accessible refers to the balance is usable
	Accessible int64 `json:"accessible"`
	// Lockbox refers to the amount in the virtual lockbox
	Lockbox uint64 `json:"lockbox"`
}

Balance contains relevant balance amounts for a given checking account

type BalanceRequest

type BalanceRequest struct {
	// Checking Account ID specifies the id of the checking account for the balance in question
	// Must be a uuid that corresponds to a valid checking account
	CheckingAccountID string
	// Client is the seed client
	Client *Client
}

BalanceRequest is a request for fetching a balance for a given checking account

func (*BalanceRequest) Get

func (b *BalanceRequest) Get() (Balance, error)

Get retrieves the balance

type BalanceResponse

type BalanceResponse struct {
	// Errors is a list of errors
	Errors ErrorList `json:"errors"`
	// Results is a slice of Balance objects. The size of this slice is expected to be 1
	Results []Balance `json:"results"`
}

BalanceResponse is the struct that the server response will get unmarshalled into

type Client

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

Client is a seed client that can be used to create different request objects to fetch data

func New

func New(accessToken string) *Client

New creates a new Seed client given an access token

func (*Client) NewBalanceRequest

func (c *Client) NewBalanceRequest() *BalanceRequest

NewBalanceRequest creates a new balance request

func (*Client) SetClientVersion

func (c *Client) SetClientVersion(clientVersion string)

SetClientVersion sets the client version that each request will be made with

type ErrorList

type ErrorList []map[string]string

ErrorList is a list of maps that contain error message, field pairs

func (ErrorList) Error

func (e ErrorList) Error() string

Error returns a comma delineated string of errors

type Pages

type Pages struct {
	// Next is the set of parameters for the next page
	Next PaginationParams `json:"next"`
	// Previous is the set of parameters for the previous page
	Previous PaginationParams `json:"previous"`
}

Pages contains pagination information

type PaginationParams

type PaginationParams struct {
	// Offset is the pagination offset index
	Offset int `json:"offest"`
	// Limit is the pagination limit
	Limit int `json:"limit"`
}

PaginationParams encapsulates the two pagination values, offset and limit

func (PaginationParams) Encode

func (p PaginationParams) Encode() string

Encode encodes offset and limit into a url query string

func (PaginationParams) MarshalJSON

func (p PaginationParams) MarshalJSON() ([]byte, error)

MarshalJSON marshalls pagination params

func (*PaginationParams) UnmarshalJSON

func (p *PaginationParams) UnmarshalJSON(d []byte) error

UnmarshalJSON unmarshalls pagination params

type Transaction

type Transaction struct {
	// Date is the date of the transaction
	Date time.Time `json:"date"`
	// Description is the description of the transaction
	Description string `json:"description"`
	// Amount is the amount of the transaction in cents
	Amount int64 `json:"amount"`
	// Error contains any errors that happened with the transaction
	Error string `json:"error"`
	// Status is either "pending" or "settled"
	Status string `json:"status"`
	// Category is the category of the transaction
	Category string `json:"category"`
}

Transaction contains relevant information about a transaction

type TransactionsIterator

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

TransactionsIterator is an iterator to iterate through pages of transaction results

func (*TransactionsIterator) Next

func (t *TransactionsIterator) Next() ([]Transaction, error)

Next will retrieve the next batch of transactions. It returns a slice of Transactions, and any http errors

func (*TransactionsIterator) Previous

func (t *TransactionsIterator) Previous() ([]Transaction, error)

Previous will retrieve the previous batch of transactions. It returns a slice of Transactions, and any errors that happen

func (*TransactionsIterator) SetBatchSize

func (t *TransactionsIterator) SetBatchSize(n int)

SetBatchSize sets the batch size for paginated results

type TransactionsRequest

type TransactionsRequest struct {
	// CheckingAccountID is a uuid of the checking account for the transaction request
	CheckingAccountID string
	// Status is either "pending" or "settled"
	Status string
	// From is the start date of the date range, inclusive
	From time.Time
	// To is the end date of the date range, exclusive
	To time.Time
	// Client is the seed client that will send the request
	Client *Client
}

TransactionsRequest contains fields for querying transactions

func (*TransactionsRequest) Get

func (t *TransactionsRequest) Get() ([]Transaction, error)

Get retrieves a list of transactions

func (*TransactionsRequest) Iterator

Iterator returns a TransactionIterator

type TransactionsResponse

type TransactionsResponse struct {
	// Errors is a list of errors
	Errors ErrorList `json:"errors"`
	// Results is a slice of transaction objects
	Results []Transaction `json:"results"`
	// Pages contains pagination information
	Pages Pages `json:"pages"`
}

TransactionsResponse is the response object that the server data unmarshalls into

Jump to

Keyboard shortcuts

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