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
//! This lib allow to access [Airparif](https://www.airparif.asso.fr/) indice pollution API for Ile-de-France (France). //! It needs an [API key](https://www.airparif.asso.fr/rss/api) to work. //! //! Through the [client](./client/struct.RParifClient.html) it allows access to the following endpoints : //! * indice : it provides the global pollution index //! * indiceJour : it returns global and per pollutant indices for previous, current or next day //! * idxville : returns indice and pollutant for given cities for previous, current and next day //! * episode : returns pollution alerts //! //! # Examples //! //! Getting and displaying global pollution indices : //! ```rust,no_run //! use rparif::client::RParifClient; //! //! let client = RParifClient::new("my-api-key"); //! let indices = client.index()?; //! for index in indices.into_iter() { //! println!("{}", index); //! } //! # Ok::<(), rparif::error::RParifError>(()) //! ``` //! //! Fetching pollution alert : //! ```rust,no_run //! use rparif::client::RParifClient; //! //! let client = RParifClient::new("my-api-key"); //! let episodes = client.episode()?; //! for episode in episodes.into_iter() { //! println!("{}", episode); //! } //! # Ok::<(), rparif::error::RParifError>(()) //! ``` #![doc(html_root_url = "https://docs.rs/rparif/0.1.0/")] // macro use for unit test #[cfg(test)] #[macro_use] extern crate json; #[macro_use] extern crate log; #[cfg(feature = "serde")] extern crate serde; use crate::client::RParifClient; use crate::error::RParifError; use crate::objects::{Day, Episode, Index}; pub mod client; pub mod error; pub mod objects; /// Convenient function that allow easy to access [`indice`](./client/struct.RParifClient.html#method.indice) endpoint. /// If multiple calls needs to be made to HTTP API, use [RParifClient](./client/struct.RParifClient.html) /// /// # Arguments /// /// * `api_key` - API key /// /// # Errors /// /// * [RParifError::RequestError](../error/enum.RParifError.html#variant.RequestError) when reqwest lib /// fails. It contains the underlying error. /// /// * [RParifError::CallError](../error/enum.RParifError.html#variant.CallError) when HTTP status is /// other than 2XX. It contains the URL called, the HTTP status and the body response /// /// * [RParifError::UnexpectedDate](../error/enum.RParifError.html#variant.UnexpectedDate) /// if the date can't be parsed (see [`convert_json_to_date`](#method.convert_json_to_date)) /// /// * [RParifError::MissingJsonKey](../error/enum.RParifError.html#variant.MissingJsonKey) if missing /// JSON is missing `indice` pollution /// /// * [RParifError::WrongJsonType](../error/enum.RParifError.html#variant.WrongJsonType) if `indice` /// pollution is not a number or if JSON is not as expected /// /// * [RParifError::JsonError](../error/enum.RParifError.html#variant.JsonError) if response isn't a well /// formed JSON pub fn indice(api_key: &str) -> Result<Vec<Index>, RParifError> { RParifClient::new(api_key).index() } /// Convenient function that allow easy to access [`indiceJour`](./client/struct.RParifClient.html#method.indice_day) endpoint. /// If multiple calls needs to be made to HTTP API, use [RParifClient](./client/struct.RParifClient.html) /// /// # Arguments /// /// * `api_key` - API key /// /// * `day` - Which day to get pollution indices for /// /// # Errors /// /// * [RParifError::RequestError](../error/enum.RParifError.html#variant.RequestError) when reqwest lib /// fails. It contains the underlying error. /// /// * [RParifError::CallError](../error/enum.RParifError.html#variant.CallError) when HTTP status is /// other than 2XX. It contains the URL called, the HTTP status and the body response /// /// * [RParifError::MissingJsonKey](../error/enum.RParifError.html#variant.MissingJsonKey) if missing /// JSON is missing `indice` pollution or `date` /// /// * [RParifError::WrongJsonType](../error/enum.RParifError.html#variant.WrongJsonType) if `indice` /// pollution is not a number or if `date` isn't a string /// /// * [RParifError::DateParseError](../error/enum.RParifError.html#variant.DateParseError) if `date` /// is not in `dd/mm/yyyy` format /// /// * [RParifError::JsonError](../error/enum.RParifError.html#variant.JsonError) if response isn't a well /// formed JSON pub fn indice_day(api_key: &str, day: Day) -> Result<Vec<Index>, RParifError> { RParifClient::new(api_key).index_day(day) } /// Convenient function that allow easy to access [`idxville`](./client/struct.RParifClient.html#method.indice_city) endpoint. /// If multiple calls needs to be made to HTTP API, use [RParifClient](./client/struct.RParifClient.html) /// /// # Arguments /// /// * `api_key` - API key /// /// * `cities` - List of INSEE city code. See [here](https://data.opendatasoft.com/explore/dataset/correspondance-code-insee-code-postal%40public/table/) /// or [here](https://www.data.gouv.fr/en/datasets/correspondance-entre-les-codes-postaux-et-codes-insee-des-communes-francaises/) to find corresponding code /// /// # Errors /// /// * [RParifError::RequestError](../error/enum.RParifError.html#variant.RequestError) when reqwest lib /// fails. It contains the underlying error. /// /// * [RParifError::CallError](../error/enum.RParifError.html#variant.CallError) when HTTP status is /// other than 2XX. It contains the URL called, the HTTP status and the body response /// /// * [RParifError::UnexpectedDate](../error/enum.RParifError.html#variant.UnexpectedDate) /// if the date can't be parsed (see [`convert_string_to_date`](#method.convert_string_to_date)) /// /// * [RParifError::MissingJsonKey](../error/enum.RParifError.html#variant.MissingJsonKey) if missing /// JSON is missing `ninsee` or `indice` /// /// * [RParifError::WrongJsonType](../error/enum.RParifError.html#variant.WrongJsonType) if `ninsee` /// isn't a string or `indice` is not a number or if JSON is not as expected /// /// * [RParifError::JsonError](../error/enum.RParifError.html#variant.JsonError) if response isn't a well /// formed JSON pub fn indice_city(api_key: &str, cities: Vec<&str>) -> Result<Vec<Index>, RParifError> { RParifClient::new(api_key).index_city(cities) } /// Convenient function that allow easy to access [`episode`](./client/struct.RParifClient.html#method.episode) endpoint. /// If multiple calls needs to be made to HTTP API, use [RParifClient](./client/struct.RParifClient.html) /// /// # Arguments /// /// * `api_key` - API key /// /// * `cities` - List of INSEE city code. See [here](https://data.opendatasoft.com/explore/dataset/correspondance-code-insee-code-postal%40public/table/) /// or [here](https://www.data.gouv.fr/en/datasets/correspondance-entre-les-codes-postaux-et-codes-insee-des-communes-francaises/) to find corresponding code /// /// # Errors /// /// * [RParifError::RequestError](../error/enum.RParifError.html#variant.RequestError) when reqwest lib /// fails. It contains the underlying error. /// /// * [RParifError::CallError](../error/enum.RParifError.html#variant.CallError) when HTTP status is /// other than 2XX. It contains the URL called, the HTTP status and the body response /// /// * [RParifError::UnexpectedDate](../error/enum.RParifError.html#variant.UnexpectedDate) /// if the date can't be parsed (see [`convert_string_to_date`](#method.convert_string_to_date)) /// /// * [RParifError::MissingJsonKey](../error/enum.RParifError.html#variant.MissingJsonKey) if missing /// JSON is missing `ninsee` or `indice` /// /// * [RParifError::WrongJsonType](../error/enum.RParifError.html#variant.WrongJsonType) if `ninsee` /// isn't a string or `indice` is not a number or if JSON is not as expected /// /// * [RParifError::JsonError](../error/enum.RParifError.html#variant.JsonError) if response isn't a well /// formed JSON pub fn episode(api_key: &str) -> Result<Vec<Episode>, RParifError> { RParifClient::new(api_key).episode() }