1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2025-06-13 21:48:38 -04:00

Generalize response parsing code

This removes the many decodeXXXMessageSet() functions and replaces them
with a large map and a single generic decodeMessageSet() function. Also
change Responses to satisfy the Message interface as pointer types
(instead of the raw types), add the full set of top-level message sets
(though most of them still lack any message-parsing ability), adjust the
message set names to more closely mirror their OFX names, and fixup
tests and the command-line client to match the above changes.
This commit is contained in:
2017-03-31 11:54:43 -04:00
parent d822179446
commit f185d78d29
18 changed files with 171 additions and 301 deletions

View File

@ -55,7 +55,7 @@ func download() {
},
Include: true,
}
query.Banking = append(query.Banking, &statementRequest)
query.Bank = append(query.Bank, &statementRequest)
response, err := client.RequestNoParse(query)
if err != nil {

View File

@ -40,7 +40,7 @@ func bankTransactions() {
},
Include: true,
}
query.Banking = append(query.Banking, &statementRequest)
query.Bank = append(query.Bank, &statementRequest)
response, err := client.Request(query)
if err != nil {
@ -54,12 +54,12 @@ func bankTransactions() {
os.Exit(1)
}
if len(response.Banking) < 1 {
if len(response.Bank) < 1 {
fmt.Println("No banking messages received")
return
}
if stmt, ok := response.Banking[0].(ofxgo.StatementResponse); ok {
if stmt, ok := response.Bank[0].(*ofxgo.StatementResponse); ok {
fmt.Printf("Balance: %s %s (as of %s)\n", stmt.BalAmt, stmt.CurDef, stmt.DtAsOf)
fmt.Println("Transactions:")
for _, tran := range stmt.BankTranList.Transactions {

View File

@ -49,7 +49,7 @@ func ccDownload() {
},
Include: true,
}
query.CreditCards = append(query.CreditCards, &statementRequest)
query.CreditCard = append(query.CreditCard, &statementRequest)
response, err := client.RequestNoParse(query)

View File

@ -36,7 +36,7 @@ func ccTransactions() {
},
Include: true,
}
query.CreditCards = append(query.CreditCards, &statementRequest)
query.CreditCard = append(query.CreditCard, &statementRequest)
response, err := client.Request(query)
if err != nil {
@ -50,12 +50,12 @@ func ccTransactions() {
os.Exit(1)
}
if len(response.CreditCards) < 1 {
if len(response.CreditCard) < 1 {
fmt.Println("No banking messages received")
return
}
if stmt, ok := response.CreditCards[0].(ofxgo.CCStatementResponse); ok {
if stmt, ok := response.CreditCard[0].(*ofxgo.CCStatementResponse); ok {
fmt.Printf("Balance: %s %s (as of %s)\n", stmt.BalAmt, stmt.CurDef, stmt.DtAsOf)
fmt.Println("Transactions:")
for _, tran := range stmt.BankTranList.Transactions {

View File

@ -54,7 +54,7 @@ func getAccounts() {
fmt.Printf("\nFound the following accounts:\n\n")
if acctinfo, ok := response.Signup[0].(ofxgo.AcctInfoResponse); ok {
if acctinfo, ok := response.Signup[0].(*ofxgo.AcctInfoResponse); ok {
for _, acct := range acctinfo.AcctInfo {
if acct.BankAcctInfo != nil {
fmt.Printf("Bank Account:\n\tBankId: \"%s\"\n\tAcctId: \"%s\"\n\tAcctType: %s\n", acct.BankAcctInfo.BankAcctFrom.BankId, acct.BankAcctInfo.BankAcctFrom.AcctId, acct.BankAcctInfo.BankAcctFrom.AcctType)

View File

@ -58,7 +58,7 @@ func invDownload() {
Include401K: true,
Include401KBal: true,
}
query.Investments = append(query.Investments, &statementRequest)
query.InvStmt = append(query.InvStmt, &statementRequest)
response, err := client.RequestNoParse(query)

View File

@ -44,7 +44,7 @@ func invTransactions() {
Include401K: true,
Include401KBal: true,
}
query.Investments = append(query.Investments, &statementRequest)
query.InvStmt = append(query.InvStmt, &statementRequest)
response, err := client.Request(query)
if err != nil {
@ -59,12 +59,12 @@ func invTransactions() {
os.Exit(1)
}
if len(response.Investments) < 1 {
if len(response.InvStmt) < 1 {
fmt.Println("No investment messages received")
return
}
if stmt, ok := response.Investments[0].(ofxgo.InvStatementResponse); ok {
if stmt, ok := response.InvStmt[0].(*ofxgo.InvStatementResponse); ok {
availCash := big.Rat(stmt.InvBal.AvailCash)
if availCash.IsInt() && availCash.Num().Int64() != 0 {
fmt.Printf("Balance: %s %s (as of %s)\n", stmt.InvBal.AvailCash, stmt.CurDef, stmt.DtAsOf)