use crate::prelude::*;
use crate::requests::*;
use azure_core::HttpClient;
use azure_storage::core::clients::StorageClient;
use std::sync::Arc;
pub trait AsPopReceiptClient {
fn as_pop_receipt_client(&self, pop_receipt: impl Into<PopReceipt>) -> Arc<PopReceiptClient>;
}
impl AsPopReceiptClient for Arc<QueueClient> {
fn as_pop_receipt_client(&self, pop_receipt: impl Into<PopReceipt>) -> Arc<PopReceiptClient> {
PopReceiptClient::new(self.clone(), pop_receipt)
}
}
#[derive(Debug, Clone)]
pub struct PopReceiptClient {
queue_client: Arc<QueueClient>,
pop_receipt: PopReceipt,
}
impl PopReceiptClient {
pub(crate) fn new(
queue_client: Arc<QueueClient>,
pop_receipt: impl Into<PopReceipt>,
) -> Arc<Self> {
Arc::new(Self {
queue_client,
pop_receipt: pop_receipt.into(),
})
}
pub(crate) fn storage_client(&self) -> &StorageClient {
self.queue_client.storage_client()
}
pub(crate) fn http_client(&self) -> &dyn HttpClient {
self.queue_client
.storage_client()
.storage_account_client()
.http_client()
}
pub(crate) fn pop_receipt_url(&self) -> Result<url::Url, url::ParseError> {
let mut url = self.queue_client.url_with_segments(
["messages", self.pop_receipt.message_id()]
.iter()
.map(std::ops::Deref::deref),
)?;
url.query_pairs_mut()
.append_pair("popreceipt", self.pop_receipt.pop_receipt());
Ok(url)
}
pub fn delete(&self) -> DeleteMessageBuilder {
DeleteMessageBuilder::new(self)
}
pub fn update(&self, visibility_timeout: impl Into<VisibilityTimeout>) -> UpdateMessageBuilder {
UpdateMessageBuilder::new(self, visibility_timeout)
}
}