mirror of
https://github.com/aclindsa/ofxgo.git
synced 2024-12-26 06:53:21 -05:00
Add OFX version to Valid() calls
This allows for future differentiation based on different requirements of different versions of the OFX specification.
This commit is contained in:
parent
0eba6741f2
commit
9bd9c01962
4
bank.go
4
bank.go
@ -29,7 +29,7 @@ func (r *StatementRequest) Name() string {
|
||||
|
||||
// Valid returns (true, nil) if this struct would be valid OFX if marshalled
|
||||
// into XML/SGML
|
||||
func (r *StatementRequest) Valid() (bool, error) {
|
||||
func (r *StatementRequest) Valid(version ofxVersion) (bool, error) {
|
||||
// TODO implement
|
||||
return true, nil
|
||||
}
|
||||
@ -181,7 +181,7 @@ func (sr *StatementResponse) Name() string {
|
||||
}
|
||||
|
||||
// Valid returns (true, nil) if this struct was valid OFX when unmarshalled
|
||||
func (sr *StatementResponse) Valid() (bool, error) {
|
||||
func (sr *StatementResponse) Valid(version ofxVersion) (bool, error) {
|
||||
//TODO implement
|
||||
return true, nil
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ import (
|
||||
// Message represents an OFX message in a message set. it is used to ease
|
||||
// marshalling and unmarshalling.
|
||||
type Message interface {
|
||||
Name() string // The name of the OFX transaction wrapper element this represents
|
||||
Valid() (bool, error) // Called before a Message is marshaled and after it's unmarshaled to ensure the request or response is valid
|
||||
Type() messageType // The message set this message belongs to
|
||||
Name() string // The name of the OFX transaction wrapper element this represents
|
||||
Valid(version ofxVersion) (bool, error) // Called before a Message is marshaled and after it's unmarshaled to ensure the request or response is valid
|
||||
Type() messageType // The message set this message belongs to
|
||||
}
|
||||
|
||||
type messageType uint
|
||||
|
@ -28,7 +28,7 @@ func (r *CCStatementRequest) Name() string {
|
||||
|
||||
// Valid returns (true, nil) if this struct would be valid OFX if marshalled
|
||||
// into XML/SGML
|
||||
func (r *CCStatementRequest) Valid() (bool, error) {
|
||||
func (r *CCStatementRequest) Valid(version ofxVersion) (bool, error) {
|
||||
// TODO implement
|
||||
return true, nil
|
||||
}
|
||||
@ -73,7 +73,7 @@ func (sr *CCStatementResponse) Name() string {
|
||||
}
|
||||
|
||||
// Valid returns (true, nil) if this struct was valid OFX when unmarshalled
|
||||
func (sr *CCStatementResponse) Valid() (bool, error) {
|
||||
func (sr *CCStatementResponse) Valid(version ofxVersion) (bool, error) {
|
||||
//TODO implement
|
||||
return true, nil
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func (r *InvStatementRequest) Name() string {
|
||||
|
||||
// Valid returns (true, nil) if this struct would be valid OFX if marshalled
|
||||
// into XML/SGML
|
||||
func (r *InvStatementRequest) Valid() (bool, error) {
|
||||
func (r *InvStatementRequest) Valid(version ofxVersion) (bool, error) {
|
||||
// TODO implement
|
||||
return true, nil
|
||||
}
|
||||
@ -1180,7 +1180,7 @@ func (sr *InvStatementResponse) Name() string {
|
||||
}
|
||||
|
||||
// Valid returns (true, nil) if this struct was valid OFX when unmarshalled
|
||||
func (sr *InvStatementResponse) Valid() (bool, error) {
|
||||
func (sr *InvStatementResponse) Valid(version ofxVersion) (bool, error) {
|
||||
//TODO implement
|
||||
return true, nil
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func (r *ProfileRequest) Name() string {
|
||||
|
||||
// Valid returns (true, nil) if this struct would be valid OFX if marshalled
|
||||
// into XML/SGML
|
||||
func (r *ProfileRequest) Valid() (bool, error) {
|
||||
func (r *ProfileRequest) Valid(version ofxVersion) (bool, error) {
|
||||
// TODO implement
|
||||
r.ClientRouting = "NONE"
|
||||
return true, nil
|
||||
@ -158,7 +158,7 @@ func (pr *ProfileResponse) Name() string {
|
||||
}
|
||||
|
||||
// Valid returns (true, nil) if this struct was valid OFX when unmarshalled
|
||||
func (pr *ProfileResponse) Valid() (bool, error) {
|
||||
func (pr *ProfileResponse) Valid(version ofxVersion) (bool, error) {
|
||||
//TODO implement
|
||||
return true, nil
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ type Request struct {
|
||||
indent bool // Whether to indent the marshaled XML
|
||||
}
|
||||
|
||||
func marshalMessageSet(e *xml.Encoder, requests []Message, set messageType) error {
|
||||
func marshalMessageSet(e *xml.Encoder, requests []Message, set messageType, version ofxVersion) error {
|
||||
if len(requests) > 0 {
|
||||
messageSetElement := xml.StartElement{Name: xml.Name{Local: set.String()}}
|
||||
if err := e.EncodeToken(messageSetElement); err != nil {
|
||||
@ -46,7 +46,7 @@ func marshalMessageSet(e *xml.Encoder, requests []Message, set messageType) erro
|
||||
if request.Type() != set {
|
||||
return errors.New("Expected " + set.String() + " message , found " + request.Type().String())
|
||||
}
|
||||
if ok, err := request.Valid(); !ok {
|
||||
if ok, err := request.Valid(version); !ok {
|
||||
return err
|
||||
}
|
||||
if err := e.Encode(request); err != nil {
|
||||
@ -111,7 +111,7 @@ NEWFILEUID:NONE
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ok, err := oq.Signon.Valid(); !ok {
|
||||
if ok, err := oq.Signon.Valid(oq.Version); !ok {
|
||||
return nil, err
|
||||
}
|
||||
signonMsgSet := xml.StartElement{Name: xml.Name{Local: SignonRq.String()}}
|
||||
@ -145,7 +145,7 @@ NEWFILEUID:NONE
|
||||
{oq.Image, ImageRq},
|
||||
}
|
||||
for _, set := range messageSets {
|
||||
if err := marshalMessageSet(encoder, set.Messages, set.Type); err != nil {
|
||||
if err := marshalMessageSet(encoder, set.Messages, set.Type, oq.Version); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ func ParseResponse(reader io.Reader) (*Response, error) {
|
||||
} else if signonEnd, ok := tok.(xml.EndElement); !ok || signonEnd.Name.Local != SignonRs.String() {
|
||||
return nil, errors.New("Missing closing SIGNONMSGSRSV1 xml element")
|
||||
}
|
||||
if ok, err := or.Signon.Valid(); !ok {
|
||||
if ok, err := or.Signon.Valid(or.Version); !ok {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ func (r *SecListRequest) Name() string {
|
||||
|
||||
// Valid returns (true, nil) if this struct would be valid OFX if marshalled
|
||||
// into XML/SGML
|
||||
func (r *SecListRequest) Valid() (bool, error) {
|
||||
func (r *SecListRequest) Valid(version ofxVersion) (bool, error) {
|
||||
// TODO implement
|
||||
return true, nil
|
||||
}
|
||||
@ -73,7 +73,7 @@ func (r *SecListResponse) Name() string {
|
||||
}
|
||||
|
||||
// Valid returns (true, nil) if this struct was valid OFX when unmarshalled
|
||||
func (r *SecListResponse) Valid() (bool, error) {
|
||||
func (r *SecListResponse) Valid(version ofxVersion) (bool, error) {
|
||||
// TODO implement
|
||||
return true, nil
|
||||
}
|
||||
@ -224,7 +224,7 @@ func (r *SecurityList) Name() string {
|
||||
}
|
||||
|
||||
// Valid returns (true, nil) if this struct was valid OFX when unmarshalled
|
||||
func (r *SecurityList) Valid() (bool, error) {
|
||||
func (r *SecurityList) Valid(version ofxVersion) (bool, error) {
|
||||
// TODO implement
|
||||
return true, nil
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func (r *SignonRequest) Name() string {
|
||||
|
||||
// Valid returns (true, nil) if this struct would be valid OFX if marshalled
|
||||
// into XML/SGML
|
||||
func (r *SignonRequest) Valid() (bool, error) {
|
||||
func (r *SignonRequest) Valid(version ofxVersion) (bool, error) {
|
||||
if len(r.UserID) < 1 || len(r.UserID) > 32 {
|
||||
return false, errors.New("SONRQ>USERID invalid length")
|
||||
}
|
||||
@ -79,7 +79,7 @@ func (r *SignonResponse) Name() string {
|
||||
}
|
||||
|
||||
// Valid returns (true, nil) if this struct was valid OFX when unmarshalled
|
||||
func (r *SignonResponse) Valid() (bool, error) {
|
||||
func (r *SignonResponse) Valid(version ofxVersion) (bool, error) {
|
||||
if len(r.Language) != 3 {
|
||||
return false, fmt.Errorf("SONRS>LANGUAGE invalid length: \"%s\"", r.Language)
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func (r *AcctInfoRequest) Name() string {
|
||||
|
||||
// Valid returns (true, nil) if this struct would be valid OFX if marshalled
|
||||
// into XML/SGML
|
||||
func (r *AcctInfoRequest) Valid() (bool, error) {
|
||||
func (r *AcctInfoRequest) Valid(version ofxVersion) (bool, error) {
|
||||
// TODO implement
|
||||
return true, nil
|
||||
}
|
||||
@ -148,7 +148,7 @@ func (air *AcctInfoResponse) Name() string {
|
||||
}
|
||||
|
||||
// Valid returns (true, nil) if this struct was valid OFX when unmarshalled
|
||||
func (air *AcctInfoResponse) Valid() (bool, error) {
|
||||
func (air *AcctInfoResponse) Valid(version ofxVersion) (bool, error) {
|
||||
//TODO implement
|
||||
return true, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user