Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): manual updates #174

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 27
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/terminal%2Fterminal-967b257f759fb4b78a7b5b5803f8f51fc92d1b42bc3aec78f57dfac2ce599d66.yml
configured_endpoints: 29
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/terminal%2Fterminal-168780e70e1a37038f9208c6e92cb9271ef973ce745a17fb4a148aaa3e2ed2d1.yml
10 changes: 9 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Response Types:

Methods:

- <code title="put /subscription">client.Subscription.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#SubscriptionService.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/terminaldotshop/terminal-sdk-go">terminal</a>.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#SubscriptionNewParams">SubscriptionNewParams</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#SubscriptionNewResponse">SubscriptionNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="post /subscription">client.Subscription.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#SubscriptionService.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/terminaldotshop/terminal-sdk-go">terminal</a>.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#SubscriptionNewParams">SubscriptionNewParams</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#SubscriptionNewResponse">SubscriptionNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /subscription">client.Subscription.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#SubscriptionService.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#SubscriptionListResponse">SubscriptionListResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="delete /subscription/{id}">client.Subscription.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#SubscriptionService.Delete">Delete</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#SubscriptionDeleteResponse">SubscriptionDeleteResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

Expand All @@ -109,27 +109,35 @@ Methods:
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#Token">Token</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#TokenNewResponse">TokenNewResponse</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#TokenListResponse">TokenListResponse</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#TokenDeleteResponse">TokenDeleteResponse</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#TokenGetResponse">TokenGetResponse</a>

Methods:

- <code title="post /token">client.Token.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#TokenService.New">New</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#TokenNewResponse">TokenNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /token">client.Token.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#TokenService.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#TokenListResponse">TokenListResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="delete /token/{id}">client.Token.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#TokenService.Delete">Delete</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#TokenDeleteResponse">TokenDeleteResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /token/{id}">client.Token.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#TokenService.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#TokenGetResponse">TokenGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

# App

Params 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#AppParam">AppParam</a>

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#App">App</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#AppNewResponse">AppNewResponse</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#AppListResponse">AppListResponse</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#AppDeleteResponse">AppDeleteResponse</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#AppGetResponse">AppGetResponse</a>

Methods:

- <code title="post /app">client.App.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#AppService.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/terminaldotshop/terminal-sdk-go">terminal</a>.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#AppNewParams">AppNewParams</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#AppNewResponse">AppNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /app">client.App.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#AppService.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#AppListResponse">AppListResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="delete /app/{id}">client.App.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#AppService.Delete">Delete</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#AppDeleteResponse">AppDeleteResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /app/{id}">client.App.<a href="https://pkg.go.dev/github.com/terminaldotshop/terminal-sdk-go#AppService.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#AppGetResponse">AppGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
Expand Down
77 changes: 77 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"

"github.com/terminaldotshop/terminal-sdk-go/internal/apijson"
"github.com/terminaldotshop/terminal-sdk-go/internal/param"
"github.com/terminaldotshop/terminal-sdk-go/internal/requestconfig"
"github.com/terminaldotshop/terminal-sdk-go/option"
)
Expand All @@ -32,6 +33,14 @@ func NewAppService(opts ...option.RequestOption) (r *AppService) {
return
}

// Create an app.
func (r *AppService) New(ctx context.Context, body AppNewParams, opts ...option.RequestOption) (res *AppNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "app"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}

// List the current user's registered apps.
func (r *AppService) List(ctx context.Context, opts ...option.RequestOption) (res *AppListResponse, err error) {
opts = append(r.Options[:], opts...)
Expand Down Expand Up @@ -92,6 +101,65 @@ func (r appJSON) RawJSON() string {
return r.raw
}

// A Terminal App used for configuring an OAuth 2.0 client.
type AppParam struct {
// Unique object identifier. The format and length of IDs may change over time.
ID param.Field[string] `json:"id,required"`
// Name of the app.
Name param.Field[string] `json:"name,required"`
// Redirect URI of the app.
RedirectUri param.Field[string] `json:"redirectURI,required"`
}

func (r AppParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type AppNewResponse struct {
Data AppNewResponseData `json:"data,required"`
JSON appNewResponseJSON `json:"-"`
}

// appNewResponseJSON contains the JSON metadata for the struct [AppNewResponse]
type appNewResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

type AppNewResponseData struct {
// OAuth 2.0 client ID.
ID string `json:"id,required"`
// OAuth 2.0 client secret.
Secret string `json:"secret,required"`
JSON appNewResponseDataJSON `json:"-"`
}

// appNewResponseDataJSON contains the JSON metadata for the struct
// [AppNewResponseData]
type appNewResponseDataJSON struct {
ID apijson.Field
Secret apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

type AppListResponse struct {
// List of apps.
Data []App `json:"data,required"`
Expand Down Expand Up @@ -168,3 +236,12 @@ func (r *AppGetResponse) UnmarshalJSON(data []byte) (err error) {
func (r appGetResponseJSON) RawJSON() string {
return r.raw
}

type AppNewParams struct {
// A Terminal App used for configuring an OAuth 2.0 client.
App AppParam `json:"app,required"`
}

func (r AppNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.App)
}
28 changes: 28 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@ import (
"github.com/terminaldotshop/terminal-sdk-go/option"
)

func TestAppNew(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.App.New(context.TODO(), terminal.AppNewParams{
App: terminal.AppParam{
ID: terminal.F("cli_XXXXXXXXXXXXXXXXXXXXXXXXX"),
Name: terminal.F("Example App"),
RedirectUri: terminal.F("https://example.com/callback"),
},
})
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())
}
}

func TestAppList(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
Expand Down
2 changes: 1 addition & 1 deletion subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewSubscriptionService(opts ...option.RequestOption) (r *SubscriptionServic
func (r *SubscriptionService) New(ctx context.Context, body SubscriptionNewParams, opts ...option.RequestOption) (res *SubscriptionNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "subscription"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, body, &res, opts...)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}

Expand Down
55 changes: 55 additions & 0 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ func NewTokenService(opts ...option.RequestOption) (r *TokenService) {
return
}

// Create a personal access token.
func (r *TokenService) New(ctx context.Context, opts ...option.RequestOption) (res *TokenNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "token"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}

// List the current user's personal access tokens.
func (r *TokenService) List(ctx context.Context, opts ...option.RequestOption) (res *TokenListResponse, err error) {
opts = append(r.Options[:], opts...)
Expand Down Expand Up @@ -115,6 +123,53 @@ func (r tokenTimeJSON) RawJSON() string {
return r.raw
}

type TokenNewResponse struct {
Data TokenNewResponseData `json:"data,required"`
JSON tokenNewResponseJSON `json:"-"`
}

// tokenNewResponseJSON contains the JSON metadata for the struct
// [TokenNewResponse]
type tokenNewResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

type TokenNewResponseData struct {
// Personal token ID.
ID string `json:"id,required"`
// Personal access token. Include this in the Authorization header
// (`Bearer <token>`) when accessing the Terminal API.
Token string `json:"token,required"`
JSON tokenNewResponseDataJSON `json:"-"`
}

// tokenNewResponseDataJSON contains the JSON metadata for the struct
// [TokenNewResponseData]
type tokenNewResponseDataJSON struct {
ID apijson.Field
Token apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

type TokenListResponse struct {
// List of personal access tokens.
Data []Token `json:"data,required"`
Expand Down
22 changes: 22 additions & 0 deletions token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ import (
"github.com/terminaldotshop/terminal-sdk-go/option"
)

func TestTokenNew(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.Token.New(context.TODO())
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())
}
}

func TestTokenList(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
Expand Down