Skip to content

Commit

Permalink
Merge pull request #12 from guitmz/adding-requested-transactions-para…
Browse files Browse the repository at this point in the history
…meter

feat(cmd/api): adding number of transactions to be displayed as optional parameter
  • Loading branch information
guitmz authored Sep 9, 2018
2 parents f517501 + 9debb33 commit 431eaae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
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

0 comments on commit 431eaae

Please sign in to comment.