-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrequest.go
65 lines (55 loc) · 1.56 KB
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package intacct
import "encoding/xml"
func NewRequest() Request {
return Request{
Control: RequestControl{
SenderID: "",
SenderPassword: "",
ControlID: "",
UniqueID: true,
DTDVersion: "3.0",
IncludeWhitespace: true,
},
Operation: RequestOperation{
Authentication: RequestAuthentication{},
Content: nil,
},
}
}
type Request struct {
XMLName xml.Name `xml:"request" json:"-"`
Control RequestControl `xml:"control"`
Operation RequestOperation `xml:"operation"`
}
func (r *Request) SetSessionID(sessionID string) {
r.Operation.Authentication.SessionID = sessionID
}
type RequestControl struct {
SenderID string `xml:"senderid"`
SenderPassword CData `xml:"password"`
ControlID string `xml:"controlid"`
UniqueID bool `xml:"uniqueid"`
DTDVersion string `xml:"dtdversion"`
IncludeWhitespace bool `xml:"includewhitespace"`
}
type RequestOperation struct {
Authentication RequestAuthentication `xml:"authentication"`
Content interface{} `xml:"content"`
}
type RequestAuthentication struct {
SessionID string `xml:"sessionid,omitempty"`
Login *RequestLogin `xml:"login,omitempty"`
}
type RequestLogin struct {
UserID string `xml:"userid"`
CompanyID string `xml:"companyid"`
Password string `xml:"password"`
}
type CData string
func (n CData) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return e.EncodeElement(struct {
S string `xml:",innerxml"`
}{
S: "<![CDATA[" + string(n) + "]]>",
}, start)
}