forked from orbcorp/orb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdimensionalpricegroup.go
More file actions
220 lines (196 loc) · 9.31 KB
/
dimensionalpricegroup.go
File metadata and controls
220 lines (196 loc) · 9.31 KB
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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package orb
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"github.com/orbcorp/orb-go/internal/apijson"
"github.com/orbcorp/orb-go/internal/apiquery"
"github.com/orbcorp/orb-go/internal/param"
"github.com/orbcorp/orb-go/internal/requestconfig"
"github.com/orbcorp/orb-go/option"
"github.com/orbcorp/orb-go/packages/pagination"
"github.com/orbcorp/orb-go/shared"
)
// DimensionalPriceGroupService contains methods and other services that help with
// interacting with the orb API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewDimensionalPriceGroupService] method instead.
type DimensionalPriceGroupService struct {
Options []option.RequestOption
ExternalDimensionalPriceGroupID *DimensionalPriceGroupExternalDimensionalPriceGroupIDService
}
// NewDimensionalPriceGroupService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewDimensionalPriceGroupService(opts ...option.RequestOption) (r *DimensionalPriceGroupService) {
r = &DimensionalPriceGroupService{}
r.Options = opts
r.ExternalDimensionalPriceGroupID = NewDimensionalPriceGroupExternalDimensionalPriceGroupIDService(opts...)
return
}
// A dimensional price group is used to partition the result of a billable metric
// by a set of dimensions. Prices in a price group must specify the partition used
// to derive their usage.
//
// For example, suppose we have a billable metric that measures the number of
// widgets used and we want to charge differently depending on the color of the
// widget. We can create a price group with a dimension "color" and two prices: one
// that charges \$10 per red widget and one that charges \$20 per blue widget.
func (r *DimensionalPriceGroupService) New(ctx context.Context, body DimensionalPriceGroupNewParams, opts ...option.RequestOption) (res *DimensionalPriceGroup, err error) {
opts = append(r.Options[:], opts...)
path := "dimensional_price_groups"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Fetch dimensional price group
func (r *DimensionalPriceGroupService) Get(ctx context.Context, dimensionalPriceGroupID string, opts ...option.RequestOption) (res *DimensionalPriceGroup, err error) {
opts = append(r.Options[:], opts...)
if dimensionalPriceGroupID == "" {
err = errors.New("missing required dimensional_price_group_id parameter")
return
}
path := fmt.Sprintf("dimensional_price_groups/%s", dimensionalPriceGroupID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// This endpoint can be used to update the `external_dimensional_price_group_id`
// and `metadata` of an existing dimensional price group. Other fields on a
// dimensional price group are currently immutable.
func (r *DimensionalPriceGroupService) Update(ctx context.Context, dimensionalPriceGroupID string, body DimensionalPriceGroupUpdateParams, opts ...option.RequestOption) (res *DimensionalPriceGroup, err error) {
opts = append(r.Options[:], opts...)
if dimensionalPriceGroupID == "" {
err = errors.New("missing required dimensional_price_group_id parameter")
return
}
path := fmt.Sprintf("dimensional_price_groups/%s", dimensionalPriceGroupID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, body, &res, opts...)
return
}
// List dimensional price groups
func (r *DimensionalPriceGroupService) List(ctx context.Context, query DimensionalPriceGroupListParams, opts ...option.RequestOption) (res *pagination.Page[DimensionalPriceGroup], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "dimensional_price_groups"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List dimensional price groups
func (r *DimensionalPriceGroupService) ListAutoPaging(ctx context.Context, query DimensionalPriceGroupListParams, opts ...option.RequestOption) *pagination.PageAutoPager[DimensionalPriceGroup] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
// A dimensional price group is used to partition the result of a billable metric
// by a set of dimensions. Prices in a price group must specify the parition used
// to derive their usage.
type DimensionalPriceGroup struct {
ID string `json:"id,required"`
// The billable metric associated with this dimensional price group. All prices
// associated with this dimensional price group will be computed using this
// billable metric.
BillableMetricID string `json:"billable_metric_id,required"`
// The dimensions that this dimensional price group is defined over
Dimensions []string `json:"dimensions,required"`
// An alias for the dimensional price group
ExternalDimensionalPriceGroupID string `json:"external_dimensional_price_group_id,required,nullable"`
// User specified key-value pairs for the resource. If not present, this defaults
// to an empty dictionary. Individual keys can be removed by setting the value to
// `null`, and the entire metadata mapping can be cleared by setting `metadata` to
// `null`.
Metadata map[string]string `json:"metadata,required"`
// The name of the dimensional price group
Name string `json:"name,required"`
JSON dimensionalPriceGroupJSON `json:"-"`
}
// dimensionalPriceGroupJSON contains the JSON metadata for the struct
// [DimensionalPriceGroup]
type dimensionalPriceGroupJSON struct {
ID apijson.Field
BillableMetricID apijson.Field
Dimensions apijson.Field
ExternalDimensionalPriceGroupID apijson.Field
Metadata apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DimensionalPriceGroup) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dimensionalPriceGroupJSON) RawJSON() string {
return r.raw
}
type DimensionalPriceGroups struct {
Data []DimensionalPriceGroup `json:"data,required"`
PaginationMetadata shared.PaginationMetadata `json:"pagination_metadata,required"`
JSON dimensionalPriceGroupsJSON `json:"-"`
}
// dimensionalPriceGroupsJSON contains the JSON metadata for the struct
// [DimensionalPriceGroups]
type dimensionalPriceGroupsJSON struct {
Data apijson.Field
PaginationMetadata apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DimensionalPriceGroups) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dimensionalPriceGroupsJSON) RawJSON() string {
return r.raw
}
type DimensionalPriceGroupNewParams struct {
BillableMetricID param.Field[string] `json:"billable_metric_id,required"`
// The set of keys (in order) used to disambiguate prices in the group.
Dimensions param.Field[[]string] `json:"dimensions,required"`
Name param.Field[string] `json:"name,required"`
ExternalDimensionalPriceGroupID param.Field[string] `json:"external_dimensional_price_group_id"`
// User-specified key/value pairs for the resource. Individual keys can be removed
// by setting the value to `null`, and the entire metadata mapping can be cleared
// by setting `metadata` to `null`.
Metadata param.Field[map[string]string] `json:"metadata"`
}
func (r DimensionalPriceGroupNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type DimensionalPriceGroupUpdateParams struct {
// An optional user-defined ID for this dimensional price group resource, used
// throughout the system as an alias for this dimensional price group. Use this
// field to identify a dimensional price group by an existing identifier in your
// system.
ExternalDimensionalPriceGroupID param.Field[string] `json:"external_dimensional_price_group_id"`
// User-specified key/value pairs for the resource. Individual keys can be removed
// by setting the value to `null`, and the entire metadata mapping can be cleared
// by setting `metadata` to `null`.
Metadata param.Field[map[string]string] `json:"metadata"`
}
func (r DimensionalPriceGroupUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type DimensionalPriceGroupListParams struct {
// Cursor for pagination. This can be populated by the `next_cursor` value returned
// from the initial request.
Cursor param.Field[string] `query:"cursor"`
// The number of items to fetch. Defaults to 20.
Limit param.Field[int64] `query:"limit"`
}
// URLQuery serializes [DimensionalPriceGroupListParams]'s query parameters as
// `url.Values`.
func (r DimensionalPriceGroupListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}