Documentation
¶
Index ¶
- type Config
- type Error
- type ErrorDetail
- type MockAPICall
- type MockRequestService
- func (m *MockRequestService) Delete(ctx context.Context, endpoint string) (*Response, error)
- func (m *MockRequestService) Get(ctx context.Context, endpoint string) (*Response, error)
- func (m *MockRequestService) Patch(ctx context.Context, endpoint string, body string) (*Response, error)
- func (m *MockRequestService) Post(ctx context.Context, endpoint string, body string) (*Response, error)
- func (m *MockRequestService) Put(ctx context.Context, endpoint string, body string) (*Response, error)
- func (m *MockRequestService) Reset()
- func (m *MockRequestService) WithAPIError(statusCode int, message string) *MockRequestService
- func (m *MockRequestService) WithError(err error) *MockRequestService
- func (m *MockRequestService) WithGetResponse(statusCode int, body string) *MockRequestService
- func (m *MockRequestService) WithPostResponse(statusCode int, body string) *MockRequestService
- func (m *MockRequestService) WithResponse(statusCode int, body string) *MockRequestService
- type RequestService
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
ClientID string
ClientSecret string
BaseURL string
APIVersion string
Timeout time.Duration // ← moved here from client.go
MaxRetry int // ← moved here from client.go
}
Config holds configuration for the API service
type Error ¶ added in v1.6.0
type Error struct {
StatusCode int `json:"status_code"`
Message string `json:"message"`
Details []ErrorDetail `json:"details,omitempty"`
}
Error represents an error response from the Aura API
func (*Error) HasMultipleErrors ¶ added in v1.6.0
HasMultipleErrors returns true if there are multiple error details
func (*Error) IsBadRequest ¶ added in v1.6.0
IsBadRequest returns true if the error is a 400
func (*Error) IsNotFound ¶ added in v1.6.0
IsNotFound returns true if the error is a 404
func (*Error) IsUnauthorized ¶ added in v1.6.0
IsUnauthorized returns true if the error is a 401
type ErrorDetail ¶ added in v1.6.0
type ErrorDetail struct {
Message string `json:"message"`
Reason string `json:"reason,omitempty"`
Field string `json:"field,omitempty"`
}
ErrorDetail represents individual error details
type MockAPICall ¶
MockAPICall represents a single call to the mock service
type MockRequestService ¶ added in v1.6.0
type MockRequestService struct {
// Default response for all requests
Response *Response
Error error
// Method-specific responses
GetResponse *Response
GetError error
PostResponse *Response
PostError error
PutResponse *Response
PutError error
PatchResponse *Response
PatchError error
DeleteResponse *Response
DeleteError error
// Capture the last request for assertions
LastMethod string
LastEndpoint string
LastBody string
CallCount int
CallHistory []MockAPICall
}
MockRequestService is a mock implementation of RequestService for testing
func NewMockRequestService ¶ added in v1.6.0
func NewMockRequestService() *MockRequestService
NewMockRequestService creates a new mock API request service
func (*MockRequestService) Patch ¶ added in v1.6.0
func (m *MockRequestService) Patch(ctx context.Context, endpoint string, body string) (*Response, error)
Patch implements RequestService.Patch
func (*MockRequestService) Post ¶ added in v1.6.0
func (m *MockRequestService) Post(ctx context.Context, endpoint string, body string) (*Response, error)
Post implements RequestService.Post
func (*MockRequestService) Put ¶ added in v1.6.0
func (m *MockRequestService) Put(ctx context.Context, endpoint string, body string) (*Response, error)
Put implements RequestService.Put
func (*MockRequestService) Reset ¶ added in v1.6.0
func (m *MockRequestService) Reset()
Reset clears all recorded calls and responses
func (*MockRequestService) WithAPIError ¶ added in v1.6.0
func (m *MockRequestService) WithAPIError(statusCode int, message string) *MockRequestService
WithError sets an API error response
func (*MockRequestService) WithError ¶ added in v1.6.0
func (m *MockRequestService) WithError(err error) *MockRequestService
WithError sets the default error for all methods
func (*MockRequestService) WithGetResponse ¶ added in v1.6.0
func (m *MockRequestService) WithGetResponse(statusCode int, body string) *MockRequestService
WithGetResponse sets a specific response for GET requests
func (*MockRequestService) WithPostResponse ¶ added in v1.6.0
func (m *MockRequestService) WithPostResponse(statusCode int, body string) *MockRequestService
WithPostResponse sets a specific response for POST requests
func (*MockRequestService) WithResponse ¶ added in v1.6.0
func (m *MockRequestService) WithResponse(statusCode int, body string) *MockRequestService
WithResponse sets the default response for all methods
type RequestService ¶ added in v1.6.0
type RequestService interface {
Get(ctx context.Context, endpoint string) (*Response, error)
Post(ctx context.Context, endpoint string, body string) (*Response, error)
Put(ctx context.Context, endpoint string, body string) (*Response, error)
Patch(ctx context.Context, endpoint string, body string) (*Response, error)
Delete(ctx context.Context, endpoint string) (*Response, error)
}
RequestService defines the interface for making authenticated API requests. This is the middle layer that handles authentication and common API patterns.
func NewRequestService ¶ added in v1.6.0
func NewRequestService(cfg Config, logger *slog.Logger) RequestService
NewRequestService creates a new RequestService. It constructs its own HTTP transport layer internally — callers do not need to know about or create an httpClient.