forked from labd/commercetools-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_custom_object.go
84 lines (76 loc) · 2.66 KB
/
service_custom_object.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
// Automatically generated, do not edit
package commercetools
import (
"context"
"fmt"
"net/url"
"strconv"
)
// CustomObjectCreate creates a new instance of type CustomObject
func (client *Client) CustomObjectCreate(ctx context.Context, draft *CustomObjectDraft, opts ...RequestOption) (result *CustomObject, err error) {
params := url.Values{}
for _, opt := range opts {
opt(¶ms)
}
endpoint := "custom-objects"
err = client.create(ctx, endpoint, params, draft, &result)
if err != nil {
return nil, err
}
return result, nil
}
// CustomObjectQuery allows querying for type CustomObject
/*
The query endpoint allows to retrieve custom objects in a specific container or all custom objects.
For performance reasons, it is highly advisable to query only for custom objects in a container by using
the container field in the where predicate.
*/
func (client *Client) CustomObjectQuery(ctx context.Context, input *QueryInput) (result *CustomObjectPagedQueryResponse, err error) {
endpoint := "custom-objects"
err = client.query(ctx, endpoint, input.toParams(), &result)
if err != nil {
return nil, err
}
return result, nil
}
// CustomObjectDeleteWithContainerAndKey Delete CustomObject by container and key
func (client *Client) CustomObjectDeleteWithContainerAndKey(ctx context.Context, container string, key string, version int, dataErasure bool, opts ...RequestOption) (result *CustomObject, err error) {
params := url.Values{}
params.Set("version", strconv.Itoa(version))
params.Set("dataErasure", strconv.FormatBool(dataErasure))
for _, opt := range opts {
opt(¶ms)
}
endpoint := fmt.Sprintf("custom-objects/%s/%s", container, key)
err = client.delete(ctx, endpoint, params, &result)
if err != nil {
return nil, err
}
return result, nil
}
// CustomObjectGetWithContainer for type CustomObject
func (client *Client) CustomObjectGetWithContainer(ctx context.Context, container string, opts ...RequestOption) (result *CustomObject, err error) {
params := url.Values{}
for _, opt := range opts {
opt(¶ms)
}
endpoint := fmt.Sprintf("custom-objects/%s", container)
err = client.get(ctx, endpoint, params, &result)
if err != nil {
return nil, err
}
return result, nil
}
// CustomObjectGetWithContainerAndKey Get CustomObject by container and key
func (client *Client) CustomObjectGetWithContainerAndKey(ctx context.Context, container string, key string, opts ...RequestOption) (result *CustomObject, err error) {
params := url.Values{}
for _, opt := range opts {
opt(¶ms)
}
endpoint := fmt.Sprintf("custom-objects/%s/%s", container, key)
err = client.get(ctx, endpoint, params, &result)
if err != nil {
return nil, err
}
return result, nil
}