-
Notifications
You must be signed in to change notification settings - Fork 1
/
envelope.go
123 lines (102 loc) · 5.14 KB
/
envelope.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package netsuite
import (
"encoding/xml"
"github.com/cydev/zero"
"github.com/omniboost/go-netsuite-soap/omitempty"
)
type RequestEnvelope struct {
XMLName xml.Name
Header Header `xml:"env:Header"`
Body Body `xml:"env:Body"`
}
func NewRequestEnvelope() RequestEnvelope {
return RequestEnvelope{
Header: NewHeader(),
}
}
type ResponseEnvelope struct {
XMLName xml.Name
Header Header `xml:"Header"`
Body Body `xml:"Body"`
}
func (env RequestEnvelope) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
start.Name = xml.Name{Local: "env:Envelope"}
namespaces := []xml.Attr{
{Name: xml.Name{Space: "", Local: "xmlns:xsd"}, Value: "http://www.w3.org/2001/XMLSchema"},
{Name: xml.Name{Space: "", Local: "xmlns:xsi"}, Value: "http://www.w3.org/2001/XMLSchema-instance"},
{Name: xml.Name{Space: "", Local: "xmlns:platformMsgs"}, Value: "urn:messages_2021_2.platform.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:env"}, Value: "http://schemas.xmlsoap.org/soap/envelope/"},
{Name: xml.Name{Space: "", Local: "xmlns:platformCore"}, Value: "urn:core_2021_2.platform.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:platformCommon"}, Value: "urn:common_2021_2.platform.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:listRel"}, Value: "urn:relationships_2021_2.lists.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:tranSales"}, Value: "urn:sales_2021_2.transactions.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:tranPurch"}, Value: "urn:purchases_2021_2.transactions.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:actSched"}, Value: "urn:scheduling_2021_2.activities.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:setupCustom"}, Value: "urn:customization_2021_2.setup.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:listAcct"}, Value: "urn:accounting_2021_2.lists.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:tranBank"}, Value: "urn:bank_2021_2.transactions.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:tranCust"}, Value: "urn:customers_2021_2.transactions.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:tranEmp"}, Value: "urn:employees_2021_2.transactions.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:tranInvt"}, Value: "urn:inventory_2021_2.transactions.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:listSupport"}, Value: "urn:support_2021_2.lists.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:tranGeneral"}, Value: "urn:general_2021_2.transactions.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:commGeneral"}, Value: "urn:communication_2021_2.general.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:listMkt"}, Value: "urn:marketing_2021_2.lists.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:listWebsite"}, Value: "urn:website_2021_2.lists.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:fileCabinet"}, Value: "urn:filecabinet_2021_2.documents.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:listEmp"}, Value: "urn:employees_2021_2.lists.webservices.netsuite.com"},
{Name: xml.Name{Space: "", Local: "xmlns:messages"}, Value: "urn:messages_2017_1.platform.webservices.netsuite.com"},
}
for _, ns := range namespaces {
start.Attr = append(start.Attr, ns)
}
type alias RequestEnvelope
a := alias(env)
return e.EncodeElement(a, start)
}
type Body struct {
ActionBody interface{} `xml:",any"`
}
type Header struct {
TokenPassport TokenPassport `xml:"platformMsgs:tokenPassport"`
// DocumentInfo struct {
// NSInfo string `xml:"platformMsgs:nsId,omitempty"`
// } `xml:"platformMsgs:documentInfo,omitempty"`
Preferences Preferences `xml:"platformMsgs:preferences"`
SearchPreferences SearchPreferences `xml:"platformMsgs:searchPreferences"`
}
func (h Header) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return omitempty.MarshalXML(h, e, start)
}
func (h Header) IsEmpty() bool {
return zero.IsZero(h)
}
func NewHeader() Header {
return Header{}
}
type ActionBody interface{}
type TokenPassport struct {
XMLName xml.Name `xml:"platformMsgs:tokenPassport"`
Account string `xml:"platformMsgs:account"`
ConsumerKey string `xml:"platformMsgs:consumerKey"`
Token string `xml:"platformMsgs:token"`
Nonce string `xml:"platformMsgs:nonce"`
Timestamp int64 `xml:"platformMsgs:timestamp"`
Signature struct {
Algorithm string `xml:"algorithm,attr"`
Text string `xml:",chardata"`
} `xml:"platformMsgs:signature"`
}
type Preferences struct {
}
type SearchPreferences struct {
PageSize int `xml:"platformMsgs:pageSize,omitempty"`
BodyFieldsOnly bool `xml:"platformMsgs:bodyFieldsOnly"`
ReturnSearchColumns bool `xml:"platformMsgs:returnSearchColumns"`
}
func (s SearchPreferences) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return omitempty.MarshalXML(s, e, start)
}
func (s SearchPreferences) IsEmpty() bool {
return zero.IsZero(s)
}