-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpws_offers.go
350 lines (298 loc) · 11 KB
/
pws_offers.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
//********************************************************************************************************************//
//
// Copyright (C) 2018 - 2021 J&J Ideenschmiede GmbH <[email protected]>
//
// This file is part of goidealo.
// All code may be used. Feel free and maybe code something better.
//
// Author: Jonas Kwiedor (aka gowizzard)
//
//********************************************************************************************************************//
package goidealo
import (
"encoding/json"
"fmt"
)
// OfferBody is to structure the body data
type OfferBody struct {
Sku string `json:"sku,omitempty"`
Title string `json:"title,omitempty"`
Price string `json:"price,omitempty"`
Url string `json:"url,omitempty"`
PaymentCosts interface{} `json:"paymentCosts,omitempty"`
DeliveryCosts interface{} `json:"deliveryCosts,omitempty"`
BasePrice string `json:"basePrice,omitempty"`
PackagingUnit int `json:"packagingUnit,omitempty"`
VoucherCode string `json:"voucherCode,omitempty"`
BranchId string `json:"branchId,omitempty"`
Brand string `json:"brand,omitempty"`
Oens []string `json:"oens,omitempty"`
CategoryPath []string `json:"categoryPath,omitempty"`
Description string `json:"description,omitempty"`
ImageUrls []string `json:"imageUrls,omitempty"`
Eans []string `json:"eans,omitempty"`
Hans []string `json:"hans,omitempty"`
Pzns []string `json:"pzns,omitempty"`
Kbas []string `json:"kbas,omitempty"`
MerchantName string `json:"merchantName,omitempty"`
MerchantId string `json:"merchantId,omitempty"`
DeliveryComment string `json:"deliveryComment,omitempty"`
Delivery string `json:"delivery,omitempty"`
MaxOrderProcessingTime int `json:"maxOrderProcessingTime,omitempty"`
FreeReturnDays int `json:"freeReturnDays,omitempty"`
Checkout bool `json:"checkout,omitempty"`
CheckoutLimitPerPeriod int `json:"checkoutLimitPerPeriod"`
QuantityPerOrder int `json:"quantityPerOrder,omitempty"`
MinimumPrice string `json:"minimumPrice,omitempty"`
FulfillmentType string `json:"fulfillmentType,omitempty"`
TwoManHandlingFee string `json:"twoManHandlingFee,omitempty"`
DisposalFee string `json:"disposalFee,omitempty"`
Eec string `json:"eec,omitempty"`
EnergyLabels []*OfferBodyEnergyLabels `json:"energyLabels,omitempty"`
Deposit string `json:"deposit,omitempty"`
Size string `json:"size,omitempty"`
Colour string `json:"colour,omitempty"`
Gender string `json:"gender,omitempty"`
Material string `json:"material,omitempty"`
Replica bool `json:"replica,omitempty"`
Used bool `json:"used,omitempty"`
Download bool `json:"download,omitempty"`
DynamicProductAttributes interface{} `json:"dynamicProductAttributes,omitempty"`
}
type OfferBodyEnergyLabels struct {
EfficiencyClass string `json:"efficiencyClass,omitempty"`
Spectrum string `json:"spectrum,omitempty"`
LabelUrl string `json:"labelUrl,omitempty"`
DataSheetUrl string `json:"dataSheetUrl,omitempty"`
FuelEfficiencyClass string `json:"fuelEfficiencyClass,omitempty"`
WetGripClass string `json:"wetGripClass,omitempty"`
ExternalRollingNoise int `json:"externalRollingNoise,omitempty"`
ExternalRollingNoiseClass string `json:"externalRollingNoiseClass,omitempty"`
SnowGrip bool `json:"snowGrip,omitempty"`
IceGrip bool `json:"iceGrip,omitempty"`
Version int `json:"version,omitempty"`
}
// OfferReturn is to decode the json data
type OfferReturn struct {
Sku string `json:"sku"`
Title string `json:"title"`
Price string `json:"price"`
Url string `json:"url"`
BasePrice string `json:"basePrice"`
PackagingUnit int `json:"packagingUnit"`
VoucherCode string `json:"voucherCode"`
BranchId string `json:"branchId"`
Brand string `json:"brand"`
Oens []string `json:"oens"`
CategoryPath []string `json:"categoryPath"`
Description string `json:"description"`
ImageUrls []string `json:"imageUrls"`
Eans []string `json:"eans"`
Hans []string `json:"hans"`
Pzns []string `json:"pzns"`
Kbas []string `json:"kbas"`
MerchantName string `json:"merchantName"`
MerchantId string `json:"merchantId"`
PaymentCosts struct {
PAYPAL string `json:"PAYPAL"`
CASHINADVANCE string `json:"CASH_IN_ADVANCE"`
INVOICE string `json:"INVOICE"`
CREDITCARD string `json:"CREDIT_CARD"`
} `json:"paymentCosts"`
DeliveryCosts struct {
DHL string `json:"DHL"`
DPD string `json:"DPD"`
} `json:"deliveryCosts"`
DeliveryComment string `json:"deliveryComment"`
Delivery string `json:"delivery"`
MaxOrderProcessingTime int `json:"maxOrderProcessingTime"`
FreeReturnDays int `json:"freeReturnDays"`
Checkout bool `json:"checkout"`
CheckoutLimitPerPeriod int `json:"checkoutLimitPerPeriod"`
QuantityPerOrder int `json:"quantityPerOrder"`
MinimumPrice string `json:"minimumPrice"`
FulfillmentType string `json:"fulfillmentType"`
TwoManHandlingFee string `json:"twoManHandlingFee"`
DisposalFee string `json:"disposalFee"`
Eec string `json:"eec"`
EnergyLabels []struct {
EfficiencyClass string `json:"efficiencyClass"`
Spectrum string `json:"spectrum"`
LabelUrl string `json:"labelUrl"`
DataSheetUrl string `json:"dataSheetUrl"`
Version int `json:"version"`
} `json:"energyLabels"`
Deposit string `json:"deposit"`
Size string `json:"size"`
Colour string `json:"colour"`
Gender string `json:"gender"`
Material string `json:"material"`
Replica bool `json:"replica"`
Used bool `json:"used"`
Download bool `json:"download"`
DynamicProductAttributes interface{} `json:"dynamicProductAttributes"`
FieldErrors []struct {
Field string `json:"field"`
Message string `json:"message"`
} `json:"fieldErrors"`
GeneralErrors []string `json:"generalErrors,omitempty"`
}
// Offer is to get an offer by id
func Offer(shopId int, sku string, r Request) (OfferReturn, error) {
// Config new request
c := Config{
Pws: true,
Path: fmt.Sprintf("/shop/%d/offer/%s", shopId, sku),
Method: "GET",
}
// Send new request
response, err := c.Send(r)
if err != nil {
return OfferReturn{}, err
}
// Close request body
defer response.Body.Close()
// Check response status
err = statusCodes(response.Status)
if err != nil {
return OfferReturn{}, err
}
// Decode data
var decode OfferReturn
json.NewDecoder(response.Body).Decode(&decode)
// Return data
return decode, nil
}
// CreateOffer is to create an new offer
func CreateOffer(shopId int, body OfferBody, r Request) (OfferReturn, error) {
// Convert body
convert, err := json.Marshal(body)
if err != nil {
return OfferReturn{}, err
}
// Config new request
c := Config{
Pws: true,
Path: fmt.Sprintf("/shop/%d/offer/%s", shopId, body.Sku),
Method: "PUT",
Body: convert,
}
// Send new request
response, err := c.Send(r)
if err != nil {
return OfferReturn{}, err
}
// Close request body
defer response.Body.Close()
// Decode data
var decode OfferReturn
json.NewDecoder(response.Body).Decode(&decode)
// Check response status
err = statusCodes(response.Status)
if err != nil {
return OfferReturn{}, err
}
// Return data
return decode, nil
}
// UpdateOffer is to update an existing offer
func UpdateOffer(shopId int, body OfferBody, r Request) (OfferReturn, error) {
// Convert body
convert, err := json.Marshal(body)
if err != nil {
return OfferReturn{}, err
}
// Config new request
c := Config{
Pws: true,
Path: fmt.Sprintf("/shop/%d/offer/%s", shopId, body.Sku),
Method: "PATCH",
Body: convert,
}
// Send new request
response, err := c.Send(r)
if err != nil {
return OfferReturn{}, err
}
// Close request body
defer response.Body.Close()
// Check response status
err = statusCodes(response.Status)
if err != nil {
return OfferReturn{}, err
}
// Decode data
var decode OfferReturn
json.NewDecoder(response.Body).Decode(&decode)
// Return data
return decode, nil
}
// DeleteOffer is to delete an offer
func DeleteOffer(shopId int, sku string, r Request) error {
// Config new request
c := Config{
Pws: true,
Path: fmt.Sprintf("/shop/%d/offer/%s", shopId, sku),
Method: "DELETE",
}
// Send new request
response, err := c.Send(r)
if err != nil {
return err
}
// Close request body
defer response.Body.Close()
// Check response status
err = statusCodes(response.Status)
if err != nil {
return err
}
// Return nothing
return nil
}
// DeleteAllOffers is to delete all existing offers
func DeleteAllOffers(shopId int, r Request) error {
// Config new request
c := Config{
Pws: true,
Path: fmt.Sprintf("/shop/%d/offer", shopId),
Method: "DELETE",
}
// Send new request
response, err := c.Send(r)
if err != nil {
return err
}
// Close request body
defer response.Body.Close()
// Check response status
err = statusCodes(response.Status)
if err != nil {
return err
}
// Return nothing
return nil
}
// UpdateOffersTimestamp is to update the timestamp of all offers
func UpdateOffersTimestamp(shopId int, r Request) error {
// Config new request
c := Config{
Pws: true,
Path: fmt.Sprintf("/shop/%d/offer", shopId),
Method: "PUT",
}
// Send new request
response, err := c.Send(r)
if err != nil {
return err
}
// Close request body
defer response.Body.Close()
// Check response status
err = statusCodes(response.Status)
if err != nil {
return err
}
// Return nothing
return nil
}