diff --git a/.stats.yml b/.stats.yml index 74464d7..a3eeb48 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 20 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nirvana-labs%2Fnirvana-9b0b2954abe182969aa3bff89752c5ef6f9aefe22a6c9333d0047c8b94728d1c.yml +configured_endpoints: 21 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nirvana-labs%2Fnirvana-d34ebbf790173255bdedff7e5d4fe32a6b217c0dd51dee295603872843065848.yml diff --git a/api.md b/api.md index 353f905..dba02fb 100644 --- a/api.md +++ b/api.md @@ -88,6 +88,7 @@ Methods: - client.Volumes.New(ctx context.Context, body volumes.VolumeNewParams) (operations.Operation, error) - client.Volumes.Update(ctx context.Context, volumeID string, body volumes.VolumeUpdateParams) (operations.Operation, error) - client.Volumes.Delete(ctx context.Context, volumeID string, body volumes.VolumeDeleteParams) (operations.Operation, error) +- client.Volumes.Get(ctx context.Context, volumeID string) (volumes.Volume, error) # Operations diff --git a/volumes/volume.go b/volumes/volume.go index 4840b8c..d884380 100644 --- a/volumes/volume.go +++ b/volumes/volume.go @@ -66,6 +66,18 @@ func (r *VolumeService) Delete(ctx context.Context, volumeID string, body Volume return } +// Get a Volume. +func (r *VolumeService) Get(ctx context.Context, volumeID string, opts ...option.RequestOption) (res *Volume, err error) { + opts = append(r.Options[:], opts...) + if volumeID == "" { + err = errors.New("missing required volume_id parameter") + return + } + path := fmt.Sprintf("volumes/%s", volumeID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) + return +} + // Storage type. type StorageType string @@ -83,18 +95,22 @@ func (r StorageType) IsKnown() bool { // Volume details. type Volume struct { - ID string `json:"id,required"` - Size int64 `json:"size,required"` + ID string `json:"id,required"` + CreatedAt string `json:"created_at,required"` + Size int64 `json:"size,required"` // Storage type. - Type StorageType `json:"type,required"` - JSON volumeJSON `json:"-"` + Type StorageType `json:"type,required"` + UpdatedAt string `json:"updated_at,required"` + JSON volumeJSON `json:"-"` } // volumeJSON contains the JSON metadata for the struct [Volume] type volumeJSON struct { ID apijson.Field + CreatedAt apijson.Field Size apijson.Field Type apijson.Field + UpdatedAt apijson.Field raw string ExtraFields map[string]apijson.Field } diff --git a/volumes/volume_test.go b/volumes/volume_test.go index 72c70a7..434231e 100644 --- a/volumes/volume_test.go +++ b/volumes/volume_test.go @@ -96,3 +96,25 @@ func TestVolumeDelete(t *testing.T) { t.Fatalf("err should be nil: %s", err.Error()) } } + +func TestVolumeGet(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := nirvana.NewClient( + option.WithBaseURL(baseURL), + option.WithAuthToken("My Auth Token"), + ) + _, err := client.Volumes.Get(context.TODO(), "volume_id") + if err != nil { + var apierr *nirvana.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +}