api

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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) AllErrors added in v1.6.0

func (e *Error) AllErrors() []string

AllErrors returns all error messages as a slice

func (*Error) Error added in v1.6.0

func (e *Error) Error() string

Error implements the error interface

func (*Error) HasMultipleErrors added in v1.6.0

func (e *Error) HasMultipleErrors() bool

HasMultipleErrors returns true if there are multiple error details

func (*Error) IsBadRequest added in v1.6.0

func (e *Error) IsBadRequest() bool

IsBadRequest returns true if the error is a 400

func (*Error) IsNotFound added in v1.6.0

func (e *Error) IsNotFound() bool

IsNotFound returns true if the error is a 404

func (*Error) IsUnauthorized added in v1.6.0

func (e *Error) IsUnauthorized() bool

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

type MockAPICall struct {
	Method   string
	Endpoint string
	Body     string
}

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) Delete added in v1.6.0

func (m *MockRequestService) Delete(ctx context.Context, endpoint string) (*Response, error)

Delete implements RequestService.Delete

func (*MockRequestService) Get added in v1.6.0

func (m *MockRequestService) Get(ctx context.Context, endpoint string) (*Response, error)

Get implements RequestService.Get

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.

type Response added in v1.6.0

type Response struct {
	StatusCode int
	Body       []byte
}

Response represents a response from the Aura API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL