-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustomers_get.go
207 lines (178 loc) · 4.38 KB
/
customers_get.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package economic
import (
"net/http"
"net/url"
)
func (c *Client) NewCustomersGetRequest() CustomersGetRequest {
return CustomersGetRequest{
client: c,
queryParams: c.NewCustomersGetQueryParams(),
pathParams: c.NewCustomersGetPathParams(),
method: http.MethodGet,
headers: http.Header{},
requestBody: c.NewCustomersGetRequestBody(),
}
}
type CustomersGetRequest struct {
client *Client
queryParams *CustomersGetQueryParams
pathParams *CustomersGetPathParams
method string
headers http.Header
requestBody CustomersGetRequestBody
}
func (c *Client) NewCustomersGetQueryParams() *CustomersGetQueryParams {
return &CustomersGetQueryParams{}
}
type CustomersGetQueryParams struct {
// https://restdocs.e-conomic.com/#pagination
SkipPages int `schema:"skippages,omitempty"`
PageSize int `schema:"pagesize,omitempty"`
// https://restdocs.e-conomic.com/#filtering
Filter Filter `schema:"filter,omitempty"`
// https://restdocs.e-conomic.com/#sorting
Sort string `schema:"sort,omitempty"`
}
func (r CustomersGetRequest) RequiredProperties() []string {
return []string{
"attention.self",
"currency",
"customerContact.self",
"customerGroup",
"customerGroup.self",
"defaultDeliveryLocation.self",
"invoices.self",
"layout.self",
"name",
"paymentTerms",
"paymentTerms.self",
"salesPerson.self",
"self",
"templates.self",
"totals.self",
"vatZone",
"vatZone.self",
}
}
func (r CustomersGetRequest) FilterableProperties() []string {
return []string{
"address",
"balance",
"barred",
"city",
"corporateIdentificationNumber",
"country",
"creditLimit",
"currency",
"customerNumber",
"ean",
"email",
"lastUpdated",
"mobilePhone",
"name",
"publicEntryNumber",
"telephoneAndFaxNumber",
"vatNumber",
"website",
"zip",
}
}
func (r CustomersGetRequest) SortableProperties() []string {
return []string{
"address",
"balance",
"city",
"corporateIdentificationNumber",
"country",
"creditLimit",
"currency",
"customerNumber",
"ean",
"email",
"lastUpdated",
"mobilePhone",
"name",
"publicEntryNumber",
"telephoneAndFaxNumber",
"vatNumber",
"website",
"zip",
}
}
func (p CustomersGetQueryParams) ToURLValues() (url.Values, error) {
encoder := newSchemaEncoder()
params := url.Values{}
err := encoder.Encode(p, params)
if err != nil {
return params, err
}
return params, nil
}
func (r *CustomersGetRequest) QueryParams() *CustomersGetQueryParams {
return r.queryParams
}
func (c *Client) NewCustomersGetPathParams() *CustomersGetPathParams {
return &CustomersGetPathParams{}
}
type CustomersGetPathParams struct {
}
func (p *CustomersGetPathParams) Params() map[string]string {
return map[string]string{}
}
func (r *CustomersGetRequest) PathParams() *CustomersGetPathParams {
return r.pathParams
}
func (r *CustomersGetRequest) SetMethod(method string) {
r.method = method
}
func (r *CustomersGetRequest) Method() string {
return r.method
}
func (s *Client) NewCustomersGetRequestBody() CustomersGetRequestBody {
return CustomersGetRequestBody{}
}
type CustomersGetRequestBody struct {
}
func (r *CustomersGetRequest) RequestBody() *CustomersGetRequestBody {
return &r.requestBody
}
func (r *CustomersGetRequest) SetRequestBody(body CustomersGetRequestBody) {
r.requestBody = body
}
func (r *CustomersGetRequest) NewResponseBody() *CustomersGetResponseBody {
return &CustomersGetResponseBody{}
}
type CustomersGetResponseBody struct {
Collection []Customer `json:"collection"`
Pagination Pagination `json:"pagination"`
MetaData struct {
Create struct {
Description string `json:"description"`
Href string `json:"href"`
HTTPMethod string `json:"httpMethod"`
} `json:"create"`
} `json:"metaData"`
Self string `json:"self"`
}
func (r *CustomersGetRequest) URL() (url.URL, error) {
return r.client.GetEndpointURL("customers", r.PathParams())
}
func (r *CustomersGetRequest) Do() (CustomersGetResponseBody, error) {
u, err := r.URL()
if err != nil {
return *r.NewResponseBody(), err
}
// Create http request
req, err := r.client.NewRequest(nil, r.Method(), u, nil)
if err != nil {
return *r.NewResponseBody(), err
}
// Process query parameters
err = AddQueryParamsToRequest(r.QueryParams(), req, false)
if err != nil {
return *r.NewResponseBody(), err
}
responseBody := r.NewResponseBody()
_, err = r.client.Do(req, responseBody)
return *responseBody, err
}