clickatell_api/one_api/send_messages/response.rs
1use crate::one_api::send_messages::{GatewayError, MessageResponse};
2use serde::Deserialize;
3
4/// The response returned from a [Client::send_messages][crate::one_api::Client::send_messages] call to the Clickatell One messaging gateway.
5#[derive(Deserialize, Debug)]
6pub struct Response {
7 /// Request level error
8 ///
9 /// If this is `Some` then no messages in the request were processed by the gateway.
10 /// If it is `None` there may still be errors on each individual [MessageResponse] returned by
11 /// [Response::messages].
12 pub error: Option<GatewayError>,
13
14 messages: Option<Vec<MessageResponse>>,
15}
16
17impl Response {
18 /// Responses for each processed message
19 ///
20 /// If a request level error occurs then the returned [Vec] will be empty.
21 pub fn messages(&self) -> Vec<MessageResponse> {
22 match self.messages.clone() {
23 Some(message_responses) => message_responses,
24 None => Vec::new(),
25 }
26 }
27
28 /// Convenience method to check if an error occured processing the corresponding
29 /// [Request][crate::one_api::send_messages::Request]
30 pub fn is_error(&self) -> bool {
31 self.error.is_some()
32 }
33}