Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored May 14, 2024
1 parent 27ed461 commit 9621839
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 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: 1
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/terminal%2Fterminal-3946ee3c8d25d3f5012a5d5ea441d99ec260b925a70bb7dd8a614101d4a3f482.yml
configured_endpoints: 2
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/terminal%2Fterminal-f4a3aca8ff2474533240c82b76ea4f1f7870485abbbf7d8d4caccc707f1a506d.yml
9 changes: 9 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ Methods:
- <code title="get /product">client.Product.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#ProductService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) (<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go">terminal</a>.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#ProductListResponse">ProductListResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

# User

Response Types:

- <a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go">terminal</a>.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#User">User</a>
- <a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go">terminal</a>.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#UserGetResponse">UserGetResponse</a>

Methods:

- <code title="get /user/{id}">client.User.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#UserService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go">terminal</a>.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#UserGetResponse">UserGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
57 changes: 57 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
package terminal

import (
"context"
"fmt"
"net/http"

"github.com/terminaldotshop/terminal-sdk-go/internal/apijson"
"github.com/terminaldotshop/terminal-sdk-go/internal/requestconfig"
"github.com/terminaldotshop/terminal-sdk-go/option"
)

Expand All @@ -24,3 +30,54 @@ func NewUserService(opts ...option.RequestOption) (r *UserService) {
r.Options = opts
return
}

func (r *UserService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *UserGetResponse, err error) {
opts = append(r.Options[:], opts...)
path := fmt.Sprintf("user/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}

type User struct {
ID string `json:"id,required"`
Email string `json:"email,required,nullable"`
Fingerprint string `json:"fingerprint,required"`
JSON userJSON `json:"-"`
}

// userJSON contains the JSON metadata for the struct [User]
type userJSON struct {
ID apijson.Field
Email apijson.Field
Fingerprint apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *User) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r userJSON) RawJSON() string {
return r.raw
}

type UserGetResponse struct {
Result User `json:"result,required"`
JSON userGetResponseJSON `json:"-"`
}

// userGetResponseJSON contains the JSON metadata for the struct [UserGetResponse]
type userGetResponseJSON struct {
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *UserGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r userGetResponseJSON) RawJSON() string {
return r.raw
}
36 changes: 36 additions & 0 deletions user_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package terminal_test

import (
"context"
"errors"
"os"
"testing"

"github.com/terminaldotshop/terminal-sdk-go"
"github.com/terminaldotshop/terminal-sdk-go/internal/testutil"
"github.com/terminaldotshop/terminal-sdk-go/option"
)

func TestUserGet(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 := terminal.NewClient(
option.WithBaseURL(baseURL),
option.WithBearerToken("My Bearer Token"),
)
_, err := client.User.Get(context.TODO(), "string")
if err != nil {
var apierr *terminal.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 9621839

Please sign in to comment.