From 7d77591839a2c8de115a2649cd9266f084f3778b Mon Sep 17 00:00:00 2001 From: Giannis Katsanos Date: Thu, 8 Feb 2024 15:48:45 +0200 Subject: [PATCH] feat: Proxy Checks API Added support for the Proxy Checks API and the Create operation. --- proxy_check.go | 13 ++++++++++++ proxycheck/api.go | 21 +++++++++++++++++++ proxycheck/client.go | 43 +++++++++++++++++++++++++++++++++++++++ proxycheck/client_test.go | 40 ++++++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 proxy_check.go create mode 100644 proxycheck/api.go create mode 100644 proxycheck/client.go create mode 100644 proxycheck/client_test.go diff --git a/proxy_check.go b/proxy_check.go new file mode 100644 index 00000000..f08f6b61 --- /dev/null +++ b/proxy_check.go @@ -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"` +} diff --git a/proxycheck/api.go b/proxycheck/api.go new file mode 100644 index 00000000..537c444b --- /dev/null +++ b/proxycheck/api.go @@ -0,0 +1,21 @@ +// Code generated by "gen"; DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. +// Last generated at 2024-02-08 13:48:28.874404424 +0000 UTC +package proxycheck + +import ( + "context" + + "github.com/clerk/clerk-sdk-go/v2" +) + +// Create creates a proxy check. +func Create(ctx context.Context, params *CreateParams) (*clerk.ProxyCheck, error) { + return getClient().Create(ctx, params) +} + +func getClient() *Client { + return &Client{ + Backend: clerk.GetBackend(), + } +} diff --git a/proxycheck/client.go b/proxycheck/client.go new file mode 100644 index 00000000..729a57d0 --- /dev/null +++ b/proxycheck/client.go @@ -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 +} diff --git a/proxycheck/client_test.go b/proxycheck/client_test.go new file mode 100644 index 00000000..e86a57c7 --- /dev/null +++ b/proxycheck/client_test.go @@ -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) +}