MCPcopy Create free account
hub / github.com/dgreif/ring / example

Function example

packages/examples/api-example.ts:4–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { RingApi } from 'ring-client-api'
3
4async function example() {
5 const { env } = process,
6 ringApi = new RingApi({
7 // Replace with your refresh token
8 refreshToken: env.RING_REFRESH_TOKEN!,
9 }),
10 locations = await ringApi.getLocations(),
11 location = locations[0],
12 cameras = await ringApi.getCameras(),
13 camera = cameras[0]
14
15 // Locations API
16 location.onConnected.subscribe((connected) => {
17 const state = connected ? 'Connected' : 'Connecting'
18 console.log(`${state} to location ${location.name} - ${location.id}`)
19 })
20
21 const locationCameraEvents = await location.getCameraEvents({
22 // same params as camera.getEvents
23 }),
24 locationAlarmEvents = await location.getHistory({
25 limit: 1,
26 category: 'alarm',
27 //offset: 100 - number of events to skip over for pagination
28 }),
29 locationBeamsEvents = await location.getHistory({
30 limit: 1,
31 category: 'beams',
32 })
33 console.log('Location Camera Event', locationCameraEvents.events[0])
34 console.log('Location Alarm Event', locationAlarmEvents[0])
35 console.log('Location Beams Event', locationBeamsEvents[0])
36
37 console.log('Monitoring Status', await location.getAccountMonitoringStatus())
38
39 // Camera API
40 const eventsResponse = await camera.getEvents({
41 limit: 10,
42 kind: 'ding',
43 state: 'accepted',
44 // olderThanId: previousEventsResponse.meta.pagination_key
45 // favorites: true
46 }),
47 [firstRecordedEvent] = eventsResponse.events.filter(
48 (event) => event.recording_status === 'ready',
49 )
50
51 if (!firstRecordedEvent) {
52 console.log('No events with recordings found')
53 return
54 }
55
56 const transcodedUrl = await camera.getRecordingUrl(
57 firstRecordedEvent.ding_id_str, // MUST use the ding_id_str, not ding_id
58 {
59 transcoded: true, // get transcoded version of the video. false by default. transcoded has ring log and timestamp
60 },
61 ),

Callers 1

api-example.tsFile · 0.70

Calls 7

getLocationsMethod · 0.95
getCamerasMethod · 0.95
getCameraEventsMethod · 0.80
getHistoryMethod · 0.80
getEventsMethod · 0.80
getRecordingUrlMethod · 0.80

Tested by

no test coverage detected