rest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

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

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

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

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

func (c *Client) HTTPClient() *http.Client

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

func (c *Client) RegisterSession(ctx context.Context) error

RegisterSession registers the client hardware ID with Ring before API use.

func (*Client) Request2FACode

func (c *Client) Request2FACode(ctx context.Context, username, password, hardwareID string) error

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) SetLights

func (c *Client) SetLights(ctx context.Context, deviceID int64, state string, duration *int) error

SetLights sets the lights for a device (floodlight cams)

func (*Client) SetMotionDetection

func (c *Client) SetMotionDetection(ctx context.Context, deviceID int64, enabled bool) error

SetMotionDetection sets motion detection for a device

func (*Client) SetVolume

func (c *Client) SetVolume(ctx context.Context, deviceID int64, volume int) error

SetVolume sets the volume for a device

func (*Client) TestSound

func (c *Client) TestSound(ctx context.Context, deviceID int64, kind string) error

TestSound tests a sound on a chime 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.

Jump to

Keyboard shortcuts

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