1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2025-07-03 12:28: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

@ -811,41 +811,15 @@ type InvStatementResponse struct {
Inv401KBal *Inv401KBal `xml:"INVSTMTRS>INV401KBAL,omitempty"`
}
func (sr InvStatementResponse) Name() string {
func (sr *InvStatementResponse) Name() string {
return "INVSTMTTRNRS"
}
func (sr InvStatementResponse) Valid() (bool, error) {
func (sr *InvStatementResponse) Valid() (bool, error) {
//TODO implement
return true, nil
}
func (sr InvStatementResponse) Type() messageType {
func (sr *InvStatementResponse) Type() messageType {
return InvStmtRs
}
func decodeInvestmentsMessageSet(d *xml.Decoder, start xml.StartElement) ([]Message, error) {
var msgs []Message
for {
tok, err := nextNonWhitespaceToken(d)
if err != nil {
return nil, err
} else if end, ok := tok.(xml.EndElement); ok && end.Name.Local == start.Name.Local {
// If we found the end of our starting element, we're done parsing
return msgs, nil
} else if startElement, ok := tok.(xml.StartElement); ok {
switch startElement.Name.Local {
case "INVSTMTTRNRS":
var info InvStatementResponse
if err := d.DecodeElement(&info, &startElement); err != nil {
return nil, err
}
msgs = append(msgs, Message(info))
default:
return nil, errors.New("Unsupported investments response tag: " + startElement.Name.Local)
}
} else {
return nil, errors.New("Didn't find an opening element")
}
}
}