use reqwest::header::ACCEPT;
use super::{ACCEPT_JSON, OpsdClient, decode_response, expect_no_content};
use crate::{
Error,
types::{
AcceptPracticeInvitationResponse, CreatePracticeBusinessRequest,
CreatePracticeBusinessResponse, CreatePracticeInvitationRequest,
CreatePracticeInvitationResponse, CreatePracticeRequest, CreatePracticeResponse,
GetPracticeResponse, ListOutgoingPracticeInvitationsResponse,
ListPendingPracticeInvitationsResponse, ListPracticeBusinessesResponse,
ListPracticeMembersResponse, ListPracticesResponse, PracticeId, PracticeInvitationId,
UpdatePracticeMemberRequest, UserId,
},
};
impl OpsdClient {
pub async fn create_practice_business(
&self,
practice_id: PracticeId,
request: &CreatePracticeBusinessRequest,
) -> Result<CreatePracticeBusinessResponse, Error> {
let url = self.endpoint(&format!("practices/{practice_id}/businesses"));
let response = self
.authenticate(self.http_client.post(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.json(request)
.send()
.await?;
decode_response(response).await
}
pub async fn list_practice_businesses(
&self,
practice_id: PracticeId,
) -> Result<ListPracticeBusinessesResponse, Error> {
let url = self.endpoint(&format!("practices/{practice_id}/businesses"));
let response = self
.authenticate(self.http_client.get(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
decode_response(response).await
}
pub async fn list_practices(&self) -> Result<ListPracticesResponse, Error> {
let url = self.endpoint("practices");
let response = self
.authenticate(self.http_client.get(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
decode_response(response).await
}
pub async fn create_practice(
&self,
request: &CreatePracticeRequest,
) -> Result<CreatePracticeResponse, Error> {
let url = self.endpoint("practices");
let response = self
.authenticate(self.http_client.post(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.json(request)
.send()
.await?;
decode_response(response).await
}
pub async fn get_practice(
&self,
practice_id: PracticeId,
) -> Result<GetPracticeResponse, Error> {
let url = self.endpoint(&format!("practices/{practice_id}"));
let response = self
.authenticate(self.http_client.get(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
decode_response(response).await
}
pub async fn list_practice_members(
&self,
practice_id: PracticeId,
) -> Result<ListPracticeMembersResponse, Error> {
let url = self.endpoint(&format!("practices/{practice_id}/members"));
let response = self
.authenticate(self.http_client.get(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
decode_response(response).await
}
pub async fn update_practice_member(
&self,
practice_id: PracticeId,
user_id: UserId,
request: &UpdatePracticeMemberRequest,
) -> Result<(), Error> {
let url = self.endpoint(&format!("practices/{practice_id}/members/{user_id}"));
let response = self
.authenticate(self.http_client.patch(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.json(request)
.send()
.await?;
expect_no_content(response).await
}
pub async fn remove_practice_member(
&self,
practice_id: PracticeId,
user_id: UserId,
) -> Result<(), Error> {
let url = self.endpoint(&format!("practices/{practice_id}/members/{user_id}"));
let response = self
.authenticate(self.http_client.delete(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
expect_no_content(response).await
}
pub async fn create_practice_invitation(
&self,
practice_id: PracticeId,
request: &CreatePracticeInvitationRequest,
) -> Result<CreatePracticeInvitationResponse, Error> {
let url = self.endpoint(&format!("practices/{practice_id}/invitations"));
let response = self
.authenticate(self.http_client.post(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.json(request)
.send()
.await?;
decode_response(response).await
}
pub async fn list_outgoing_practice_invitations(
&self,
practice_id: PracticeId,
) -> Result<ListOutgoingPracticeInvitationsResponse, Error> {
let url = self.endpoint(&format!("practices/{practice_id}/invitations"));
let response = self
.authenticate(self.http_client.get(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
decode_response(response).await
}
pub async fn cancel_practice_invitation(
&self,
practice_id: PracticeId,
invitation_id: PracticeInvitationId,
) -> Result<(), Error> {
let url = self.endpoint(&format!(
"practices/{practice_id}/invitations/{invitation_id}"
));
let response = self
.authenticate(self.http_client.delete(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
expect_no_content(response).await
}
pub async fn list_pending_practice_invitations(
&self,
) -> Result<ListPendingPracticeInvitationsResponse, Error> {
let url = self.endpoint("practice-invitations");
let response = self
.authenticate(self.http_client.get(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
decode_response(response).await
}
pub async fn accept_practice_invitation(
&self,
invitation_id: PracticeInvitationId,
) -> Result<AcceptPracticeInvitationResponse, Error> {
let url = self.endpoint(&format!("practice-invitations/{invitation_id}/accept"));
let response = self
.authenticate(self.http_client.post(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
decode_response(response).await
}
pub async fn decline_practice_invitation(
&self,
invitation_id: PracticeInvitationId,
) -> Result<(), Error> {
let url = self.endpoint(&format!("practice-invitations/{invitation_id}/decline"));
let response = self
.authenticate(self.http_client.post(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
expect_no_content(response).await
}
}
use crate::types::PracticeReportingDetails;
impl OpsdClient {
pub async fn get_practice_hmrc_reporting(
&self,
practice_id: PracticeId,
) -> Result<PracticeReportingDetails, Error> {
let url = self.endpoint(&format!("practices/{practice_id}/hmrc-reporting"));
let response = self
.authenticate(self.http_client.get(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.send()
.await?;
decode_response(response).await
}
pub async fn update_practice_hmrc_reporting(
&self,
practice_id: PracticeId,
request: &PracticeReportingDetails,
) -> Result<PracticeReportingDetails, Error> {
let url = self.endpoint(&format!("practices/{practice_id}/hmrc-reporting"));
let response = self
.authenticate(self.http_client.put(url))
.header(ACCEPT, ACCEPT_JSON.clone())
.json(request)
.send()
.await?;
decode_response(response).await
}
}