-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplanmigration.go
More file actions
389 lines (339 loc) · 14 KB
/
planmigration.go
File metadata and controls
389 lines (339 loc) · 14 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package orb
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"reflect"
"slices"
"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"
"github.com/tidwall/gjson"
)
// The [Plan](/core-concepts#plan-and-price) resource represents a plan that can be
// subscribed to by a customer. Plans define the billing behavior of the
// subscription. You can see more about how to configure prices in the
// [Price resource](/reference/price).
//
// PlanMigrationService 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 [NewPlanMigrationService] method instead.
type PlanMigrationService struct {
Options []option.RequestOption
}
// NewPlanMigrationService 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 NewPlanMigrationService(opts ...option.RequestOption) (r *PlanMigrationService) {
r = &PlanMigrationService{}
r.Options = opts
return
}
// Fetch migration
func (r *PlanMigrationService) Get(ctx context.Context, planID string, migrationID string, opts ...option.RequestOption) (res *PlanMigrationGetResponse, err error) {
opts = slices.Concat(r.Options, opts)
if planID == "" {
err = errors.New("missing required plan_id parameter")
return nil, err
}
if migrationID == "" {
err = errors.New("missing required migration_id parameter")
return nil, err
}
path := fmt.Sprintf("plans/%s/migrations/%s", planID, migrationID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// This endpoint returns a list of all migrations for a plan. The list of
// migrations is ordered starting from the most recently created migration. The
// response also includes pagination_metadata, which lets the caller retrieve the
// next page of results if they exist.
func (r *PlanMigrationService) List(ctx context.Context, planID string, query PlanMigrationListParams, opts ...option.RequestOption) (res *pagination.Page[PlanMigrationListResponse], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if planID == "" {
err = errors.New("missing required plan_id parameter")
return nil, err
}
path := fmt.Sprintf("plans/%s/migrations", planID)
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
}
// This endpoint returns a list of all migrations for a plan. The list of
// migrations is ordered starting from the most recently created migration. The
// response also includes pagination_metadata, which lets the caller retrieve the
// next page of results if they exist.
func (r *PlanMigrationService) ListAutoPaging(ctx context.Context, planID string, query PlanMigrationListParams, opts ...option.RequestOption) *pagination.PageAutoPager[PlanMigrationListResponse] {
return pagination.NewPageAutoPager(r.List(ctx, planID, query, opts...))
}
// This endpoint cancels a migration.
func (r *PlanMigrationService) Cancel(ctx context.Context, planID string, migrationID string, opts ...option.RequestOption) (res *PlanMigrationCancelResponse, err error) {
opts = slices.Concat(r.Options, opts)
if planID == "" {
err = errors.New("missing required plan_id parameter")
return nil, err
}
if migrationID == "" {
err = errors.New("missing required migration_id parameter")
return nil, err
}
path := fmt.Sprintf("plans/%s/migrations/%s/cancel", planID, migrationID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return res, err
}
type PlanMigrationGetResponse struct {
ID string `json:"id" api:"required"`
EffectiveTime PlanMigrationGetResponseEffectiveTimeUnion `json:"effective_time" api:"required,nullable" format:"date"`
PlanID string `json:"plan_id" api:"required"`
Status PlanMigrationGetResponseStatus `json:"status" api:"required"`
JSON planMigrationGetResponseJSON `json:"-"`
}
// planMigrationGetResponseJSON contains the JSON metadata for the struct
// [PlanMigrationGetResponse]
type planMigrationGetResponseJSON struct {
ID apijson.Field
EffectiveTime apijson.Field
PlanID apijson.Field
Status apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanMigrationGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planMigrationGetResponseJSON) RawJSON() string {
return r.raw
}
// Union satisfied by [shared.UnionTime], [shared.UnionTime] or
// [PlanMigrationGetResponseEffectiveTimeString].
type PlanMigrationGetResponseEffectiveTimeUnion interface {
ImplementsPlanMigrationGetResponseEffectiveTimeUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*PlanMigrationGetResponseEffectiveTimeUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionTime(shared.UnionTime{})),
},
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionTime(shared.UnionTime{})),
},
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(PlanMigrationGetResponseEffectiveTimeString("")),
},
)
}
type PlanMigrationGetResponseEffectiveTimeString string
const (
PlanMigrationGetResponseEffectiveTimeStringEndOfTerm PlanMigrationGetResponseEffectiveTimeString = "end_of_term"
)
func (r PlanMigrationGetResponseEffectiveTimeString) IsKnown() bool {
switch r {
case PlanMigrationGetResponseEffectiveTimeStringEndOfTerm:
return true
}
return false
}
func (r PlanMigrationGetResponseEffectiveTimeString) ImplementsPlanMigrationGetResponseEffectiveTimeUnion() {
}
type PlanMigrationGetResponseStatus string
const (
PlanMigrationGetResponseStatusNotStarted PlanMigrationGetResponseStatus = "not_started"
PlanMigrationGetResponseStatusInProgress PlanMigrationGetResponseStatus = "in_progress"
PlanMigrationGetResponseStatusCompleted PlanMigrationGetResponseStatus = "completed"
PlanMigrationGetResponseStatusActionNeeded PlanMigrationGetResponseStatus = "action_needed"
PlanMigrationGetResponseStatusCanceled PlanMigrationGetResponseStatus = "canceled"
)
func (r PlanMigrationGetResponseStatus) IsKnown() bool {
switch r {
case PlanMigrationGetResponseStatusNotStarted, PlanMigrationGetResponseStatusInProgress, PlanMigrationGetResponseStatusCompleted, PlanMigrationGetResponseStatusActionNeeded, PlanMigrationGetResponseStatusCanceled:
return true
}
return false
}
type PlanMigrationListResponse struct {
ID string `json:"id" api:"required"`
EffectiveTime PlanMigrationListResponseEffectiveTimeUnion `json:"effective_time" api:"required,nullable" format:"date"`
PlanID string `json:"plan_id" api:"required"`
Status PlanMigrationListResponseStatus `json:"status" api:"required"`
JSON planMigrationListResponseJSON `json:"-"`
}
// planMigrationListResponseJSON contains the JSON metadata for the struct
// [PlanMigrationListResponse]
type planMigrationListResponseJSON struct {
ID apijson.Field
EffectiveTime apijson.Field
PlanID apijson.Field
Status apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanMigrationListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planMigrationListResponseJSON) RawJSON() string {
return r.raw
}
// Union satisfied by [shared.UnionTime], [shared.UnionTime] or
// [PlanMigrationListResponseEffectiveTimeString].
type PlanMigrationListResponseEffectiveTimeUnion interface {
ImplementsPlanMigrationListResponseEffectiveTimeUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*PlanMigrationListResponseEffectiveTimeUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionTime(shared.UnionTime{})),
},
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionTime(shared.UnionTime{})),
},
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(PlanMigrationListResponseEffectiveTimeString("")),
},
)
}
type PlanMigrationListResponseEffectiveTimeString string
const (
PlanMigrationListResponseEffectiveTimeStringEndOfTerm PlanMigrationListResponseEffectiveTimeString = "end_of_term"
)
func (r PlanMigrationListResponseEffectiveTimeString) IsKnown() bool {
switch r {
case PlanMigrationListResponseEffectiveTimeStringEndOfTerm:
return true
}
return false
}
func (r PlanMigrationListResponseEffectiveTimeString) ImplementsPlanMigrationListResponseEffectiveTimeUnion() {
}
type PlanMigrationListResponseStatus string
const (
PlanMigrationListResponseStatusNotStarted PlanMigrationListResponseStatus = "not_started"
PlanMigrationListResponseStatusInProgress PlanMigrationListResponseStatus = "in_progress"
PlanMigrationListResponseStatusCompleted PlanMigrationListResponseStatus = "completed"
PlanMigrationListResponseStatusActionNeeded PlanMigrationListResponseStatus = "action_needed"
PlanMigrationListResponseStatusCanceled PlanMigrationListResponseStatus = "canceled"
)
func (r PlanMigrationListResponseStatus) IsKnown() bool {
switch r {
case PlanMigrationListResponseStatusNotStarted, PlanMigrationListResponseStatusInProgress, PlanMigrationListResponseStatusCompleted, PlanMigrationListResponseStatusActionNeeded, PlanMigrationListResponseStatusCanceled:
return true
}
return false
}
type PlanMigrationCancelResponse struct {
ID string `json:"id" api:"required"`
EffectiveTime PlanMigrationCancelResponseEffectiveTimeUnion `json:"effective_time" api:"required,nullable" format:"date"`
PlanID string `json:"plan_id" api:"required"`
Status PlanMigrationCancelResponseStatus `json:"status" api:"required"`
JSON planMigrationCancelResponseJSON `json:"-"`
}
// planMigrationCancelResponseJSON contains the JSON metadata for the struct
// [PlanMigrationCancelResponse]
type planMigrationCancelResponseJSON struct {
ID apijson.Field
EffectiveTime apijson.Field
PlanID apijson.Field
Status apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanMigrationCancelResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planMigrationCancelResponseJSON) RawJSON() string {
return r.raw
}
// Union satisfied by [shared.UnionTime], [shared.UnionTime] or
// [PlanMigrationCancelResponseEffectiveTimeString].
type PlanMigrationCancelResponseEffectiveTimeUnion interface {
ImplementsPlanMigrationCancelResponseEffectiveTimeUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*PlanMigrationCancelResponseEffectiveTimeUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionTime(shared.UnionTime{})),
},
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionTime(shared.UnionTime{})),
},
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(PlanMigrationCancelResponseEffectiveTimeString("")),
},
)
}
type PlanMigrationCancelResponseEffectiveTimeString string
const (
PlanMigrationCancelResponseEffectiveTimeStringEndOfTerm PlanMigrationCancelResponseEffectiveTimeString = "end_of_term"
)
func (r PlanMigrationCancelResponseEffectiveTimeString) IsKnown() bool {
switch r {
case PlanMigrationCancelResponseEffectiveTimeStringEndOfTerm:
return true
}
return false
}
func (r PlanMigrationCancelResponseEffectiveTimeString) ImplementsPlanMigrationCancelResponseEffectiveTimeUnion() {
}
type PlanMigrationCancelResponseStatus string
const (
PlanMigrationCancelResponseStatusNotStarted PlanMigrationCancelResponseStatus = "not_started"
PlanMigrationCancelResponseStatusInProgress PlanMigrationCancelResponseStatus = "in_progress"
PlanMigrationCancelResponseStatusCompleted PlanMigrationCancelResponseStatus = "completed"
PlanMigrationCancelResponseStatusActionNeeded PlanMigrationCancelResponseStatus = "action_needed"
PlanMigrationCancelResponseStatusCanceled PlanMigrationCancelResponseStatus = "canceled"
)
func (r PlanMigrationCancelResponseStatus) IsKnown() bool {
switch r {
case PlanMigrationCancelResponseStatusNotStarted, PlanMigrationCancelResponseStatusInProgress, PlanMigrationCancelResponseStatusCompleted, PlanMigrationCancelResponseStatusActionNeeded, PlanMigrationCancelResponseStatusCanceled:
return true
}
return false
}
type PlanMigrationListParams 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 [PlanMigrationListParams]'s query parameters as
// `url.Values`.
func (r PlanMigrationListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}