-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add patching of oauth provider
- Loading branch information
Showing
7 changed files
with
120 additions
and
69 deletions.
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,43 @@ | ||
use async_trait::async_trait; | ||
use reqwest::StatusCode; | ||
use thiserror::Error; | ||
|
||
use crate::akapi::{types::OAuthProvider, AkApiRoute, AkClient}; | ||
|
||
pub struct PatchOAuthProvider; | ||
|
||
#[async_trait] | ||
impl AkApiRoute for PatchOAuthProvider { | ||
type Body = OAuthProvider; | ||
type Response = OAuthProvider; | ||
type Error = PatchOAuthProviderError; | ||
|
||
#[instrument] | ||
async fn send(ak: &AkClient, body: Self::Body) -> Result<Self::Response, Self::Error> { | ||
let res = ak | ||
.patch(&format!("/api/v3/providers/oauth2/{}/", body.pk)) | ||
.json(&body) | ||
.send() | ||
.await?; | ||
|
||
match res.status() { | ||
StatusCode::OK => { | ||
let body: OAuthProvider = res.json().await?; | ||
|
||
Ok(body) | ||
} | ||
code => Err(Self::Error::Unknown(format!( | ||
"Invalid status code {}", | ||
code | ||
))), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
pub enum PatchOAuthProviderError { | ||
#[error("An unknown error occured ({0}).")] | ||
Unknown(String), | ||
#[error("Failed to send HTTP request: {0}")] | ||
ConnectionError(#[from] reqwest::Error), | ||
} |
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