diff --git a/client.go b/client.go index 4f86aee..3ddeb7c 100644 --- a/client.go +++ b/client.go @@ -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 { diff --git a/request.go b/request.go index 20a9e16..dc6840c 100644 --- a/request.go +++ b/request.go @@ -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