- 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
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package onspring
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
)
|
|
|
|
const (
|
|
// pingPath is the API endpoint path for the ping health check.
|
|
pingPath = "/ping"
|
|
)
|
|
|
|
// PingEndpoint provides access to the Onspring API ping endpoint.
|
|
// It can be used to verify API connectivity and authentication.
|
|
type PingEndpoint struct {
|
|
// client is the parent Client used to make API requests.
|
|
client *Client
|
|
}
|
|
|
|
// Get performs a ping request to verify API connectivity.
|
|
// This is a simple health check that can be used to test if the API is
|
|
// reachable.
|
|
//
|
|
// Parameters:
|
|
// - ctx: The context for the request
|
|
//
|
|
// Returns:
|
|
// - error: nil if the ping succeeds, or an error if the request fails
|
|
// or authentication is invalid
|
|
//
|
|
// Example:
|
|
//
|
|
// client := onspring.NewClient("your-api-key")
|
|
// err := client.Ping.Get(context.Background())
|
|
// if err != nil {
|
|
// log.Fatal("Ping failed:", err)
|
|
// }
|
|
func (p *PingEndpoint) Get(ctx context.Context) error {
|
|
req, err := p.client.newRequest(ctx, http.MethodGet, pingPath, nil, nil)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return p.client.do(req)
|
|
}
|