Skip to content

Commit

Permalink
feat: Proxy Checks API (#233)
Browse files Browse the repository at this point in the history
Added support for the Proxy Checks API and the Create operation.
  • Loading branch information
gkats authored Feb 8, 2024
1 parent a4d27b1 commit ff3e770
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
13 changes: 13 additions & 0 deletions proxy_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package clerk

type ProxyCheck struct {
APIResource
Object string `json:"object"`
ID string `json:"id"`
DomainID string `json:"domain_id"`
ProxyURL string `json:"proxy_url"`
Successful bool `json:"successful"`
LastRunAt *int64 `json:"last_run_at"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
21 changes: 21 additions & 0 deletions proxycheck/api.go

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

43 changes: 43 additions & 0 deletions proxycheck/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Package proxycheck provides the Proxy Checks API.
package proxycheck

import (
"context"
"net/http"

"github.com/clerk/clerk-sdk-go/v2"
)

//go:generate go run ../cmd/gen/main.go

const path = "/proxy_checks"

// Client is used to invoke the Proxy Checks API.
type Client struct {
Backend clerk.Backend
}

type ClientConfig struct {
clerk.BackendConfig
}

func NewClient(config *ClientConfig) *Client {
return &Client{
Backend: clerk.NewBackend(&config.BackendConfig),
}
}

type CreateParams struct {
clerk.APIParams
DomainID *string `json:"domain_id,omitempty"`
ProxyURL *string `json:"proxy_url,omitempty"`
}

// Create creates a proxy check.
func (c *Client) Create(ctx context.Context, params *CreateParams) (*clerk.ProxyCheck, error) {
req := clerk.NewAPIRequest(http.MethodPost, path)
req.SetParams(params)
resource := &clerk.ProxyCheck{}
err := c.Backend.Call(ctx, req, resource)
return resource, err
}
40 changes: 40 additions & 0 deletions proxycheck/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package proxycheck

import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"

"github.com/clerk/clerk-sdk-go/v2"
"github.com/clerk/clerk-sdk-go/v2/clerktest"
"github.com/stretchr/testify/require"
)

func TestProxyCheckClientCreate(t *testing.T) {
t.Parallel()
id := "proxchk_123"
proxyURL := "https://clerk.com/__proxy"
domainID := "dmn_123"
config := &ClientConfig{}
config.HTTPClient = &http.Client{
Transport: &clerktest.RoundTripper{
T: t,
In: json.RawMessage(fmt.Sprintf(`{"domain_id":"%s","proxy_url":"%s"}`, domainID, proxyURL)),
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","domain_id":"%s","proxy_url":"%s","successful":true}`, id, domainID, proxyURL)),
Method: http.MethodPost,
Path: "/v1/proxy_checks",
},
}
client := NewClient(config)
proxyCheck, err := client.Create(context.Background(), &CreateParams{
ProxyURL: clerk.String(proxyURL),
DomainID: clerk.String(domainID),
})
require.NoError(t, err)
require.Equal(t, id, proxyCheck.ID)
require.Equal(t, proxyURL, proxyCheck.ProxyURL)
require.Equal(t, domainID, proxyCheck.DomainID)
require.True(t, proxyCheck.Successful)
}

0 comments on commit ff3e770

Please sign in to comment.