forked from labd/commercetools-go-sdk
/
client_product_projections_by_project_key_in_store_key_by_store_key_product_projections_by_id_get.go
186 lines (169 loc) · 6.07 KB
/
client_product_projections_by_project_key_in_store_key_by_store_key_product_projections_by_id_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
package platform
// Generated file, please do not change!!!
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
type ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet struct {
url string
client *Client
headers http.Header
params *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput
}
func (r *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) Dump() map[string]interface{} {
return map[string]interface{}{
"url": r.url,
"params": r.params,
}
}
type ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput struct {
Staged *bool
PriceCurrency *string
PriceCountry *string
PriceCustomerGroup *string
PriceChannel *string
LocaleProjection []string
Expand []string
}
func (input *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput) Values() url.Values {
values := url.Values{}
if input.Staged != nil {
if *input.Staged {
values.Add("staged", "true")
} else {
values.Add("staged", "false")
}
}
if input.PriceCurrency != nil {
values.Add("priceCurrency", fmt.Sprintf("%v", *input.PriceCurrency))
}
if input.PriceCountry != nil {
values.Add("priceCountry", fmt.Sprintf("%v", *input.PriceCountry))
}
if input.PriceCustomerGroup != nil {
values.Add("priceCustomerGroup", fmt.Sprintf("%v", *input.PriceCustomerGroup))
}
if input.PriceChannel != nil {
values.Add("priceChannel", fmt.Sprintf("%v", *input.PriceChannel))
}
for _, v := range input.LocaleProjection {
values.Add("localeProjection", fmt.Sprintf("%v", v))
}
for _, v := range input.Expand {
values.Add("expand", fmt.Sprintf("%v", v))
}
return values
}
func (rb *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) Staged(v bool) *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet {
if rb.params == nil {
rb.params = &ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput{}
}
rb.params.Staged = &v
return rb
}
func (rb *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) PriceCurrency(v string) *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet {
if rb.params == nil {
rb.params = &ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput{}
}
rb.params.PriceCurrency = &v
return rb
}
func (rb *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) PriceCountry(v string) *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet {
if rb.params == nil {
rb.params = &ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput{}
}
rb.params.PriceCountry = &v
return rb
}
func (rb *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) PriceCustomerGroup(v string) *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet {
if rb.params == nil {
rb.params = &ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput{}
}
rb.params.PriceCustomerGroup = &v
return rb
}
func (rb *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) PriceChannel(v string) *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet {
if rb.params == nil {
rb.params = &ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput{}
}
rb.params.PriceChannel = &v
return rb
}
func (rb *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) LocaleProjection(v []string) *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet {
if rb.params == nil {
rb.params = &ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput{}
}
rb.params.LocaleProjection = v
return rb
}
func (rb *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) Expand(v []string) *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet {
if rb.params == nil {
rb.params = &ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput{}
}
rb.params.Expand = v
return rb
}
func (rb *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) WithQueryParams(input ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGetInput) *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet {
rb.params = &input
return rb
}
func (rb *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) WithHeaders(headers http.Header) *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet {
rb.headers = headers
return rb
}
/**
* Gets the current or staged representation of a [Product](ctp:api:type:Product) by its ID from the specified [Store](ctp:api:type:Store).
* If the Store has defined some languages, countries, distribution or supply Channels,
* they are used for projections based on [locale](ctp:api:type:ProductProjectionLocales), [price](ctp:api:type:ProductProjectionPrices)
* and [inventory](ctp:api:type:ProductProjectionInventoryEntries).
*
* When used with an API Client that has the `view_published_products:{projectKey}` scope, this endpoint only returns published (current) Product Projections.
*
*/
func (rb *ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDRequestMethodGet) Execute(ctx context.Context) (result *ProductProjection, err error) {
var queryParams url.Values
if rb.params != nil {
queryParams = rb.params.Values()
} else {
queryParams = url.Values{}
}
resp, err := rb.client.get(
ctx,
rb.url,
queryParams,
rb.headers,
)
if err != nil {
return nil, err
}
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
defer resp.Body.Close()
switch resp.StatusCode {
case 200:
err = json.Unmarshal(content, &result)
return result, nil
case 400, 401, 403, 500, 502, 503:
errorObj := ErrorResponse{}
err = json.Unmarshal(content, &errorObj)
if err != nil {
return nil, err
}
return nil, errorObj
case 404:
return nil, ErrNotFound
default:
result := GenericRequestError{
StatusCode: resp.StatusCode,
Content: content,
Response: resp,
}
return nil, result
}
}