use std::rc::Rc;
use crate::{
blocking::http::client,
common::{
errors,
switch::number::{NumberMessageRequest, NumberMessageResponse},
},
};
#[derive(Debug)]
pub struct Number<'a> {
api_key: &'a str,
client: Rc<client::HttpClient>,
}
impl<'a> Number<'a> {
pub(crate) fn new(api_key: &'a str, client: Rc<client::HttpClient>) -> Number<'a> {
Number { api_key, client }
}
pub fn send(
&self,
mut message: NumberMessageRequest,
) -> Result<NumberMessageResponse, errors::HttpError> {
message.set_api_key(self.api_key);
let response = self
.client
.post("sms/number/send", None, None, Some(message))?;
let message_response = response_or_error_text_blocking!(response, NumberMessageResponse);
Ok(message_response)
}
}