use std::rc::Rc;
use crate::{
blocking::http::client,
common::{
errors,
token::request::{RequestTokenRequest, RequestTokenResponse},
},
};
#[derive(Debug)]
pub struct RequestToken<'a> {
api_key: &'a str,
client: Rc<client::HttpClient>,
}
impl<'a> RequestToken<'a> {
pub(crate) fn new(api_key: &'a str, client: Rc<client::HttpClient>) -> RequestToken<'a> {
RequestToken { api_key, client }
}
pub fn send(
&self,
mut otp_payload: RequestTokenRequest,
) -> Result<RequestTokenResponse, errors::HttpError> {
otp_payload.set_api_key(self.api_key);
let response = self
.client
.post("sms/otp/send", None, None, Some(otp_payload))?;
let otp_response = response_or_error_text_blocking!(response, RequestTokenResponse);
Ok(otp_response)
}
}