pub enum GetProjectGrantsError {
RequestFailure(reqwest::Error),
InvalidHeaderValue(reqwest::header::InvalidHeaderValue),
UnexpectedStatus(reqwest::StatusCode),
Status404 {
message: String,
},
Status400 {
errors: Vec<String>,
},
Status403 {
error: String,
},
Status500 {
error: String,
},
}
impl From<reqwest::Error> for GetProjectGrantsError {
fn from(error: reqwest::Error) -> GetProjectGrantsError {
GetProjectGrantsError::RequestFailure(error)
}
}
impl From<reqwest::header::InvalidHeaderValue> for GetProjectGrantsError {
fn from(error: reqwest::header::InvalidHeaderValue) -> GetProjectGrantsError {
GetProjectGrantsError::InvalidHeaderValue(error)
}
}
impl GetProjectGrantsError {
pub fn to_project_endpoint_error(&self) -> Option<crate::model::ProjectEndpointError> {
match self {
GetProjectGrantsError::Status404 { message } => Some(crate::model::ProjectEndpointError::NotFound { message: message.clone() }),
GetProjectGrantsError::Status400 { errors } => Some(crate::model::ProjectEndpointError::ArgValidation { errors: errors.clone() }),
GetProjectGrantsError::Status403 { error } => Some(crate::model::ProjectEndpointError::LimitExceeded { error: error.clone() }),
GetProjectGrantsError::Status500 { error } => Some(crate::model::ProjectEndpointError::Internal { error: error.clone() }),
_ => None
}
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
struct ProjectEndpointErrorNotFoundPayload {
pub message: String,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
struct ProjectEndpointErrorArgValidationPayload {
pub errors: Vec<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
struct ProjectEndpointErrorLimitExceededPayload {
pub error: String,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
struct ProjectEndpointErrorInternalPayload {
pub error: String,
}
pub enum GetProjectGrantError {
RequestFailure(reqwest::Error),
InvalidHeaderValue(reqwest::header::InvalidHeaderValue),
UnexpectedStatus(reqwest::StatusCode),
Status404 {
message: String,
},
Status400 {
errors: Vec<String>,
},
Status403 {
error: String,
},
Status500 {
error: String,
},
}
impl From<reqwest::Error> for GetProjectGrantError {
fn from(error: reqwest::Error) -> GetProjectGrantError {
GetProjectGrantError::RequestFailure(error)
}
}
impl From<reqwest::header::InvalidHeaderValue> for GetProjectGrantError {
fn from(error: reqwest::header::InvalidHeaderValue) -> GetProjectGrantError {
GetProjectGrantError::InvalidHeaderValue(error)
}
}
impl GetProjectGrantError {
pub fn to_project_endpoint_error(&self) -> Option<crate::model::ProjectEndpointError> {
match self {
GetProjectGrantError::Status404 { message } => Some(crate::model::ProjectEndpointError::NotFound { message: message.clone() }),
GetProjectGrantError::Status400 { errors } => Some(crate::model::ProjectEndpointError::ArgValidation { errors: errors.clone() }),
GetProjectGrantError::Status403 { error } => Some(crate::model::ProjectEndpointError::LimitExceeded { error: error.clone() }),
GetProjectGrantError::Status500 { error } => Some(crate::model::ProjectEndpointError::Internal { error: error.clone() }),
_ => None
}
}
}
pub enum PostProjectGrantError {
RequestFailure(reqwest::Error),
InvalidHeaderValue(reqwest::header::InvalidHeaderValue),
UnexpectedStatus(reqwest::StatusCode),
Status404 {
message: String,
},
Status400 {
errors: Vec<String>,
},
Status403 {
error: String,
},
Status500 {
error: String,
},
}
impl From<reqwest::Error> for PostProjectGrantError {
fn from(error: reqwest::Error) -> PostProjectGrantError {
PostProjectGrantError::RequestFailure(error)
}
}
impl From<reqwest::header::InvalidHeaderValue> for PostProjectGrantError {
fn from(error: reqwest::header::InvalidHeaderValue) -> PostProjectGrantError {
PostProjectGrantError::InvalidHeaderValue(error)
}
}
impl PostProjectGrantError {
pub fn to_project_endpoint_error(&self) -> Option<crate::model::ProjectEndpointError> {
match self {
PostProjectGrantError::Status404 { message } => Some(crate::model::ProjectEndpointError::NotFound { message: message.clone() }),
PostProjectGrantError::Status400 { errors } => Some(crate::model::ProjectEndpointError::ArgValidation { errors: errors.clone() }),
PostProjectGrantError::Status403 { error } => Some(crate::model::ProjectEndpointError::LimitExceeded { error: error.clone() }),
PostProjectGrantError::Status500 { error } => Some(crate::model::ProjectEndpointError::Internal { error: error.clone() }),
_ => None
}
}
}
pub enum PostProjectGrantWithActionsError {
RequestFailure(reqwest::Error),
InvalidHeaderValue(reqwest::header::InvalidHeaderValue),
UnexpectedStatus(reqwest::StatusCode),
Status404 {
message: String,
},
Status400 {
errors: Vec<String>,
},
Status403 {
error: String,
},
Status500 {
error: String,
},
}
impl From<reqwest::Error> for PostProjectGrantWithActionsError {
fn from(error: reqwest::Error) -> PostProjectGrantWithActionsError {
PostProjectGrantWithActionsError::RequestFailure(error)
}
}
impl From<reqwest::header::InvalidHeaderValue> for PostProjectGrantWithActionsError {
fn from(error: reqwest::header::InvalidHeaderValue) -> PostProjectGrantWithActionsError {
PostProjectGrantWithActionsError::InvalidHeaderValue(error)
}
}
impl PostProjectGrantWithActionsError {
pub fn to_project_endpoint_error(&self) -> Option<crate::model::ProjectEndpointError> {
match self {
PostProjectGrantWithActionsError::Status404 { message } => Some(crate::model::ProjectEndpointError::NotFound { message: message.clone() }),
PostProjectGrantWithActionsError::Status400 { errors } => Some(crate::model::ProjectEndpointError::ArgValidation { errors: errors.clone() }),
PostProjectGrantWithActionsError::Status403 { error } => Some(crate::model::ProjectEndpointError::LimitExceeded { error: error.clone() }),
PostProjectGrantWithActionsError::Status500 { error } => Some(crate::model::ProjectEndpointError::Internal { error: error.clone() }),
_ => None
}
}
}
pub enum DeleteGrantError {
RequestFailure(reqwest::Error),
InvalidHeaderValue(reqwest::header::InvalidHeaderValue),
UnexpectedStatus(reqwest::StatusCode),
Status404 {
message: String,
},
Status400 {
errors: Vec<String>,
},
Status403 {
error: String,
},
Status500 {
error: String,
},
}
impl From<reqwest::Error> for DeleteGrantError {
fn from(error: reqwest::Error) -> DeleteGrantError {
DeleteGrantError::RequestFailure(error)
}
}
impl From<reqwest::header::InvalidHeaderValue> for DeleteGrantError {
fn from(error: reqwest::header::InvalidHeaderValue) -> DeleteGrantError {
DeleteGrantError::InvalidHeaderValue(error)
}
}
impl DeleteGrantError {
pub fn to_project_endpoint_error(&self) -> Option<crate::model::ProjectEndpointError> {
match self {
DeleteGrantError::Status404 { message } => Some(crate::model::ProjectEndpointError::NotFound { message: message.clone() }),
DeleteGrantError::Status400 { errors } => Some(crate::model::ProjectEndpointError::ArgValidation { errors: errors.clone() }),
DeleteGrantError::Status403 { error } => Some(crate::model::ProjectEndpointError::LimitExceeded { error: error.clone() }),
DeleteGrantError::Status500 { error } => Some(crate::model::ProjectEndpointError::Internal { error: error.clone() }),
_ => None
}
}
}
#[async_trait::async_trait]
pub trait ProjectGrant {
async fn get_project_grants(&self, project_id: &str, authorization: &str) -> Result<Vec<crate::model::ProjectGrant>, GetProjectGrantsError>;
async fn get_project_grant(&self, project_id: &str, grant_id: &str, authorization: &str) -> Result<crate::model::ProjectGrant, GetProjectGrantError>;
async fn post_project_grant(&self, project_id: &str, field0: crate::model::ProjectGrantDataRequest, authorization: &str) -> Result<crate::model::ProjectGrant, PostProjectGrantError>;
async fn post_project_grant_with_actions(&self, project_id: &str, field0: crate::model::ProjectGrantDataWithProjectActions, authorization: &str) -> Result<crate::model::ProjectGrant, PostProjectGrantWithActionsError>;
async fn delete_grant(&self, project_id: &str, grant_id: &str, authorization: &str) -> Result<(), DeleteGrantError>;
}
#[derive(Clone, Debug)]
pub struct ProjectGrantLive {
pub base_url: reqwest::Url,
}
#[async_trait::async_trait]
impl ProjectGrant for ProjectGrantLive {
async fn get_project_grants(&self, project_id: &str, authorization: &str) -> Result<Vec<crate::model::ProjectGrant>, GetProjectGrantsError> {
let mut url = self.base_url.clone();
url.set_path(&format!("v1/projects/{project_id}/grants"));
let mut headers = reqwest::header::HeaderMap::new();
headers.append("authorization", reqwest::header::HeaderValue::from_str(&format!("{authorization}"))?);
let result = reqwest::Client::builder()
.build()?
.get(url)
.headers(headers)
.send()
.await?;
match result.status().as_u16() {
200 => {
let body = result.json::<Vec<crate::model::ProjectGrant>>().await?;
Ok(body)
}
404 => {
let body = result.json::<ProjectEndpointErrorNotFoundPayload>().await?;
Err(GetProjectGrantsError::Status404 { message: body.message })
}
400 => {
let body = result.json::<ProjectEndpointErrorArgValidationPayload>().await?;
Err(GetProjectGrantsError::Status400 { errors: body.errors })
}
403 => {
let body = result.json::<ProjectEndpointErrorLimitExceededPayload>().await?;
Err(GetProjectGrantsError::Status403 { error: body.error })
}
500 => {
let body = result.json::<ProjectEndpointErrorInternalPayload>().await?;
Err(GetProjectGrantsError::Status500 { error: body.error })
}
_ => Err(GetProjectGrantsError::UnexpectedStatus(result.status()))
}
}
async fn get_project_grant(&self, project_id: &str, grant_id: &str, authorization: &str) -> Result<crate::model::ProjectGrant, GetProjectGrantError> {
let mut url = self.base_url.clone();
url.set_path(&format!("v1/projects/{project_id}/grants/{grant_id}"));
let mut headers = reqwest::header::HeaderMap::new();
headers.append("authorization", reqwest::header::HeaderValue::from_str(&format!("{authorization}"))?);
let result = reqwest::Client::builder()
.build()?
.get(url)
.headers(headers)
.send()
.await?;
match result.status().as_u16() {
200 => {
let body = result.json::<crate::model::ProjectGrant>().await?;
Ok(body)
}
404 => {
let body = result.json::<ProjectEndpointErrorNotFoundPayload>().await?;
Err(GetProjectGrantError::Status404 { message: body.message })
}
400 => {
let body = result.json::<ProjectEndpointErrorArgValidationPayload>().await?;
Err(GetProjectGrantError::Status400 { errors: body.errors })
}
403 => {
let body = result.json::<ProjectEndpointErrorLimitExceededPayload>().await?;
Err(GetProjectGrantError::Status403 { error: body.error })
}
500 => {
let body = result.json::<ProjectEndpointErrorInternalPayload>().await?;
Err(GetProjectGrantError::Status500 { error: body.error })
}
_ => Err(GetProjectGrantError::UnexpectedStatus(result.status()))
}
}
async fn post_project_grant(&self, project_id: &str, field0: crate::model::ProjectGrantDataRequest, authorization: &str) -> Result<crate::model::ProjectGrant, PostProjectGrantError> {
let mut url = self.base_url.clone();
url.set_path(&format!("v1/projects/{project_id}/grants"));
let mut headers = reqwest::header::HeaderMap::new();
headers.append("authorization", reqwest::header::HeaderValue::from_str(&format!("{authorization}"))?);
let result = reqwest::Client::builder()
.build()?
.post(url)
.headers(headers)
.json(&field0)
.send()
.await?;
match result.status().as_u16() {
200 => {
let body = result.json::<crate::model::ProjectGrant>().await?;
Ok(body)
}
404 => {
let body = result.json::<ProjectEndpointErrorNotFoundPayload>().await?;
Err(PostProjectGrantError::Status404 { message: body.message })
}
400 => {
let body = result.json::<ProjectEndpointErrorArgValidationPayload>().await?;
Err(PostProjectGrantError::Status400 { errors: body.errors })
}
403 => {
let body = result.json::<ProjectEndpointErrorLimitExceededPayload>().await?;
Err(PostProjectGrantError::Status403 { error: body.error })
}
500 => {
let body = result.json::<ProjectEndpointErrorInternalPayload>().await?;
Err(PostProjectGrantError::Status500 { error: body.error })
}
_ => Err(PostProjectGrantError::UnexpectedStatus(result.status()))
}
}
async fn post_project_grant_with_actions(&self, project_id: &str, field0: crate::model::ProjectGrantDataWithProjectActions, authorization: &str) -> Result<crate::model::ProjectGrant, PostProjectGrantWithActionsError> {
let mut url = self.base_url.clone();
url.set_path(&format!("v1/projects/{project_id}/grants"));
let mut headers = reqwest::header::HeaderMap::new();
headers.append("authorization", reqwest::header::HeaderValue::from_str(&format!("{authorization}"))?);
let result = reqwest::Client::builder()
.build()?
.post(url)
.headers(headers)
.json(&field0)
.send()
.await?;
match result.status().as_u16() {
200 => {
let body = result.json::<crate::model::ProjectGrant>().await?;
Ok(body)
}
404 => {
let body = result.json::<ProjectEndpointErrorNotFoundPayload>().await?;
Err(PostProjectGrantWithActionsError::Status404 { message: body.message })
}
400 => {
let body = result.json::<ProjectEndpointErrorArgValidationPayload>().await?;
Err(PostProjectGrantWithActionsError::Status400 { errors: body.errors })
}
403 => {
let body = result.json::<ProjectEndpointErrorLimitExceededPayload>().await?;
Err(PostProjectGrantWithActionsError::Status403 { error: body.error })
}
500 => {
let body = result.json::<ProjectEndpointErrorInternalPayload>().await?;
Err(PostProjectGrantWithActionsError::Status500 { error: body.error })
}
_ => Err(PostProjectGrantWithActionsError::UnexpectedStatus(result.status()))
}
}
async fn delete_grant(&self, project_id: &str, grant_id: &str, authorization: &str) -> Result<(), DeleteGrantError> {
let mut url = self.base_url.clone();
url.set_path(&format!("v1/projects/{project_id}/grants/{grant_id}"));
let mut headers = reqwest::header::HeaderMap::new();
headers.append("authorization", reqwest::header::HeaderValue::from_str(&format!("{authorization}"))?);
let result = reqwest::Client::builder()
.build()?
.post(url)
.headers(headers)
.send()
.await?;
match result.status().as_u16() {
200 => {
let body = result.json::<()>().await?;
Ok(body)
}
404 => {
let body = result.json::<ProjectEndpointErrorNotFoundPayload>().await?;
Err(DeleteGrantError::Status404 { message: body.message })
}
400 => {
let body = result.json::<ProjectEndpointErrorArgValidationPayload>().await?;
Err(DeleteGrantError::Status400 { errors: body.errors })
}
403 => {
let body = result.json::<ProjectEndpointErrorLimitExceededPayload>().await?;
Err(DeleteGrantError::Status403 { error: body.error })
}
500 => {
let body = result.json::<ProjectEndpointErrorInternalPayload>().await?;
Err(DeleteGrantError::Status500 { error: body.error })
}
_ => Err(DeleteGrantError::UnexpectedStatus(result.status()))
}
}
}