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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//! # Ring Client
//!
//! The Ring Client crate provides a client for interfacing with [Ring](https://www.ring.com/)
//! home security devices.
//!
//! ## Usage
//! ```toml
//! [dependencies]
//! ring-client = "0.1.3"
//! ```
//!
//! ## Capabilities
//!
//! 1. Authenticate with Ring - either via Username and Password, or Refresh Tokens.
//! 2. Interact with Ring locations - including listening for events (such as motion detectors) in
//! real-time, as well as changing the states of devices (such as enabling or disabling an Alarm system).
//! 3. Retrieve profile information.
//!
//! ## Examples
//!
//! More in-depth examples can be found in documentation comments on the Client methods.
//!
//! ### Listening for Events
//!
//! Perhaps one of the most useful features of the crate is the ability to listen and respond to
//! events which occur in a location in real-time.
//!
//! This is done using the [`location::Listener`] method.
//!
//! ```no_run
//! use ring_client::Client;
//!
//! use ring_client::authentication::Credentials;
//! use ring_client::OperatingSystem;
//!
//! # tokio_test::block_on(async {
//! let client = Client::new("Home Automation", "mock-system-id", OperatingSystem::Ios);
//!
//! // For brevity, a Refresh Token is being used here. However, the client can also
//! // be authenticated using a username and password.
//! //
//! // See `Client::login` for more information.
//! let refresh_token = Credentials::RefreshToken("".to_string());
//!
//! client.login(refresh_token)
//! .await
//! .expect("Logging in with a valid refresh token should not fail");
//!
//! let locations = client.get_locations()
//! .await
//! .expect("Getting locations should not fail");
//!
//! let location = locations
//! .first()
//! .expect("There should be at least one location");
//!
//! let mut listener = location.get_listener()
//! .await
//! .expect("Creating a listener should not fail");
//!
//! // Listen for events in the location and react to them using the provided closure.
//! let result = listener.listen::<_, _, ()>(|event, _, _| async move {
//! // Connection can be used to send commands to the Ring API.
//! println!("New event: {:#?}", event);
//!
//! // The connection argument can be used to send events back to Ring in
//! // response to the event.
//!
//! // Return true or false to indicate whether the listener should continue listening, or
//! // whether the promise should be resolved.
//! Ok(true)
//! })
//! .await;
//! # });
//!```
//!
//! ### Sending Events
//!
//! The [`location::Listener`] can also be used to send events to the Ring API, such as arming or disarming an alarm
//! system.
//!
//! ```no_run
//! use serde_json::json;
//! use ring_client::Client;
//!
//! use ring_client::authentication::Credentials;
//! use ring_client::location::{Event, Message};
//! use ring_client::OperatingSystem;
//!
//! # tokio_test::block_on(async {
//! let client = Client::new("Home Automation", "mock-system-id", OperatingSystem::Ios);
//!
//! // For brevity, a Refresh Token is being used here. However, the client can also
//! // be authenticated using a username and password.
//! //
//! // See `Client::login` for more information.
//! let refresh_token = Credentials::RefreshToken("".to_string());
//!
//! client.login(refresh_token)
//! .await
//! .expect("Logging in with a valid refresh token should not fail");
//!
//! let locations = client.get_locations()
//! .await
//! .expect("Getting locations should not fail");
//!
//! let location = locations
//! .first()
//! .expect("There should be at least one location");
//!
//! location.get_listener()
//! .await
//! .expect("Creating a listener should not fail")
//! .send(
//! Event::new(
//! Message::DataUpdate(json!({}))
//! )
//! )
//! .await
//! .expect("Sending an event should not fail");
//! # });
//!```
//!
//! ### Listing Devices
//!
//! ```no_run
//! use ring_client::Client;
//!
//! use ring_client::authentication::Credentials;
//! use ring_client::OperatingSystem;
//!
//! # tokio_test::block_on(async {
//! let client = Client::new("Home Automation", "mock-system-id", OperatingSystem::Ios);
//!
//! // For brevity, a Refresh Token is being used here. However, the client can also
//! // be authenticated using a username and password.
//! //
//! // See `Client::login` for more information.
//! let refresh_token = Credentials::RefreshToken("".to_string());
//!
//! client.login(refresh_token)
//! .await
//! .expect("Logging in with a valid refresh token should not fail");
//!
//! let devices = client.get_devices()
//! .await
//! .expect("Getting devices not fail");
//!
//! println!("{:#?}", devices);
//! # });
//!```
//!
//! ## Contributing
//!
//! There are _tons_ of features which could be added to the crate. If you'd like to contribute, please
//! feel free to open an issue or a pull request.
//!
//! Examples of features which could be added:
//! 1. Better parity between the Ring API and the structs.
//! 2. Support for streaming video from Ring cameras and doorbells.
//!
//! ### Testing
//!
//! Many of the tests require a valid Ring account before they can be run, which can be provided
//! via a Refresh Token being set in the `.env` file.
//!
//! The `.env` file can be created by using `.env.example` as a template:
//! ```sh
//! cp .env.example .env
//! ```
//! #### Running tests
//! The tests can be run with:
//! ```sh
//! cargo test
//! ```
pub use *;
pub use OperatingSystem;