forked from labd/commercetools-go-sdk
/
client_action_frontastic_action_by_namespace_by_action_put.go
72 lines (64 loc) · 1.88 KB
/
client_action_frontastic_action_by_namespace_by_action_put.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
package frontend
// Generated file, please do not change!!!
import (
"context"
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
)
type FrontasticActionByNamespaceByActionRequestMethodPut struct {
body interface{}
url string
client *Client
headers http.Header
}
func (r *FrontasticActionByNamespaceByActionRequestMethodPut) Dump() map[string]interface{} {
return map[string]interface{}{
"url": r.url,
}
}
func (rb *FrontasticActionByNamespaceByActionRequestMethodPut) WithHeaders(headers http.Header) *FrontasticActionByNamespaceByActionRequestMethodPut {
rb.headers = headers
return rb
}
/**
* Use the PUT method to write data to a backend system. Any JSON serializable payload is accepted. The following request example adds a product to a cart. For the response, we recommend to use standard HTTP codes and `application/json` encoded content. The response will be structured [as defined by the `body` property of the action](/../frontend-development/developing-an-action-extension#1-implement-the-action). The following response example contains the updated cart information, which includes the added product.
*/
func (rb *FrontasticActionByNamespaceByActionRequestMethodPut) Execute(ctx context.Context) (result *interface{}, err error) {
queryParams := url.Values{}
resp, err := rb.client.put(
ctx,
rb.url,
queryParams,
rb.headers,
nil,
)
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:
errorObj := Error{}
err = json.Unmarshal(content, &errorObj)
if err != nil {
return nil, err
}
return nil, errorObj
default:
result := GenericRequestError{
StatusCode: resp.StatusCode,
Content: content,
Response: resp,
}
return nil, result
}
}