Use ? instead of match where appropriate
This commit is contained in:
parent
17d375a5dc
commit
7f717d30b7
2 changed files with 10 additions and 28 deletions
|
@ -102,12 +102,9 @@ impl Config {
|
|||
let mut post_queue: Vec<CreatePost> = vec![];
|
||||
|
||||
match self.feeds.iter().map(|feed| {
|
||||
let res = match CLIENT
|
||||
let res = CLIENT
|
||||
.get(feed.feed_url.clone())
|
||||
.send() {
|
||||
Ok(data) => data.text().unwrap(),
|
||||
Err(e) => return Err(e)
|
||||
};
|
||||
.send()?.text()?;
|
||||
|
||||
let data: FeedData = serde_json::from_str(&res).unwrap();
|
||||
|
||||
|
@ -281,13 +278,10 @@ impl CommunitiesVector {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let res = match CLIENT
|
||||
let res = CLIENT
|
||||
.get(base.clone() + "/api/v3/community/list")
|
||||
.query(¶ms)
|
||||
.send() {
|
||||
Ok(data) => data.text().unwrap(),
|
||||
Err(e) => return Err(e)
|
||||
};
|
||||
.send()?.text()?;
|
||||
|
||||
let site_data: ListCommunitiesResponse = serde_json::from_str(&res).unwrap();
|
||||
|
||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -57,13 +57,10 @@ impl Bot {
|
|||
totp_2fa_token: None,
|
||||
};
|
||||
|
||||
let res = match CLIENT
|
||||
let res = CLIENT
|
||||
.post(self.config.instance.clone() + "/api/v3/user/login")
|
||||
.json(&login_params)
|
||||
.send() {
|
||||
Ok(data) => data,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
.send()?;
|
||||
|
||||
|
||||
if res.status() == StatusCode::OK {
|
||||
|
@ -84,13 +81,10 @@ impl Bot {
|
|||
/// * `return` : Returns true if Post was succesful, false otherwise
|
||||
#[warn(unused_results)]
|
||||
pub(crate) fn post(&mut self, post_data: CreatePost) -> Result<(), reqwest::Error> {
|
||||
let res = match CLIENT
|
||||
let res = CLIENT
|
||||
.post(self.config.instance.clone() + "/api/v3/post")
|
||||
.json(&post_data)
|
||||
.send() {
|
||||
Ok(data) => data,
|
||||
Err(e) => return Err(e)
|
||||
};
|
||||
.send()?;
|
||||
|
||||
// TODO: process res to get info about if post was successfuly (mostly if jwt token was valid)
|
||||
|
||||
|
@ -106,20 +100,14 @@ impl Bot {
|
|||
println!("Reloading Config");
|
||||
*prev_time = self.start_time;
|
||||
self.config.load();
|
||||
match self.community_ids.load(&self.auth, &self.config.instance) {
|
||||
Ok(_) => {},
|
||||
Err(e) => return Err(e)
|
||||
};
|
||||
self.community_ids.load(&self.auth, &self.config.instance)?;
|
||||
println!("Done!");
|
||||
}
|
||||
|
||||
// Start the polling process
|
||||
// Get all feed URLs (use cache)
|
||||
println!("Checking Feeds");
|
||||
let post_queue: Vec<CreatePost> = match self.config.check_feeds(&mut self.post_history, &self.community_ids, &self.auth) {
|
||||
Ok(data) => data,
|
||||
Err(e) => return Err(e)
|
||||
};
|
||||
let post_queue: Vec<CreatePost> = self.config.check_feeds(&mut self.post_history, &self.community_ids, &self.auth)?;
|
||||
println!("Done!");
|
||||
|
||||
post_queue.iter().for_each(|post| {
|
||||
|
|
Loading…
Reference in a new issue