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
//! # Ambient Weather API
//!
//! `ambient_weather_api` is a collection of functions for downloading current and historical data from the Ambient Weather API. It features built in support for choosing which device you want to pull data from, and has (some) safety measures built in to avoid hitting Ambient Weather's rate limits.
//!
//! To learn more about how the Ambient Weather API works, and to obtain the required API and Application keys to use this creat, check out the [Ambient Weather API Documentation](https://ambientweather.docs.apiary.io).
//!
//! In order to use this API, you will need to look over the [list of device parameters](https://github.com/ambient-weather/api-docs/wiki/Device-Data-Specs) that Ambient Weather offers. Not all device parameters may be used, so make sure you are calling one that is associated with your device.
//!
//! Currently, this Rust crate is only capable of utilizing the Ambient Weather REST API. Support for their Realtime Socket.IO API will come at a later date.
//!
//! # Getting Started
//!
//! To get started with pulling in the latest weather data from your Ambient Weather device, simply follow the example below:
//!
//! ```
//! use ambient_weather_api::*;
//!
//! fn main() {
//!
//! let api_credentials = AmbientWeatherAPICredentials {
//! api_key: String::from("Your API Key"),
//! app_key: String::from("Your Application Key"),
//! device_id: 0,
//! use_new_api_endpoint: false,
//! };
//!
//! // Get the current temperature
//! let latest_data = get_latest_device_data(&api_credentials);
//! println!("The current temp is: {}F", latest_data.tempf.unwrap());
//!
//! // Get the historic temperatures and loop through them going back in time
//! let historic_data = get_historic_device_data(&api_credentials);
//! for i in 0..historic_data.len() {
//! println!("The historic temp was: {}F", historic_data[i].tempf.unwrap());
//! }
//! }
//! ```
use ;
use ;
/// The struct for holding the API and App keys, the device idea, and whether or not to use the new API endpoint or not.
/// A private function for crafting the appropriate Ambient Weather API URL.
/// A private function that gets the raw device data from the Ambient Weather REST API, and then returns either the latest or the historical data for a device
async
/// Gets the latest device data from the Ambient Weather API.
///
/// In order to use this API, you will need to look over the [list of device parameters](https://github.com/ambient-weather/api-docs/wiki/Device-Data-Specs) that Ambient Weather offers. Not all device parameters may be used, so make sure you are calling one that is associated with your device.
///
/// When calling the `get_latest_device_data` function, you must pass the api_credentials as a reference (`&api_credentials`), as this allows for it to be called multiple times elsewhere in a program if necessary.
///
/// # Examples
///
/// ```
/// use ambient_weather_api::*;
///
/// fn main() {
///
/// let api_credentials = AmbientWeatherAPICredentials {
/// api_key: String::from("Your API Key"),
/// app_key: String::from("Your Application Key"),
/// device_id: 0,
/// use_new_api_endpoint: false,
/// };
///
/// // Get the current temperature
/// let latest_data = get_latest_device_data(&api_credentials);
/// println!("The current temp is: {}F", latest_data.tempf.unwrap());
///
/// }
/// ```
/// Gets the historic device data from the Ambient Weather API.
///
/// As of version 0.3.0 this now functions in an asynchronous manner.
///
/// In order to use this API, you will need to look over the [list of device parameters](https://github.com/ambient-weather/api-docs/wiki/Device-Data-Specs) that Ambient Weather offers. Not all device parameters may be used, so make sure you are calling one that is associated with your device.
///
/// # Examples
///
/// ```
/// use ambient_weather_api::*;
///
/// fn main() {
///
/// let api_credentials = AmbientWeatherAPICredentials {
/// api_key: String::from("Your API Key"),
/// app_key: String::from("Your Application Key"),
/// device_id: 0,
/// use_new_api_endpoint: false,
/// };
///
/// // Get the historic temperatures and loop through them going back in time
/// let historic_data = get_historic_device_data(&api_credentials);
/// for i in 0..historic_data.len() {
/// println!("The historic temp was: {}F", historic_data[i].tempf.unwrap());
/// }
///
/// }
/// ```