Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #31 from engvik/1.6.0
Browse files Browse the repository at this point in the history
1.6.0
  • Loading branch information
engvik authored May 8, 2021
2 parents be74fb7 + ab253f1 commit f3da9ef
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
default: build

APP=sbanken
VERSION=1.5.0
VERSION=1.6.0

## build: build binaries and generate checksums
build:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ USAGE:
main [global options] command [command options] [arguments...]

VERSION:
1.5.0
1.6.0

COMMANDS:
accounts, a list and read accounts
Expand Down
2 changes: 1 addition & 1 deletion cmd/sbanken/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// VERSION is the current sbanken-cli version
const VERSION string = "1.5.0"
const VERSION string = "1.6.0"

func main() {
ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/engvik/sbanken-cli
go 1.15

require (
github.com/engvik/sbanken-go v1.1.0
github.com/engvik/sbanken-go v1.2.0
github.com/jedib0t/go-pretty/v6 v6.0.5
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/engvik/sbanken-go v1.1.0 h1:wh/aNyjm7PoUk4nMVM6PmacYA1/RynaygVjJ5OnyHFw=
github.com/engvik/sbanken-go v1.1.0/go.mod h1:EvtkZuNhNnVGwiuyIz4u59h3mtKB9Uic36spBs/UHxc=
github.com/engvik/sbanken-go v1.2.0 h1:6Ot0uPBZheUTT9ubKaBvPh5uz/CcqeYKXufl5sGTtjI=
github.com/engvik/sbanken-go v1.2.0/go.mod h1:EvtkZuNhNnVGwiuyIz4u59h3mtKB9Uic36spBs/UHxc=
github.com/jedib0t/go-pretty/v6 v6.0.5 h1:oOo0/jSb3NEYKT6l1hhFXoX2UZnkanMuCE2DVT1mqnE=
github.com/jedib0t/go-pretty/v6 v6.0.5/go.mod h1:MTr6FgcfNdnN5wPVBzJ6mhJeDyiF0yBvS2TMXEV/XSU=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -34,11 +34,9 @@ github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
4 changes: 0 additions & 4 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ func New(ctx context.Context, conn sbankenConn, version string) *cli.App {
if c.String("client-secret") == "" {
return errors.New("client-secret is a required parameter")
}

if c.String("customer-id") == "" {
return errors.New("customer-id is a required parameter")
}
}

if err := conn.ConnectClient(ctx, c, version); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion internal/cli/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func getTransactionsCommand(conn transactions) *cli.Command {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "account id (or name) to list payments from",
Usage: "account id (or name) to list transactions from",
Required: true,
},
&cli.StringFlag{
Expand Down Expand Up @@ -54,6 +54,11 @@ func getTransactionsCommand(conn transactions) *cli.Command {
Usage: "list more transaction details if applicable",
Aliases: []string{"td"},
},
&cli.BoolFlag{
Name: "archived",
Usage: "lists only archived transactions",
Aliases: []string{"a"},
},
},
Action: conn.ListTransactions,
}
Expand Down
5 changes: 3 additions & 2 deletions internal/output/table/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ func (w *Writer) ListAccounts(accounts []sbanken.Account) {
w.setAccountsColors()
}

w.table.AppendHeader(table.Row{"ID", "Type", "Name", "Number", "Balance", "Available", "Credit Limit"})
w.table.AppendHeader(table.Row{"ID", "Type", "Owner Customer ID", "Name", "Number", "Balance", "Available", "Credit Limit"})

var rows []table.Row
var balance float32
var available float32
var creditLimit float32

for _, a := range accounts {
rows = append(rows, table.Row{a.ID, a.Type, a.Name, a.Number, a.Balance, a.Available, a.CreditLimit})
rows = append(rows, table.Row{a.ID, a.Type, a.OwnerCustomerID, a.Name, a.Number, a.Balance, a.Available, a.CreditLimit})
balance += a.Balance
available += a.Available
creditLimit += a.CreditLimit
Expand All @@ -32,6 +32,7 @@ func (w *Writer) ListAccounts(accounts []sbanken.Account) {
func (w *Writer) ReadAccount(account sbanken.Account) {
w.table.AppendRow(table.Row{"ID", account.ID})
w.table.AppendRow(table.Row{"Type", account.Type})
w.table.AppendRow(table.Row{"Owner Customer ID", account.OwnerCustomerID})
w.table.AppendRow(table.Row{"Name", account.Name})
w.table.AppendRow(table.Row{"Number", account.Number})
w.table.AppendRow(table.Row{"Balance", account.Balance})
Expand Down
4 changes: 2 additions & 2 deletions internal/output/table/cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
)

func (w *Writer) ListCards(cards []sbanken.Card) {
w.table.AppendHeader(table.Row{"ID", "Type", "Product Code", "Number", "Account Number", "ExpiryDate", "Status", "Version Number"})
w.table.AppendHeader(table.Row{"ID", "Type", "Product Code", "Customer ID", "Account Owner", "Number", "Account Number", "ExpiryDate", "Status", "Version Number"})

var rows []table.Row

for _, card := range cards {
rows = append(rows, table.Row{card.ID, card.Type, card.ProductCode, card.Number, card.AccountNumber, card.ExpiryDate, card.Status, card.VersionNumber})
rows = append(rows, table.Row{card.ID, card.Type, card.ProductCode, card.CustomerID, card.AccountOwner, card.Number, card.AccountNumber, card.ExpiryDate, card.Status, card.VersionNumber})
}

w.table.AppendRows(rows)
Expand Down
2 changes: 2 additions & 0 deletions internal/output/table/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (w *Writer) ListTransactions(transactions []sbanken.Transaction, detailedOu

w.table.AppendHeader(table.Row{
"Index",
"ID",
"Text",
"Amount",
"Accounting Date",
Expand All @@ -28,6 +29,7 @@ func (w *Writer) ListTransactions(transactions []sbanken.Transaction, detailedOu
for i, tr := range transactions {
rows = append(rows, table.Row{
i,
tr.TransactionID,
tr.Text,
tr.Amount,
tr.AccountingDate,
Expand Down
50 changes: 27 additions & 23 deletions internal/sbanken/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ import (
)

var testAccount = sbanken.Account{
ID: "test-id",
Name: "test-name",
Type: "test-type",
Number: "test-number",
Available: 13.37,
Balance: 13.37,
CreditLimit: 0,
ID: "test-id",
Name: "test-name",
Type: "test-type",
Number: "test-number",
OwnerCustomerID: "test-owner-customer-id",
Available: 13.37,
Balance: 13.37,
CreditLimit: 0,
}

var testListAccountsTable = `+---------+-----------+-----------+-------------+---------+-----------+--------------+
| ID | TYPE | NAME | NUMBER | BALANCE | AVAILABLE | CREDIT LIMIT |
+---------+-----------+-----------+-------------+---------+-----------+--------------+
| test-id | test-type | test-name | test-number | 13.37 | 13.37 | 0 |
+---------+-----------+-----------+-------------+---------+-----------+--------------+
| | | | | 13.37 | 13.37 | 0 |
+---------+-----------+-----------+-------------+---------+-----------+--------------+
var testListAccountsTable = `+---------+-----------+------------------------+-----------+-------------+---------+-----------+--------------+
| ID | TYPE | OWNER CUSTOMER ID | NAME | NUMBER | BALANCE | AVAILABLE | CREDIT LIMIT |
+---------+-----------+------------------------+-----------+-------------+---------+-----------+--------------+
| test-id | test-type | test-owner-customer-id | test-name | test-number | 13.37 | 13.37 | 0 |
+---------+-----------+------------------------+-----------+-------------+---------+-----------+--------------+
| | | | | 13.37 | 13.37 | 0 | |
+---------+-----------+------------------------+-----------+-------------+---------+-----------+--------------+
`

var testListAccountsJSON = `[
Expand All @@ -37,29 +38,32 @@ var testListAccountsJSON = `[
"name": "test-name",
"accountType": "test-type",
"accountNumber": "test-number",
"ownerCustomerId": "test-owner-customer-id",
"available": 13.37,
"balance": 13.37,
"creditLimit": 0
}
]
`

var testReadAccountTable = `+--------------+-------------+
| ID | test-id |
| Type | test-type |
| Name | test-name |
| Number | test-number |
| Balance | 13.37 |
| Available | 13.37 |
| Credit Limit | 0 |
+--------------+-------------+
var testReadAccountTable = `+-------------------+------------------------+
| ID | test-id |
| Type | test-type |
| Owner Customer ID | test-owner-customer-id |
| Name | test-name |
| Number | test-number |
| Balance | 13.37 |
| Available | 13.37 |
| Credit Limit | 0 |
+-------------------+------------------------+
`

var testReadAccountJSON = `{
"accountId": "test-id",
"name": "test-name",
"accountType": "test-type",
"accountNumber": "test-number",
"ownerCustomerId": "test-owner-customer-id",
"available": 13.37,
"balance": 13.37,
"creditLimit": 0
Expand Down
14 changes: 9 additions & 5 deletions internal/sbanken/cards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ var testCard = sbanken.Card{
Type: "test-type",
ProductCode: "test-code",
AccountNumber: "987654321",
AccountOwner: "183654729",
CustomerID: "1337",
VersionNumber: 5,
}

var testListCardsTable = `+-----------+-----------+--------------+-----------+----------------+------------+-------------+----------------+
| ID | TYPE | PRODUCT CODE | NUMBER | ACCOUNT NUMBER | EXPIRYDATE | STATUS | VERSION NUMBER |
+-----------+-----------+--------------+-----------+----------------+------------+-------------+----------------+
| test-card | test-type | test-code | 123456789 | 987654321 | timestamp | test-status | 5 |
+-----------+-----------+--------------+-----------+----------------+------------+-------------+----------------+
var testListCardsTable = `+-----------+-----------+--------------+-------------+---------------+-----------+----------------+------------+-------------+----------------+
| ID | TYPE | PRODUCT CODE | CUSTOMER ID | ACCOUNT OWNER | NUMBER | ACCOUNT NUMBER | EXPIRYDATE | STATUS | VERSION NUMBER |
+-----------+-----------+--------------+-------------+---------------+-----------+----------------+------------+-------------+----------------+
| test-card | test-type | test-code | 1337 | 183654729 | 123456789 | 987654321 | timestamp | test-status | 5 |
+-----------+-----------+--------------+-------------+---------------+-----------+----------------+------------+-------------+----------------+
`

var testListCardsJSON = `[
Expand All @@ -38,6 +40,8 @@ var testListCardsJSON = `[
"cardType": "test-type",
"productCode": "test-code",
"accountNumber": "987654321",
"accountOwner": "183654729",
"customerId": "1337",
"cardVersionNumber": 5
}
]
Expand Down
12 changes: 8 additions & 4 deletions internal/sbanken/customers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var testGetCustomerTable = `+----------------+--------------------------+
| Last Name | test-last |
| Email Address | [email protected] |
| Date of Birth | 2021-01-31T10:05:54.590Z |
| Postal Address | {Tester street 1 } |
| Street Address | {Tester street 1 } |
| Postal Address | Tester street 1 |
| Street Address | Tester street 1 |
| Phone Numbers | |
| | 1 1337133713371337 |
+----------------+--------------------------+
Expand All @@ -51,8 +51,8 @@ var testGetCustomerCustomerIDTable = `+----------------+------------------------
| Last Name | test-last |
| Email Address | [email protected] |
| Date of Birth | 2021-01-31T10:05:54.590Z |
| Postal Address | {Tester street 1 } |
| Street Address | {Tester street 1 } |
| Postal Address | Tester street 1 |
| Street Address | Tester street 1 |
| Phone Numbers | |
| | 1 1337133713371337 |
+----------------+--------------------------+
Expand All @@ -68,6 +68,7 @@ var testGetCustomerJSON = `{
"addressLine1": "Tester street 1",
"addressLine2": "",
"addressLine3": "",
"addressLine4": "",
"country": "",
"zipCode": "",
"city": ""
Expand All @@ -76,6 +77,7 @@ var testGetCustomerJSON = `{
"addressLine1": "Tester street 1",
"addressLine2": "",
"addressLine3": "",
"addressLine4": "",
"country": "",
"zipCode": "",
"city": ""
Expand All @@ -99,6 +101,7 @@ var testGetCustomerCustomerIDJSON = `{
"addressLine1": "Tester street 1",
"addressLine2": "",
"addressLine3": "",
"addressLine4": "",
"country": "",
"zipCode": "",
"city": ""
Expand All @@ -107,6 +110,7 @@ var testGetCustomerCustomerIDJSON = `{
"addressLine1": "Tester street 1",
"addressLine2": "",
"addressLine3": "",
"addressLine4": "",
"country": "",
"zipCode": "",
"city": ""
Expand Down
2 changes: 1 addition & 1 deletion internal/sbanken/sbanken.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type sbankenClient interface {
ReadPayment(context.Context, string, string) (sbanken.Payment, error)
ListStandingOrders(context.Context, string) ([]sbanken.StandingOrder, error)
ListTransactions(context.Context, string, *sbanken.TransactionListQuery) ([]sbanken.Transaction, error)
ListArchivedTransactions(context.Context, string, *sbanken.TransactionListQuery) ([]sbanken.Transaction, error)
Transfer(context.Context, *sbanken.TransferQuery) error
GetCustomer(context.Context) (sbanken.Customer, error)
}
Expand Down Expand Up @@ -76,7 +77,6 @@ func (c *Connection) ConnectClient(ctx context.Context, cliCtx *cli.Context, ver
cfg := &sbanken.Config{
ClientID: cliCtx.String("client-id"),
ClientSecret: cliCtx.String("client-secret"),
CustomerID: cliCtx.String("customer-id"),
UserAgent: fmt.Sprintf("sbanken-cli/%s (github.com/engvik/sbanken-cli)", version),
}

Expand Down
13 changes: 12 additions & 1 deletion internal/sbanken/transactions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sbanken

import (
"context"
"time"

"github.com/engvik/sbanken-go"
Expand All @@ -19,7 +20,9 @@ func (c *Connection) ListTransactions(ctx *cli.Context) error {
return err
}

transactions, err := c.client.ListTransactions(ctx.Context, accountID, q)
archived := ctx.Bool("archived")

transactions, err := c.getTransactions(ctx.Context, accountID, q, archived)
if err != nil {
return err
}
Expand All @@ -33,6 +36,14 @@ func (c *Connection) ListTransactions(ctx *cli.Context) error {
return nil
}

func (c *Connection) getTransactions(ctx context.Context, accountID string, q *sbanken.TransactionListQuery, archived bool) ([]sbanken.Transaction, error) {
if archived {
return c.client.ListArchivedTransactions(ctx, accountID, q)
}

return c.client.ListTransactions(ctx, accountID, q)
}

func parseTransactionListQuery(ctx *cli.Context) (*sbanken.TransactionListQuery, error) {
startDate := ctx.String("start-date")
endDate := ctx.String("end-date")
Expand Down
Loading

0 comments on commit f3da9ef

Please sign in to comment.