Documentation
¶
Overview ¶
Package ring provides the main client for interacting with Ring services. It orchestrates authentication, API clients (REST), and event connections.
Package ring provides the main client for interacting with Ring services. This file defines the Client interface for dependency injection and testing.
Index ¶
- type AuthenticateRequest
- type Client
- func (c *Client) Apply(opts ...Option) error
- func (c *Client) Authenticate(ctx context.Context, req AuthenticateRequest) (*ringapimodels.AuthResponse, error)
- func (c *Client) Close() error
- func (c *Client) ConnectEvents(ctx context.Context) (*EventConnection, error)
- func (c *Client) GetActiveDings(ctx context.Context) (*ringapimodels.RecordingHistoryResponse, error)
- func (c *Client) GetDevice(ctx context.Context, req GetDeviceRequest) (ringapimodels.Device, error)
- func (c *Client) GetDeviceHistory(ctx context.Context, req GetDeviceHistoryRequest) (*ringapimodels.RecordingHistoryResponse, error)
- func (c *Client) GetLastRecordingID(ctx context.Context, req GetLastRecordingIDRequest) (int64, error)
- func (c *Client) GetRecording(ctx context.Context, req GetRecordingRequest) (*ringapimodels.VideoStream, error)
- func (c *Client) ListDevices(ctx context.Context) (*ringapimodels.DevicesResponse, error)
- func (c *Client) Listen(ctx context.Context, callback ringapimodels.EventCallback) error
- func (c *Client) RefreshToken(ctx context.Context, req RefreshTokenRequest) (*ringapimodels.AuthResponse, error)
- func (c *Client) Request2FACode(ctx context.Context, req Request2FACodeRequest) error
- func (c *Client) SetInHomeChime(ctx context.Context, req SetInHomeChimeRequest) error
- func (c *Client) SetLights(ctx context.Context, req SetLightsRequest) error
- func (c *Client) SetMotionDetection(ctx context.Context, req SetMotionDetectionRequest) error
- func (c *Client) SetVolume(ctx context.Context, req SetVolumeRequest) error
- func (c *Client) StartRTCStream(ctx context.Context, req StartRTCStreamRequest) (*RTCStream, error)
- func (c *Client) StopRTCStream(ctx context.Context, req StopRTCStreamRequest) error
- func (c *Client) TestSound(ctx context.Context, req TestSoundRequest) error
- func (c *Client) UpdateDeviceHealth(ctx context.Context, req UpdateDeviceHealthRequest) (*ringapimodels.DeviceHealth, error)
- type ClientInterface
- type EventConnection
- type GetDeviceHistoryRequest
- type GetDeviceRequest
- type GetLastRecordingIDRequest
- type GetRecordingRequest
- type Option
- func WithAccessToken(token string) Option
- func WithEventWebSocketURL(url string) Option
- func WithHTTPClient(httpClient *http.Client) Option
- func WithHardwareID(hardwareID string) Option
- func WithPassword(password string) Option
- func WithRTCWebSocketURL(url string) Option
- func WithRefreshToken(refreshToken string) Option
- func WithTokenGetter(getter func(ctx context.Context) (string, error)) Option
- func WithUserAgent(userAgent string) Option
- func WithUsername(username string) Option
- type RTCStream
- type RefreshTokenRequest
- type Request2FACodeRequest
- type SetInHomeChimeRequest
- type SetLightsRequest
- type SetMotionDetectionRequest
- type SetVolumeRequest
- type StartRTCStreamRequest
- type StopRTCStreamRequest
- type TestSoundRequest
- type UpdateDeviceHealthRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthenticateRequest ¶
AuthenticateRequest contains parameters for Authenticate
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main client for interacting with Ring services
func NewClientWithToken ¶
NewClientWithToken creates a client with an access token (convenience function)
func (*Client) Authenticate ¶
func (c *Client) Authenticate(ctx context.Context, req AuthenticateRequest) (*ringapimodels.AuthResponse, error)
Authenticate performs full authentication flow with username/password If 2FA is required, it will return a Requires2FAError
func (*Client) ConnectEvents ¶
func (c *Client) ConnectEvents(ctx context.Context) (*EventConnection, error)
ConnectEvents establishes a WebSocket connection for receiving events This is a wrapper that calls the internal ConnectEvents method
func (*Client) GetActiveDings ¶
func (c *Client) GetActiveDings(ctx context.Context) (*ringapimodels.RecordingHistoryResponse, error)
GetActiveDings retrieves currently active dings
func (*Client) GetDevice ¶
func (c *Client) GetDevice(ctx context.Context, req GetDeviceRequest) (ringapimodels.Device, error)
GetDevice retrieves a specific device by ID
func (*Client) GetDeviceHistory ¶
func (c *Client) GetDeviceHistory(ctx context.Context, req GetDeviceHistoryRequest) (*ringapimodels.RecordingHistoryResponse, error)
GetDeviceHistory retrieves the history of recordings for a device
func (*Client) GetLastRecordingID ¶
func (c *Client) GetLastRecordingID(ctx context.Context, req GetLastRecordingIDRequest) (int64, error)
GetLastRecordingID retrieves the ID of the most recent recording for a device
func (*Client) GetRecording ¶
func (c *Client) GetRecording(ctx context.Context, req GetRecordingRequest) (*ringapimodels.VideoStream, error)
GetRecording retrieves a video stream for a recording
func (*Client) ListDevices ¶
func (c *Client) ListDevices(ctx context.Context) (*ringapimodels.DevicesResponse, error)
ListDevices retrieves all devices associated with the account
func (*Client) Listen ¶
func (c *Client) Listen(ctx context.Context, callback ringapimodels.EventCallback) error
Listen listens for events and calls the callback for each event
func (*Client) RefreshToken ¶
func (c *Client) RefreshToken(ctx context.Context, req RefreshTokenRequest) (*ringapimodels.AuthResponse, error)
RefreshToken refreshes an access token using a refresh token
func (*Client) Request2FACode ¶
func (c *Client) Request2FACode(ctx context.Context, req Request2FACodeRequest) error
Request2FACode requests a 2FA code by attempting authentication
func (*Client) SetInHomeChime ¶
func (c *Client) SetInHomeChime(ctx context.Context, req SetInHomeChimeRequest) error
SetInHomeChime sets in-home chime settings for a doorbell req.Settings can include: "type" (e.g., "Mechanical"), "enabled" (bool), "duration" (int)
func (*Client) SetLights ¶
func (c *Client) SetLights(ctx context.Context, req SetLightsRequest) error
SetLights sets the lights for a device (floodlight cams) req.State can be "on" or "off" req.Duration is optional and specifies how long to keep lights on (in seconds)
func (*Client) SetMotionDetection ¶
func (c *Client) SetMotionDetection(ctx context.Context, req SetMotionDetectionRequest) error
SetMotionDetection sets motion detection for a device
func (*Client) SetVolume ¶
func (c *Client) SetVolume(ctx context.Context, req SetVolumeRequest) error
SetVolume sets the volume for a device
func (*Client) StartRTCStream ¶
StartRTCStream starts a WebRTC stream for live video from a device req.SDPOffer is the SDP offer from the caller
func (*Client) StopRTCStream ¶
func (c *Client) StopRTCStream(ctx context.Context, req StopRTCStreamRequest) error
StopRTCStream stops an active RTC stream
func (*Client) TestSound ¶
func (c *Client) TestSound(ctx context.Context, req TestSoundRequest) error
TestSound tests a sound on a chime device req.Kind can be "ding" or "motion"
func (*Client) UpdateDeviceHealth ¶
func (c *Client) UpdateDeviceHealth(ctx context.Context, req UpdateDeviceHealthRequest) (*ringapimodels.DeviceHealth, error)
UpdateDeviceHealth refreshes health data for a device
type ClientInterface ¶
type ClientInterface interface {
// Authenticate performs full authentication flow with username/password
Authenticate(ctx context.Context, req AuthenticateRequest) (*ringapimodels.AuthResponse, error)
// Request2FACode requests a 2FA code by attempting authentication
Request2FACode(ctx context.Context, req Request2FACodeRequest) error
// RefreshToken refreshes an access token using a refresh token
RefreshToken(ctx context.Context, req RefreshTokenRequest) (*ringapimodels.AuthResponse, error)
// ListDevices retrieves all devices associated with the account
ListDevices(ctx context.Context) (*ringapimodels.DevicesResponse, error)
// GetDevice retrieves a specific device by ID
GetDevice(ctx context.Context, req GetDeviceRequest) (ringapimodels.Device, error)
// UpdateDeviceHealth refreshes health data for a device
UpdateDeviceHealth(ctx context.Context, req UpdateDeviceHealthRequest) (*ringapimodels.DeviceHealth, error)
// SetVolume sets the volume for a device
SetVolume(ctx context.Context, req SetVolumeRequest) error
// SetLights sets the lights for a device (floodlight cams)
SetLights(ctx context.Context, req SetLightsRequest) error
// SetMotionDetection sets motion detection for a device
SetMotionDetection(ctx context.Context, req SetMotionDetectionRequest) error
// TestSound tests a sound on a chime device
TestSound(ctx context.Context, req TestSoundRequest) error
// SetInHomeChime sets in-home chime settings for a doorbell
SetInHomeChime(ctx context.Context, req SetInHomeChimeRequest) error
// ConnectEvents establishes a WebSocket connection for receiving events
ConnectEvents(ctx context.Context) (*EventConnection, error)
// Listen listens for events and calls the callback for each event
Listen(ctx context.Context, callback ringapimodels.EventCallback) error
// GetDeviceHistory retrieves the history of recordings for a device
GetDeviceHistory(ctx context.Context, req GetDeviceHistoryRequest) (*ringapimodels.RecordingHistoryResponse, error)
// GetActiveDings retrieves currently active dings
GetActiveDings(ctx context.Context) (*ringapimodels.RecordingHistoryResponse, error)
// GetRecording retrieves a video stream for a recording
GetRecording(ctx context.Context, req GetRecordingRequest) (*ringapimodels.VideoStream, error)
// GetLastRecordingID retrieves the ID of the most recent recording for a device
GetLastRecordingID(ctx context.Context, req GetLastRecordingIDRequest) (int64, error)
// StartRTCStream starts a WebRTC stream for live video from a device
// req.SDPOffer is the SDP offer from the caller
StartRTCStream(ctx context.Context, req StartRTCStreamRequest) (*RTCStream, error)
// StopRTCStream stops an active RTC stream
StopRTCStream(ctx context.Context, req StopRTCStreamRequest) error
// Close closes the client and all connections
Close() error
}
ClientInterface defines the interface for the Ring client.
type EventConnection ¶
type EventConnection struct {
// contains filtered or unexported fields
}
EventConnection represents a WebSocket connection for receiving events
func (*EventConnection) Close ¶
func (ec *EventConnection) Close() error
Close closes the event connection
func (*EventConnection) Receive ¶
func (ec *EventConnection) Receive() (*ringapimodels.Event, error)
Receive receives an event from the connection
type GetDeviceHistoryRequest ¶
GetDeviceHistoryRequest contains parameters for GetDeviceHistory
type GetDeviceRequest ¶
type GetDeviceRequest struct {
DeviceID string
}
GetDeviceRequest contains parameters for GetDevice
type GetLastRecordingIDRequest ¶
type GetLastRecordingIDRequest struct {
DeviceID string
}
GetLastRecordingIDRequest contains parameters for GetLastRecordingID
type GetRecordingRequest ¶
type GetRecordingRequest struct {
RecordingID int64
}
GetRecordingRequest contains parameters for GetRecording
type Option ¶
Option is a function that configures a Client
func WithAccessToken ¶
WithAccessToken creates a client with an access token
func WithEventWebSocketURL ¶
WithEventWebSocketURL configures the event endpoint, including local test servers. The default vendor endpoint is experimental; callers must verify vendor support.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client for REST API calls.
func WithHardwareID ¶
WithHardwareID sets the hardware ID for authentication
func WithPassword ¶
WithPassword sets the password for authentication
func WithRTCWebSocketURL ¶
WithRTCWebSocketURL sets a custom websocket URL for RTC streams (useful for testing)
func WithRefreshToken ¶
WithRefreshToken creates a client with a refresh token
func WithTokenGetter ¶
WithTokenGetter sets a function to retrieve tokens dynamically
func WithUserAgent ¶
WithUserAgent sets a custom user agent
func WithUsername ¶
WithUsername sets the username for authentication
type RTCStream ¶
type RTCStream struct {
// contains filtered or unexported fields
}
RTCStream represents an active RTC stream
func (*RTCStream) GetDeviceID ¶
GetDeviceID returns the device ID
func (*RTCStream) GetSDPAnswer ¶
GetSDPAnswer returns the SDP answer
func (*RTCStream) GetStreamID ¶
GetStreamID returns the stream ID (session ID)
type RefreshTokenRequest ¶
type RefreshTokenRequest struct {
RefreshToken string
}
RefreshTokenRequest contains parameters for RefreshToken
type Request2FACodeRequest ¶
Request2FACodeRequest contains parameters for Request2FACode
type SetInHomeChimeRequest ¶
SetInHomeChimeRequest contains parameters for SetInHomeChime
type SetLightsRequest ¶
SetLightsRequest contains parameters for SetLights
type SetMotionDetectionRequest ¶
SetMotionDetectionRequest contains parameters for SetMotionDetection
type SetVolumeRequest ¶
SetVolumeRequest contains parameters for SetVolume
type StartRTCStreamRequest ¶
StartRTCStreamRequest contains parameters for StartRTCStream
type StopRTCStreamRequest ¶
type StopRTCStreamRequest struct {
StreamID string
}
StopRTCStreamRequest contains parameters for StopRTCStream
type TestSoundRequest ¶
TestSoundRequest contains parameters for TestSound
type UpdateDeviceHealthRequest ¶
type UpdateDeviceHealthRequest struct {
DeviceID string
}
UpdateDeviceHealthRequest contains parameters for UpdateDeviceHealth