-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.rs
31 lines (27 loc) · 1.02 KB
/
util.rs
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
use crate::{DeviceFlow, DeviceFlowError, DeviceFlowState};
use std::collections::HashMap;
pub fn credential_error(msg: String) -> DeviceFlowError {
DeviceFlowError::GitHubError(msg.into())
}
pub fn send_request(device_flow: &mut DeviceFlow, url: String, body: String) -> Option<HashMap<String, serde_json::Value>> {
let client = reqwest::blocking::Client::new();
let response_struct = client.post(&url)
.header("Accept", "application/json")
.body(body)
.send();
match response_struct {
Ok(resp) => {
match resp.json::<HashMap<String, serde_json::Value>>() {
Ok(hm) => Some(hm),
Err(err) => {
device_flow.state = DeviceFlowState::Failure(err.into());
None
}
}
},
Err(err) => {
device_flow.state = DeviceFlowState::Failure(err.into());
None
}
}
}