feat: add Apps endpoint and query parameter support

- add `Apps` endpoint to the `Client` struct and initialize it in
`NewClient`
- implement `doWithJsonResponse` helper to handle request execution and
JSON decoding in one step
- update `newRequest` to support passing and encoding query parameters
via `net/url`
- rename `Option` to `ClientOption` for better clarity in the
`NewClient` signature
- refactor `Ping` tests to use a more structured nested layout
- remove `option.go` and `option_test.go` as part of the configuration
refactor
This commit is contained in:
Stevan Freeborn
2026-01-15 16:38:47 -06:00
parent 62426530bd
commit 1f6218416c
7 changed files with 339 additions and 89 deletions
+54
View File
@@ -0,0 +1,54 @@
package onspring_test
import (
"net/http"
"testing"
"time"
"github.com/StevanFreeborn/onspring-api-sdk-go"
)
func TestWithHTTPClient(t *testing.T) {
t.Run("it should set a custom HTTP client on the Onsring client", func(t *testing.T) {
customHTTPClient := &http.Client{Timeout: 10 * time.Second}
clientWithCustomHTTP := onspring.NewClient(
"test-api-key",
onspring.WithHTTPClient(customHTTPClient),
)
if clientWithCustomHTTP.HTTPClient() != customHTTPClient {
t.Errorf("Expected custom HTTP client to be set")
}
})
}
func TestWithBaseURL(t *testing.T) {
t.Run("it should set a custom base URL on the Onsring client", func(t *testing.T) {
customBaseURL := "https://custom.onspring.com"
clientWithCustomURL := onspring.NewClient(
"test-api-key",
onspring.WithBaseURL(customBaseURL),
)
if clientWithCustomURL.BaseURL() != customBaseURL {
t.Errorf("Expected base URL to be %s, got %s", customBaseURL, clientWithCustomURL.BaseURL())
}
})
}
func TestWithAPIVersion(t *testing.T) {
t.Run("it should set a custom API version on the Onsring client", func(t *testing.T) {
customVersion := "3.0"
clientWithCustomVersion := onspring.NewClient(
"test-api-key",
onspring.WithAPIVersion(customVersion),
)
if clientWithCustomVersion.APIVersion() != customVersion {
t.Errorf("Expected API version to be %s, got %s", customVersion, clientWithCustomVersion.APIVersion())
}
})
}