Documentation
¶
Overview ¶
Package rest provides a REST API client for interacting with Ring services. It supports authentication, device enumeration, control, and state management via HTTP/RESTful APIs.
Index ¶
- type Client
- func (c *Client) Apply(opts ...ClientOption)
- func (c *Client) Authenticate(ctx context.Context, username, password, hardwareID, otpCode string) (*TokenResponse, error)
- func (c *Client) GetActiveDings(ctx context.Context) (*dependencymodels.RingRecordingHistoryResponse, error)
- func (c *Client) GetDeviceHealth(ctx context.Context, deviceID int64) (map[string]interface{}, error)
- func (c *Client) GetDeviceHistory(ctx context.Context, deviceID int64, limit int, kind string) (*dependencymodels.RingRecordingHistoryResponse, error)
- func (c *Client) GetDevices(ctx context.Context) (*dependencymodels.RingDevicesResponse, error)
- func (c *Client) GetRecording(ctx context.Context, recordingID int64) (*ringapimodels.VideoStream, error)
- func (c *Client) HTTPClient() *http.Client
- func (c *Client) RefreshAccessToken(ctx context.Context, refreshToken string) (*TokenResponse, error)
- func (c *Client) RegisterSession(ctx context.Context) error
- func (c *Client) Request2FACode(ctx context.Context, username, password, hardwareID string) error
- func (c *Client) SetInHomeChime(ctx context.Context, deviceID int64, settings map[string]interface{}) error
- func (c *Client) SetLights(ctx context.Context, deviceID int64, state string, duration *int) error
- func (c *Client) SetMotionDetection(ctx context.Context, deviceID int64, enabled bool) error
- func (c *Client) SetVolume(ctx context.Context, deviceID int64, volume int) error
- func (c *Client) TestSound(ctx context.Context, deviceID int64, kind string) error
- type ClientOption
- func WithAccessToken(token string) ClientOption
- func WithBaseURI(baseURL string) ClientOption
- func WithHTTPClient(httpClient *http.Client) ClientOption
- func WithHardwareID(hardwareID string) ClientOption
- func WithTokenGetter(getter func(ctx context.Context) (string, error)) ClientOption
- func WithUserAgent(userAgent string) ClientOption
- type TokenResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a REST API client for Ring services
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
NewClient creates a new REST API client
func (*Client) Apply ¶
func (c *Client) Apply(opts ...ClientOption)
Apply applies the options to the client
func (*Client) Authenticate ¶
func (c *Client) Authenticate(ctx context.Context, username, password, hardwareID, otpCode string) (*TokenResponse, error)
Authenticate performs Ring's OAuth 2.0 authorization-code flow with PKCE. The pending browser session is retained between the initial 2FA request and the subsequent call containing the verification code.
func (*Client) GetActiveDings ¶
func (c *Client) GetActiveDings(ctx context.Context) (*dependencymodels.RingRecordingHistoryResponse, error)
GetActiveDings retrieves currently active dings
func (*Client) GetDeviceHealth ¶
func (c *Client) GetDeviceHealth(ctx context.Context, deviceID int64) (map[string]interface{}, error)
GetDeviceHealth retrieves health data for a specific device
func (*Client) GetDeviceHistory ¶
func (c *Client) GetDeviceHistory(ctx context.Context, deviceID int64, limit int, kind string) (*dependencymodels.RingRecordingHistoryResponse, error)
GetDeviceHistory retrieves the history of recordings for a device
func (*Client) GetDevices ¶
func (c *Client) GetDevices(ctx context.Context) (*dependencymodels.RingDevicesResponse, error)
GetDevices retrieves all devices from the Ring API
func (*Client) GetRecording ¶
func (c *Client) GetRecording(ctx context.Context, recordingID int64) (*ringapimodels.VideoStream, error)
GetRecording retrieves a video stream for a recording The endpoint returns video/mp4 directly in the response body
func (*Client) HTTPClient ¶
HTTPClient returns the underlying HTTP client
func (*Client) RefreshAccessToken ¶
func (c *Client) RefreshAccessToken(ctx context.Context, refreshToken string) (*TokenResponse, error)
RefreshAccessToken refreshes an access token using a refresh token.
func (*Client) RegisterSession ¶ added in v0.2.0
RegisterSession registers the client hardware ID with Ring before API use.
func (*Client) Request2FACode ¶
Request2FACode starts the PKCE login flow and causes Ring to deliver a code.
func (*Client) SetInHomeChime ¶
func (c *Client) SetInHomeChime(ctx context.Context, deviceID int64, settings map[string]interface{}) error
SetInHomeChime sets in-home chime settings for a doorbell
func (*Client) SetMotionDetection ¶
SetMotionDetection sets motion detection for a device
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a function that configures a Client
func WithAccessToken ¶
func WithAccessToken(token string) ClientOption
WithAccessToken sets an access token directly
func WithBaseURI ¶
func WithBaseURI(baseURL string) ClientOption
WithBaseURI sets the base URL for the Ring API
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient sets a custom HTTP client
func WithHardwareID ¶
func WithHardwareID(hardwareID string) ClientOption
WithHardwareID sets the hardware ID for authentication
func WithTokenGetter ¶
func WithTokenGetter(getter func(ctx context.Context) (string, error)) ClientOption
WithTokenGetter sets a function to retrieve tokens dynamically
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent sets a custom user agent
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
TokenType string `json:"token_type"`
Scope string `json:"scope"`
}
TokenResponse represents the response from Ring's OAuth token endpoint.