Skip to content

Commit

Permalink
chore: Adress PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNti committed Nov 14, 2024
1 parent a456a12 commit fa536ca
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
16 changes: 8 additions & 8 deletions oauthapplication/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions oauthapplication/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package oauthapplication
import (
"context"
"net/http"
"net/url"

"github.com/clerk/clerk-sdk-go/v2"
)
Expand Down Expand Up @@ -39,7 +40,12 @@ type ListParams struct {
clerk.ListParams
}

// List retrieve all OAuth applications.
func (params *ListParams) ToQuery() url.Values {
q := params.ListParams.ToQuery()
return q
}

// List retrieves all OAuth applications.
func (c *Client) List(ctx context.Context, params *ListParams) (*clerk.OAuthApplicationList, error) {
req := clerk.NewAPIRequest(http.MethodGet, path)
req.SetParams(params)
Expand All @@ -48,32 +54,32 @@ func (c *Client) List(ctx context.Context, params *ListParams) (*clerk.OAuthAppl
return list, err
}

type OAuthApplicationCreateParams struct {
type CreateParams struct {
clerk.APIParams
Name string `json:"name"`
CallbackURL string `json:"callback_url"`
Scopes string `json:"scopes"`
Public bool `json:"public"`
}

// Creates a new OAuth application with the given parameters.
func (c *Client) Create(ctx context.Context, params *OAuthApplicationCreateParams) (*clerk.OAuthApplication, error) {
// Create creates a new OAuth application with the given parameters.
func (c *Client) Create(ctx context.Context, params *CreateParams) (*clerk.OAuthApplication, error) {
req := clerk.NewAPIRequest(http.MethodPost, path)
req.SetParams(params)
authApplication := &clerk.OAuthApplication{}
err := c.Backend.Call(ctx, req, authApplication)
return authApplication, err
}

type OAuthApplicationUpdateParams struct {
type UpdateParams struct {
clerk.APIParams
Name *string `json:"name,omitempty"`
CallbackURL *string `json:"callback_url,omitempty"`
Scopes *string `json:"scopes,omitempty"`
}

// Update update an existing OAuth application.
func (c *Client) Update(ctx context.Context, id string, params *OAuthApplicationUpdateParams) (*clerk.OAuthApplication, error) {
// Update updates an existing OAuth application.
func (c *Client) Update(ctx context.Context, id string, params *UpdateParams) (*clerk.OAuthApplication, error) {
path, err := clerk.JoinPath(path, id)
if err != nil {
return nil, err
Expand All @@ -85,7 +91,7 @@ func (c *Client) Update(ctx context.Context, id string, params *OAuthApplication
return authApplication, err
}

// Delete delete the given OAuth application
// Delete deletes the given OAuth application
func (c *Client) DeleteOAuthApplication(ctx context.Context, id string) (*clerk.DeletedResource, error) {
path, err := clerk.JoinPath(path, id)
if err != nil {
Expand All @@ -97,7 +103,7 @@ func (c *Client) DeleteOAuthApplication(ctx context.Context, id string) (*clerk.
return authApplication, err
}

// RotateClientSecret rotate the OAuth application's client secret
// RotateClientSecret rotates the OAuth application's client secret
func (c *Client) RotateClientSecret(ctx context.Context, id string) (*clerk.OAuthApplication, error) {
path, err := clerk.JoinPath(path, id, "rotate_secret")
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions oauthapplication/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestOAuthApplicationClientCreate(t *testing.T) {
}
client := NewClient(config)

params := &OAuthApplicationCreateParams{
params := &CreateParams{
Name: name,
CallbackURL: callbackURL,
Scopes: scopes,
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestOrganizationClientCreate_Error(t *testing.T) {
},
}
client := NewClient(config)
_, err := client.Create(context.Background(), &OAuthApplicationCreateParams{})
_, err := client.Create(context.Background(), &CreateParams{})
require.Error(t, err)
apiErr, ok := err.(*clerk.APIErrorResponse)
require.True(t, ok)
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestOAuthApplicationClientUpdate(t *testing.T) {
}

client := NewClient(config)
params := &OAuthApplicationUpdateParams{
params := &UpdateParams{
Name: clerk.String(updatedName),
CallbackURL: clerk.String(callbackURL),
}
Expand All @@ -148,7 +148,7 @@ func TestOrganizationClientUpdate_Error(t *testing.T) {
},
}
client := NewClient(config)
_, err := client.Update(context.Background(), "oauth_123", &OAuthApplicationUpdateParams{})
_, err := client.Update(context.Background(), "oauth_123", &UpdateParams{})
require.Error(t, err)
apiErr, ok := err.(*clerk.APIErrorResponse)
require.True(t, ok)
Expand Down

0 comments on commit fa536ca

Please sign in to comment.