Skip to content

Commit

Permalink
feat(api): api update (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Jan 24, 2025
1 parent 15db661 commit 3e1fc4b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Methods:
- <code title="post /volumes">client.Volumes.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes#VolumeService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes">volumes</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes#VolumeNewParams">VolumeNewParams</a>) (<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/operations">operations</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/operations#Operation">Operation</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="patch /volumes/{volume_id}">client.Volumes.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes#VolumeService.Update">Update</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, volumeID <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes">volumes</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes#VolumeUpdateParams">VolumeUpdateParams</a>) (<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/operations">operations</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/operations#Operation">Operation</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="delete /volumes/{volume_id}">client.Volumes.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes#VolumeService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, volumeID <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes">volumes</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes#VolumeDeleteParams">VolumeDeleteParams</a>) (<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/operations">operations</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/operations#Operation">Operation</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /volumes/{volume_id}">client.Volumes.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes#VolumeService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, volumeID <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes">volumes</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/volumes#Volume">Volume</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

# Operations

Expand Down
24 changes: 20 additions & 4 deletions volumes/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
Expand Down
22 changes: 22 additions & 0 deletions volumes/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

0 comments on commit 3e1fc4b

Please sign in to comment.