feat: switched over to using a library to interact with teh wolves API
This commit is contained in:
parent
77a7b7b81d
commit
ca55a78447
4 changed files with 85 additions and 255 deletions
|
@ -64,8 +64,10 @@ pub mod link {
|
|||
None => {
|
||||
let invalid_user = "Please check it matches (including case) your preferred contact on https://ulwolves.ie/memberships/profile and that you are fully paid up.".to_string();
|
||||
|
||||
let wolves = wolves_oxidised::Client::new(&config.wolves_url, Some(&config.wolves_api));
|
||||
|
||||
// see if the user actually exists
|
||||
let id = match get_user(&config, email).await {
|
||||
let id = match wolves.get_member(email).await {
|
||||
None => {
|
||||
return invalid_user;
|
||||
}
|
||||
|
@ -274,33 +276,6 @@ pub mod link {
|
|||
result: WolvesResultUserResult,
|
||||
}
|
||||
|
||||
async fn get_user(config: &Config, email: &str) -> Option<i64> {
|
||||
let url = format!("{}/get_id_from_email", &config.wolves_url);
|
||||
match reqwest::Client::new()
|
||||
.post(&url)
|
||||
.form(&[("email", email)])
|
||||
.header("X-AM-Identity", &config.wolves_api)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(x) => {
|
||||
if let Ok(y) = x.json::<WolvesResultUser>().await {
|
||||
// this is the only time we will get a positive response, the None at the end catches everything else
|
||||
if let WolvesResultUserResult::S(z) = y.result {
|
||||
if let Ok(id) = z.parse::<i64>() {
|
||||
return Some(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
dbg!(e);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
async fn save_to_db_user(db: &Pool<Sqlite>, id_wolves: i64, email: &str) -> Result<Option<Wolves>, sqlx::Error> {
|
||||
sqlx::query_as::<_, Wolves>(
|
||||
"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue