-
Notifications
You must be signed in to change notification settings - Fork 1
/
request_leg.go
135 lines (120 loc) · 3.87 KB
/
request_leg.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
package browse
import (
"encoding/json"
"fmt"
"net/url"
"strings"
)
//GetItemByLegacyIdRequest ...
type GetItemByLegacyIdRequest struct {
LegacyItemID string
LegacyVariationID string
LegacyVariationSKU string
FieldGroups []string
BasicRequest
}
// WithItemID adds legacyItemID parameter to GetItemByLegacyIdRequest
func (r *GetItemByLegacyIdRequest) WithItemID(legacyItemID string) *GetItemByLegacyIdRequest {
r.LegacyItemID = legacyItemID
return r
}
// WithLegacyVariationID adds legacyVariationID parameter to GetItemByLegacyIdRequest
func (r *GetItemByLegacyIdRequest) WithLegacyVariationID(legacyVariationID string) *GetItemByLegacyIdRequest {
r.LegacyItemID = legacyVariationID
return r
}
// WithLegacyVariationSKY adds legacyVariationSKY parameter to GetItemByLegacyIdRequest
func (r *GetItemByLegacyIdRequest) WithLegacyVariationSKY(legacyVariationSKY string) *GetItemByLegacyIdRequest {
r.LegacyVariationSKU = legacyVariationSKY
return r
}
// WithFieldGroups adds fieldsGroups parameter to GetItemByLegacyIdRequest
func (r *GetItemByLegacyIdRequest) WithFieldGroups(fieldGroups ...FieldGroupsOptions) *GetItemByLegacyIdRequest {
tfg := make([]string, 0)
tfgm := make(map[string]struct{})
for _, fg := range fieldGroups {
tfgm[string(fg)] = struct{}{}
}
for k := range tfgm {
tfg = append(tfg, k)
}
r.FieldGroups = tfg
return r
}
func (r *GetItemByLegacyIdRequest) Execute() (GetItemByLegacyIdResponse, error) {
values := r.getParams()
tRes, err := r.client.R().SetQueryParamsFromValues(values).Get(r.url)
if err != nil {
return GetItemByLegacyIdResponse{}, fmt.Errorf("error during http request %w", err)
}
if tRes.StatusCode() != 200 {
return GetItemByLegacyIdResponse{}, fmt.Errorf("response code is %d, not 200", tRes.StatusCode())
}
//fmt.Println(tRes.String())
res := GetItemByLegacyIdResponse{}
err = json.Unmarshal(tRes.Body(), &res)
if err != nil {
return GetItemByLegacyIdResponse{}, fmt.Errorf("error during unmarshalling response %w", err)
}
return res, nil
}
func (r *GetItemByLegacyIdRequest) getParams() url.Values {
values := url.Values{}
if r.LegacyItemID != "" {
values.Set("legacy_item_id", r.LegacyItemID)
}
if r.LegacyVariationID != "" {
values.Set("legacy_variation_id", r.LegacyVariationID)
}
if r.LegacyVariationSKU != "" {
values.Set("legacy_variation_sku", r.LegacyVariationSKU)
}
if len(r.FieldGroups) > 0 {
value := strings.Join(r.FieldGroups, ",")
values.Set("fieldgroups", value)
}
return values
}
func (r *GetItemByLegacyIdRequest) ShowParams() url.Values {
return r.getParams()
}
/*
=========================================================================
*/
//GetItemsByItemGroupRequest ...
type GetItemsByItemGroupRequest struct {
ItemGroupID string
BasicRequest
}
// WithItemGroupID adds itemGroupID parameter to GetItemsByItemGroupRequest
func (r *GetItemsByItemGroupRequest) WithItemGroupID(itemGroupID string) *GetItemsByItemGroupRequest {
r.ItemGroupID = itemGroupID
return r
}
func (r *GetItemsByItemGroupRequest) Execute() (GetItemsByItemGroupResponse, error) {
values := r.getParams()
tRes, err := r.client.R().SetQueryParamsFromValues(values).Get(r.url)
if err != nil {
return GetItemsByItemGroupResponse{}, fmt.Errorf("error during http request %w", err)
}
if tRes.StatusCode() != 200 {
return GetItemsByItemGroupResponse{}, fmt.Errorf("response code is %d, not 200", tRes.StatusCode())
}
//fmt.Println(tRes.String())
res := GetItemsByItemGroupResponse{}
err = json.Unmarshal(tRes.Body(), &res)
if err != nil {
return GetItemsByItemGroupResponse{}, fmt.Errorf("error during unmarshalling response %w", err)
}
return res, nil
}
func (r *GetItemsByItemGroupRequest) getParams() url.Values {
values := url.Values{}
if r.ItemGroupID != "" {
values.Set("item_group_id", r.ItemGroupID)
}
return values
}
func (r *GetItemsByItemGroupRequest) ShowParams() url.Values {
return r.getParams()
}