mirror of
https://github.com/aclindsa/ofxgo.git
synced 2024-11-22 11:30:05 -05:00
Improve some request/response documentation
This commit is contained in:
parent
e755650521
commit
d07455d797
@ -7,6 +7,11 @@ import (
|
|||||||
"time"
|
"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 {
|
type Request struct {
|
||||||
URL string
|
URL string
|
||||||
Version string // OFX version string, overwritten in Client.Request()
|
Version string // OFX version string, overwritten in Client.Request()
|
||||||
|
13
response.go
13
response.go
@ -10,6 +10,9 @@ import (
|
|||||||
"strings"
|
"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 {
|
type Response struct {
|
||||||
Version string // String for OFX header, defaults to 203
|
Version string // String for OFX header, defaults to 203
|
||||||
Signon SignonResponse //<SIGNONMSGSETV1>
|
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{
|
var responseTypes = map[string]map[string]reflect.Type{
|
||||||
SignupRs.String(): map[string]reflect.Type{
|
SignupRs.String(): map[string]reflect.Type{
|
||||||
(&AcctInfoResponse{}).Name(): reflect.TypeOf(AcctInfoResponse{})},
|
(&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 {
|
} else if startElement, ok := tok.(xml.StartElement); ok {
|
||||||
responseType, ok := setTypes[startElement.Name.Local]
|
responseType, ok := setTypes[startElement.Name.Local]
|
||||||
if !ok {
|
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()
|
response := reflect.New(responseType).Interface()
|
||||||
responseMessage := response.(Message)
|
responseMessage := response.(Message)
|
||||||
|
Loading…
Reference in New Issue
Block a user