mirror of
https://github.com/aclindsa/ofxgo.git
synced 2025-07-01 11: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:
35
signup.go
35
signup.go
@ -1,7 +1,6 @@
|
||||
package ofxgo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/aclindsa/go/src/encoding/xml"
|
||||
)
|
||||
@ -120,41 +119,15 @@ type AcctInfoResponse struct {
|
||||
AcctInfo []AcctInfo `xml:"ACCTINFORS>ACCTINFO,omitempty"`
|
||||
}
|
||||
|
||||
func (air AcctInfoResponse) Name() string {
|
||||
return "ACCTINFORS"
|
||||
func (air *AcctInfoResponse) Name() string {
|
||||
return "ACCTINFOTRNRS"
|
||||
}
|
||||
|
||||
func (air AcctInfoResponse) Valid() (bool, error) {
|
||||
func (air *AcctInfoResponse) Valid() (bool, error) {
|
||||
//TODO implement
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (air AcctInfoResponse) Type() messageType {
|
||||
func (air *AcctInfoResponse) Type() messageType {
|
||||
return SignupRs
|
||||
}
|
||||
|
||||
func decodeSignupMessageSet(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 "ACCTINFOTRNRS":
|
||||
var info AcctInfoResponse
|
||||
if err := d.DecodeElement(&info, &startElement); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
msgs = append(msgs, Message(info))
|
||||
default:
|
||||
return nil, errors.New("Unsupported signup response tag: " + startElement.Name.Local)
|
||||
}
|
||||
} else {
|
||||
return nil, errors.New("Didn't find an opening element")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user