ziggy

package module
v0.0.0-...-5f31d2f Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: MIT Imports: 9 Imported by: 0

README

Ziggy

Unofficial Go client library for the Investec OpenAPI

Build Status Go Report Card GoDoc License

Installation

To install ziggy, use go get:

go get github.com/nickcorin/ziggy

Import the ziggy package into your code:

package main

import "github.com/nickcorin/ziggy"

func main() {
	client := ziggy.NewClient("user", "s3cr3t")
}

Usage

Creating a simple client.
client := ziggy.NewClient("user", "s3cr3t")
Configuring the client.
// You can chain configuration functions.
client := ziggy.NewClient("user", "s3cr3t").SetToken("mytoken")

// ...or you can configure it later.
client.SetProxy("https://proxy.ziggy.com")
Obtaining an access token.
token, err := client.GetAccessToken(context.Background(), ziggy.TokenScopeAccounts)
if err != nil {
	log.Fatal(err)
}
Fetching a list of your accounts.
accounts, err := z.GetAccounts(context.Background())
if err != nil {
	log.Fatal(err)
}
...and then fetching an account's balance.
balance, err := z.GetBalance(context.Background(), accounts[0].ID)
if err != nil {
	log.Fatal(err)
}

Contributing

Please feel free to submit issues, fork the repositoy and send pull requests!

License

This project is licensed under the terms of the MIT license.

Documentation

Index

Constants

View Source
const (
	TransactionTypeCredit = "CREDIT"
	TransactionTypeDebit  = "DEBIT"
)
View Source
const (
	TransactionStatusPosted = "POSTED"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Token     string     `json:"access_token"`
	Type      TokenType  `json:"token_type"`
	ExpiresIn int64      `json:"expires_in"`
	Scope     TokenScope `json:"scope"`
	// contains filtered or unexported fields
}

AccessToken contains a temporary authorization key.

func (*AccessToken) IsExpired

func (token *AccessToken) IsExpired() bool

IsExpired returns whether the token has expired.

type Account

type Account struct {
	ID        string `json:"accountId"`
	Name      string `json:"accountName"`
	Number    string `json:"accountNumber"`
	Product   string `json:"productName"`
	Reference string `json:"referenceName"`
}

type AccountResponse

type AccountResponse struct {
	Data struct {
		Accounts []Account `json:"accounts"`
	} `json:"data"`

	Links struct {
		Self string `json:"self"`
	} `json:"links"`

	Metadata struct {
		TotalPages int64 `json:"totalPages"`
	} `json:"meta"`
}

AccountResponse describes the response data returned for retrieving a list of accounts.

type Balance

type Balance struct {
	AccountID string  `json:"accountId"`
	Available float64 `json:"availableBalance"`
	Currency  string  `json:"currency"`
	Current   float64 `json:"currentBalance"`
}

type BalanceResponse

type BalanceResponse struct {
	Data struct {
		Balance
	} `json:"data"`

	Links struct {
		Self string `json:"self"`
	} `json:"links"`

	Metadata struct {
		TotalPages int64 `json:"totalPages"`
	} `json:"meta"`
}

BalanceResponse describes the response data returned for retrieving an account's balance.

type Client

type Client struct {
	ClientID     string
	ClientSecret string
	// contains filtered or unexported fields
}

Client defines a stateful REST client wrapper for the Investec Open API.

func NewClient

func NewClient(clientID, clientSecret string) *Client

New returns a Client configured with opts.

func NewClientForTesting

func NewClientForTesting(_ *testing.T, baseURL string) *Client

NewClientForTesting returns a Ziggy client with a custom baseURL.

func (*Client) GetAccessToken

func (c *Client) GetAccessToken(ctx context.Context, scope TokenScope) (
	*AccessToken, error)

GetAccessToken obtains an access token.

func (*Client) GetAccountBalance

func (c *Client) GetAccountBalance(ctx context.Context, accountID string) (
	*Balance, error)

GetAccountBalance obtains a specified account's balance.

func (*Client) GetAccountTransactions

func (c *Client) GetAccountTransactions(ctx context.Context,
	req *TransactionsRequest) (*TransactionsResponse, error)

GetAccountTransactions obtains a specified account's transactions.

func (*Client) GetAccounts

func (c *Client) GetAccounts(ctx context.Context) ([]Account, error)

GetAccounts obtains a list of accounts.

func (*Client) SetAccessToken

func (c *Client) SetAccessToken(token *AccessToken) *Client

func (*Client) SetProxy

func (c *Client) SetProxy(u string) *Client

SetProxy sets the proxy URL for the Ziggy client.

func (*Client) SetToken

func (c *Client) SetToken(token *AccessToken) *Client

SetToken sets a temporary authorization token on the Ziggy client.

type TokenScope

type TokenScope string

TokenScope describes the access scope of a token.

const (
	TokenScopeAccounts TokenScope = "accounts"
)

type TokenType

type TokenType string

TokenType describes the kind of token.

const (
	TokenTypeBearer TokenType = "Bearer"
)

type Transaction

type Transaction struct {
	AccountID       string            `json:"accountId"`
	Type            TransactionType   `json:"type"`
	Status          TransactionStatus `json:"status"`
	Description     string            `json:"description"`
	CardNumber      string            `json:"cardNumber"`
	PostingDate     time.Time         `json:"postingDate"`
	ValueDate       time.Time         `json:"valueDate"`
	ActionDate      time.Time         `json:"actionDate"`
	TransactionDate time.Time         `json:"transactionDate"`
	Amount          float64           `json:"amount"`
}

Transaction describes some activity which has occurred on an account.

func (*Transaction) UnmarshalJSON

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

UnmarshalJSON satisfies the json.Unmarshaler interface.

type TransactionStatus

type TransactionStatus string

TransactionStatus describes the current state of a transaction.

type TransactionType

type TransactionType string

TransactionType describes the kind of the transaction.

type TransactionsRequest

type TransactionsRequest struct {
	AccountID string `json:"-"`

	// Optional.
	StartDate time.Time `json:"fromDate,omitempty"`

	// Optional.
	EndDate time.Time `json:"toDate,omitempty"`
}

TransactionRequest describes the request parameters available for retrieving account transactions. All parameters are requires unless specified.

type TransactionsResponse

type TransactionsResponse struct {
	Data struct {
		Transactions []Transaction `json:"transactions"`
	} `json:"data"`

	Links struct {
		Self string `json:"self"`
	} `json:"links"`

	Metadata struct {
		TotalPages int64 `json:"totalPages"`
	} `json:"meta"`
}

TransactionsResponse describes the response data returned for retrieving account transactions.

Directories

Path Synopsis
cli
cmd

Jump to

Keyboard shortcuts

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