Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd/api): adding number of transactions to be displayed as optional parameter #12

Merged
merged 1 commit into from
Sep 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,17 @@ func (auth *Client) GetContacts(retType string) (string, *Contacts) {
return "", contacts
}

func (auth *Client) GetLastTransactions() (*Transactions, error) {
return auth.GetTransactions(TimeStamp{}, TimeStamp{})
func (auth *Client) GetLastTransactions(limit string) (*Transactions, error) {
return auth.GetTransactions(TimeStamp{}, TimeStamp{}, limit)
}

// Get transactions for the given time window.
// Use the zero values for the time stamps if no restrictions are
// desired (use the defaults on the server)
func (auth *Client) GetTransactions(from, to TimeStamp) (*Transactions, error) {
params := map[string]string{}
func (auth *Client) GetTransactions(from, to TimeStamp, limit string) (*Transactions, error) {
params := map[string]string{
"limit": limit,
}
//Filter is applied only if both values are set
if !from.IsZero() && !to.IsZero() {
params["from"] = fmt.Sprint(from.AsMillis())
Expand Down
Binary file added cmd/n26/n26
Binary file not shown.
8 changes: 5 additions & 3 deletions cmd/n26/n26.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const (
appVersion = "1.4.3"
appVersion = "1.4.4"
)

func check(e error) {
Expand Down Expand Up @@ -231,6 +231,7 @@ func main() {
Usage: "list your past transactions. Supports CSV output",
ArgsUsage: "[csv|json|table]",
Flags: []cli.Flag{
cli.StringFlag{Name: "limit", Value: "10", Usage: "retrieve last N transactions. Default to 10."},
cli.StringFlag{Name: "from", Usage: "retrieve transactions from this date. " +
"Also 'to' flag needs to be set. Calendar date in the format yyyy-mm-dd. E.g. 2018-03-01"},
cli.StringFlag{Name: "to", Usage: "retrieve transactions until this date. " +
Expand All @@ -242,16 +243,17 @@ func main() {
check(err)
writer, err := getTransactionWriter(c.Args().First())
check(err)
limit := c.String("limit")
var transactions *n26.Transactions
if c.IsSet("from") && c.IsSet("to") {
var from, to n26.TimeStamp
from.Time, err = time.Parse(dateFormat, c.String("from"))
check(err)
to.Time, err = time.Parse(dateFormat, c.String("to"))
check(err)
transactions, err = API.GetTransactions(from, to)
transactions, err = API.GetTransactions(from, to, limit)
} else {
transactions, err = API.GetLastTransactions()
transactions, err = API.GetLastTransactions(limit)
}
check(err)

Expand Down