1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-12-26 06:53:21 -05:00

Improve some request/response documentation

This commit is contained in:
Aaron Lindsay 2017-03-31 15:29:57 -04:00
parent e755650521
commit d07455d797
2 changed files with 17 additions and 1 deletions

View File

@ -7,6 +7,11 @@ import (
"time"
)
// Request is the top-level object marshalled and sent to OFX servers. It is
// constructed by appending one or more request objects to the message set they
// correspond to (i.e. appending StatementRequest to Request.Bank to get a bank
// statemement). If a *Request object is appended to the wrong message set, an
// error will be returned when Marshal() is called on this Request.
type Request struct {
URL string
Version string // OFX version string, overwritten in Client.Request()

View File

@ -10,6 +10,9 @@ import (
"strings"
)
// Response is the top-level object returned from a parsed OFX response file.
// It can be inspected by using type assertions or switches on the message set
// you're interested in.
type Response struct {
Version string // String for OFX header, defaults to 203
Signon SignonResponse //<SIGNONMSGSETV1>
@ -181,6 +184,10 @@ func guessVersion(r *bufio.Reader) (bool, error) {
}
}
// A map of message set tags to a map of transaction wrapper tags to the
// reflect.Type of the struct for that transaction type. Used when decoding
// Responses. Newly-implemented response transaction types *must* be added to
// this map in order to be unmarshalled.
var responseTypes = map[string]map[string]reflect.Type{
SignupRs.String(): map[string]reflect.Type{
(&AcctInfoResponse{}).Name(): reflect.TypeOf(AcctInfoResponse{})},
@ -220,7 +227,11 @@ func decodeMessageSet(d *xml.Decoder, start xml.StartElement, msgs *[]Message) e
} else if startElement, ok := tok.(xml.StartElement); ok {
responseType, ok := setTypes[startElement.Name.Local]
if !ok {
return errors.New("Unsupported response transaction for " + start.Name.Local + ": " + startElement.Name.Local)
// If you are a developer and received this message after you
// thought you added a new transaction type, make sure you
// added it to the responseTypes map above
return errors.New("Unsupported response transaction for " +
start.Name.Local + ": " + startElement.Name.Local)
}
response := reflect.New(responseType).Interface()
responseMessage := response.(Message)