@@ -210,33 +210,19 @@ type CreateWorkspaceRequest struct {
210
210
}
211
211
212
212
func (c * Client ) OrganizationByName (ctx context.Context , name string ) (Organization , error ) {
213
- res , err := c .Request (ctx , http .MethodGet , fmt .Sprintf ("/api/v2/organizations/%s" , name ), nil )
214
- if err != nil {
215
- return Organization {}, xerrors .Errorf ("execute request: %w" , err )
216
- }
217
- defer res .Body .Close ()
218
-
219
- if res .StatusCode != http .StatusOK {
220
- return Organization {}, ReadBodyAsError (res )
221
- }
222
-
223
- var organization Organization
224
- return organization , json .NewDecoder (res .Body ).Decode (& organization )
213
+ return makeSDKRequest [Organization ](ctx , c , sdkRequestArgs {
214
+ Method : http .MethodGet ,
215
+ URL : fmt .Sprintf ("/api/v2/organizations/%s" , name ),
216
+ ExpectCode : http .StatusOK ,
217
+ })
225
218
}
226
219
227
220
func (c * Client ) Organizations (ctx context.Context ) ([]Organization , error ) {
228
- res , err := c .Request (ctx , http .MethodGet , "/api/v2/organizations" , nil )
229
- if err != nil {
230
- return []Organization {}, xerrors .Errorf ("execute request: %w" , err )
231
- }
232
- defer res .Body .Close ()
233
-
234
- if res .StatusCode != http .StatusOK {
235
- return []Organization {}, ReadBodyAsError (res )
236
- }
237
-
238
- var organizations []Organization
239
- return organizations , json .NewDecoder (res .Body ).Decode (& organizations )
221
+ return makeSDKRequest [[]Organization ](ctx , c , sdkRequestArgs {
222
+ Method : http .MethodGet ,
223
+ URL : "/api/v2/organizations" ,
224
+ ExpectCode : http .StatusOK ,
225
+ })
240
226
}
241
227
242
228
func (c * Client ) Organization (ctx context.Context , id uuid.UUID ) (Organization , error ) {
@@ -264,34 +250,23 @@ func (c *Client) CreateOrganization(ctx context.Context, req CreateOrganizationR
264
250
// UpdateOrganization will update information about the corresponding organization, based on
265
251
// the UUID/name provided as `orgID`.
266
252
func (c * Client ) UpdateOrganization (ctx context.Context , orgID string , req UpdateOrganizationRequest ) (Organization , error ) {
267
- res , err := c .Request (ctx , http .MethodPatch , fmt .Sprintf ("/api/v2/organizations/%s" , orgID ), req )
268
- if err != nil {
269
- return Organization {}, xerrors .Errorf ("execute request: %w" , err )
270
- }
271
- defer res .Body .Close ()
272
-
273
- if res .StatusCode != http .StatusOK {
274
- return Organization {}, ReadBodyAsError (res )
275
- }
276
-
277
- var organization Organization
278
- return organization , json .NewDecoder (res .Body ).Decode (& organization )
253
+ return makeSDKRequest [Organization ](ctx , c , sdkRequestArgs {
254
+ Method : http .MethodPatch ,
255
+ URL : fmt .Sprintf ("/api/v2/organizations/%s" , orgID ),
256
+ Body : req ,
257
+ ExpectCode : http .StatusOK ,
258
+ })
279
259
}
280
260
281
261
// DeleteOrganization will remove the corresponding organization from the deployment, based on
282
262
// the UUID/name provided as `orgID`.
283
263
func (c * Client ) DeleteOrganization (ctx context.Context , orgID string ) error {
284
- res , err := c .Request (ctx , http .MethodDelete , fmt .Sprintf ("/api/v2/organizations/%s" , orgID ), nil )
285
- if err != nil {
286
- return xerrors .Errorf ("execute request: %w" , err )
287
- }
288
- defer res .Body .Close ()
289
-
290
- if res .StatusCode != http .StatusOK {
291
- return ReadBodyAsError (res )
292
- }
293
-
294
- return nil
264
+ _ , err := makeSDKRequest [noResponse ](ctx , c , sdkRequestArgs {
265
+ Method : http .MethodDelete ,
266
+ URL : fmt .Sprintf ("/api/v2/organizations/%s" , orgID ),
267
+ ExpectCode : http .StatusOK ,
268
+ })
269
+ return err
295
270
}
296
271
297
272
// ProvisionerDaemons returns provisioner daemons available.
@@ -445,44 +420,24 @@ func (f TemplateFilter) asRequestOption() RequestOption {
445
420
446
421
// Templates lists all viewable templates
447
422
func (c * Client ) Templates (ctx context.Context , filter TemplateFilter ) ([]Template , error ) {
448
- res , err := c .Request (ctx , http .MethodGet ,
449
- "/api/v2/templates" ,
450
- nil ,
451
- filter .asRequestOption (),
452
- )
453
- if err != nil {
454
- return nil , xerrors .Errorf ("execute request: %w" , err )
455
- }
456
- defer res .Body .Close ()
457
-
458
- if res .StatusCode != http .StatusOK {
459
- return nil , ReadBodyAsError (res )
460
- }
461
-
462
- var templates []Template
463
- return templates , json .NewDecoder (res .Body ).Decode (& templates )
423
+ return makeSDKRequest [[]Template ](ctx , c , sdkRequestArgs {
424
+ Method : http .MethodGet ,
425
+ URL : "/api/v2/templates" ,
426
+ ExpectCode : http .StatusOK ,
427
+ ReqOpts : []RequestOption {filter .asRequestOption ()},
428
+ })
464
429
}
465
430
466
431
// TemplateByName finds a template inside the organization provided with a case-insensitive name.
467
432
func (c * Client ) TemplateByName (ctx context.Context , organizationID uuid.UUID , name string ) (Template , error ) {
468
433
if name == "" {
469
434
return Template {}, xerrors .Errorf ("template name cannot be empty" )
470
435
}
471
- res , err := c .Request (ctx , http .MethodGet ,
472
- fmt .Sprintf ("/api/v2/organizations/%s/templates/%s" , organizationID .String (), name ),
473
- nil ,
474
- )
475
- if err != nil {
476
- return Template {}, xerrors .Errorf ("execute request: %w" , err )
477
- }
478
- defer res .Body .Close ()
479
-
480
- if res .StatusCode != http .StatusOK {
481
- return Template {}, ReadBodyAsError (res )
482
- }
483
-
484
- var template Template
485
- return template , json .NewDecoder (res .Body ).Decode (& template )
436
+ return makeSDKRequest [Template ](ctx , c , sdkRequestArgs {
437
+ Method : http .MethodGet ,
438
+ URL : fmt .Sprintf ("/api/v2/organizations/%s/templates/%s" , organizationID .String (), name ),
439
+ ExpectCode : http .StatusOK ,
440
+ })
486
441
}
487
442
488
443
// CreateWorkspace creates a new workspace for the template specified.
0 commit comments