mirror of
https://github.com/aclindsa/ofxgo.git
synced 2024-11-22 03:30:04 -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:
parent
3091a97b2c
commit
119c01f99b
@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
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
|
// Caveat: The caller is responsible for closing the http Response.Body (see
|
||||||
// the http module's documentation for more information)
|
// the http module's documentation for more information)
|
||||||
func (c *Client) RequestNoParse(r *Request) (*http.Response, error) {
|
func (c *Client) RequestNoParse(r *Request) (*http.Response, error) {
|
||||||
r.Signon.DtClient = Date(time.Now())
|
r.SetClientFields(c)
|
||||||
|
|
||||||
// Overwrite fields that the client controls
|
|
||||||
r.Version = c.OfxVersion()
|
|
||||||
r.Signon.AppId = c.Id()
|
|
||||||
r.Signon.AppVer = c.Version()
|
|
||||||
r.indent = c.IndentRequests()
|
|
||||||
|
|
||||||
b, err := r.Marshal()
|
b, err := r.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
15
request.go
15
request.go
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/aclindsa/go/src/encoding/xml"
|
"github.com/aclindsa/go/src/encoding/xml"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
@ -51,6 +52,20 @@ func marshalMessageSet(e *xml.Encoder, requests []Message, setname string) error
|
|||||||
return nil
|
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) {
|
func (oq *Request) Marshal() (*bytes.Buffer, error) {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user