From 9bd9c01962d88575a060d4dac4427ef7762ed6e4 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Mon, 17 Apr 2017 11:11:46 -0400 Subject: [PATCH] Add OFX version to Valid() calls This allows for future differentiation based on different requirements of different versions of the OFX specification. --- bank.go | 4 ++-- common.go | 6 +++--- creditcard.go | 4 ++-- invstmt.go | 4 ++-- profile.go | 4 ++-- request.go | 8 ++++---- response.go | 2 +- seclist.go | 6 +++--- signon.go | 4 ++-- signup.go | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/bank.go b/bank.go index fb611ae..1bc8766 100644 --- a/bank.go +++ b/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 } diff --git a/common.go b/common.go index 48dfe9c..1831618 100644 --- a/common.go +++ b/common.go @@ -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 diff --git a/creditcard.go b/creditcard.go index ae91615..066bafb 100644 --- a/creditcard.go +++ b/creditcard.go @@ -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 } diff --git a/invstmt.go b/invstmt.go index 40bef46..f258422 100644 --- a/invstmt.go +++ b/invstmt.go @@ -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 } diff --git a/profile.go b/profile.go index 03ff37e..086cff1 100644 --- a/profile.go +++ b/profile.go @@ -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 } diff --git a/request.go b/request.go index ffbdcd7..db26f51 100644 --- a/request.go +++ b/request.go @@ -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 } } diff --git a/response.go b/response.go index d2afa86..429589e 100644 --- a/response.go +++ b/response.go @@ -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 } diff --git a/seclist.go b/seclist.go index f89c5dd..fe2b505 100644 --- a/seclist.go +++ b/seclist.go @@ -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 } diff --git a/signon.go b/signon.go index f9e7709..a885b67 100644 --- a/signon.go +++ b/signon.go @@ -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) } diff --git a/signup.go b/signup.go index 0de54c0..9bfa754 100644 --- a/signup.go +++ b/signup.go @@ -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 }