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: Proxy Checks API #233

Merged
merged 1 commit into from
Feb 8, 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
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)
}
Loading