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