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

Make setting request fields from Client a Request method

This also makes it possible to call this method for testing without
making an HTTP request.
This commit is contained in:
Aaron Lindsay 2017-03-28 20:42:22 -04:00
parent 3091a97b2c
commit 119c01f99b
2 changed files with 16 additions and 8 deletions

View File

@ -4,7 +4,6 @@ import (
"errors"
"io"
"net/http"
"time"
)
type Client struct {
@ -83,13 +82,7 @@ func RawRequest(URL string, r io.Reader) (*http.Response, error) {
// Caveat: The caller is responsible for closing the http Response.Body (see
// the http module's documentation for more information)
func (c *Client) RequestNoParse(r *Request) (*http.Response, error) {
r.Signon.DtClient = Date(time.Now())
// Overwrite fields that the client controls
r.Version = c.OfxVersion()
r.Signon.AppId = c.Id()
r.Signon.AppVer = c.Version()
r.indent = c.IndentRequests()
r.SetClientFields(c)
b, err := r.Marshal()
if err != nil {

View File

@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"github.com/aclindsa/go/src/encoding/xml"
"time"
)
type Request struct {
@ -51,6 +52,20 @@ func marshalMessageSet(e *xml.Encoder, requests []Message, setname string) error
return nil
}
// Overwrite the fields in this Request object controlled by the Client
func (oq *Request) SetClientFields(c *Client) {
oq.Signon.DtClient = Date(time.Now())
// Overwrite fields that the client controls
oq.Version = c.OfxVersion()
oq.Signon.AppId = c.Id()
oq.Signon.AppVer = c.Version()
oq.indent = c.IndentRequests()
}
// Marshal this Request into its SGML/XML representation held in a bytes.Buffer
//
// If error is non-nil, this bytes.Buffer is ready to be sent to an OFX server
func (oq *Request) Marshal() (*bytes.Buffer, error) {
var b bytes.Buffer