-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for filtering by author (#72)
- Loading branch information
1 parent
3371105
commit 7470e05
Showing
4 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::auth; | ||
use crate::structs::FabConfig; | ||
use failure::Error; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::{Map, Value}; | ||
|
||
pub async fn get_user(username: &str, config: &FabConfig) -> Result<User, Error> { | ||
let mut map = Map::new(); | ||
map.insert( | ||
"api.token".to_string(), | ||
Value::from(config.api_token.clone()), | ||
); | ||
map.insert( | ||
"constraints[usernames][0]".to_string(), | ||
Value::from(username), | ||
); | ||
|
||
let url = format!("{}{}", &config.hosted_instance, "api/user.search"); | ||
|
||
let json_body = Value::Object(map); | ||
|
||
let result = | ||
auth::send::<UserSearchData>(config, reqwest::Client::new().post(&url).form(&json_body)) | ||
.await? | ||
.data | ||
.into_iter() | ||
.next() | ||
.unwrap(); | ||
|
||
Ok(result) | ||
} | ||
|
||
#[derive(Deserialize, Serialize, Debug)] | ||
struct UserSearchData { | ||
data: Vec<User>, | ||
} | ||
|
||
#[derive(Deserialize, Serialize, Debug, Clone)] | ||
pub struct User { | ||
pub id: i32, | ||
pub phid: String, | ||
} |