diff options
author | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-05 01:04:31 -0700 |
---|---|---|
committer | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-06 19:56:04 -0700 |
commit | ca754e6254d9e0453dd0e02d700ea0ac3dd9d6a5 (patch) | |
tree | 96d5e8eeaea0799d805d8a4456d8fbe1b139721a | |
parent | 6efe775ca619b9c08b260d709168694ef3bcf42b (diff) |
Hardcode filter (as recommended by SE docs)
-rw-r--r-- | src/config.rs | 1 | ||||
-rw-r--r-- | src/stackexchange.rs | 20 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs index 43491ef..4eea499 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,5 @@ pub struct Config { pub api_key: String, - pub filter: String, pub limit: u16, pub site: String, } diff --git a/src/stackexchange.rs b/src/stackexchange.rs index fda1404..79b389f 100644 --- a/src/stackexchange.rs +++ b/src/stackexchange.rs @@ -7,8 +7,14 @@ use std::collections::HashMap; use crate::config::Config; +/// StackExchange API v2.2 URL const SE_URL: &str = "http://api.stackexchange.com/2.2/"; +/// Filter generated to include only the fields needed to populate +/// the structs below. Go here to make new filters: +/// [create filter](https://api.stackexchange.com/docs/create-filter). +const SE_FILTER: &str = ".DND5X2VHHUH8HyJzpjo)5NvdHI3w6auG"; + /// This structure allows intercting with parts of the StackExchange /// API, using the `Config` struct to determine certain API settings and options. pub struct StackExchange { @@ -16,6 +22,12 @@ pub struct StackExchange { config: Config, } +#[derive(Deserialize, Serialize, Debug)] +pub struct Site { + api_site_parameter: String, + site_url: String, +} + /// Represents a StackExchange answer with a custom selection of fields from /// the [StackExchange docs](https://api.stackexchange.com/docs/types/answer) #[derive(Deserialize, Debug)] @@ -85,11 +97,11 @@ impl StackExchange { Ok(qs) } - fn get_default_opts(&self) -> HashMap<&str, &String> { + fn get_default_opts(&self) -> HashMap<&str, &str> { let mut params = HashMap::new(); - params.insert("filter", &self.config.filter); - params.insert("site", &self.config.site); - params.insert("key", &self.config.api_key); + params.insert("site", self.config.site.as_str()); + params.insert("key", self.config.api_key.as_str()); + params.insert("filter", &SE_FILTER); params } } |