Struct sendblue::SendblueClient
source · pub struct SendblueClient {
pub api_key: String,
pub api_secret: String,
pub client: Client,
/* private fields */
}
Expand description
Client for the Sendblue API
The SendblueClient
struct provides methods for interacting with the Sendblue API.
§Examples
use sendblue::SendblueClient;
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
Fields§
§api_key: String
§api_secret: String
§client: Client
Implementations§
source§impl SendblueClient
impl SendblueClient
sourcepub fn new(api_key: String, api_secret: String) -> Self
pub fn new(api_key: String, api_secret: String) -> Self
Creates a new Sendblue client with the default reqwest client
§Arguments
api_key
- The API key for authenticationapi_secret
- The API secret for authentication
§Returns
SendblueClient
- A new Sendblue client instance
§Examples
use sendblue::SendblueClient;
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
sourcepub fn new_with_url(
api_key: String,
api_secret: String,
base_url: String,
) -> Self
pub fn new_with_url( api_key: String, api_secret: String, base_url: String, ) -> Self
Creates a new Sendblue client with a custom base URL
§Arguments
api_key
- The API key for authenticationapi_secret
- The API secret for authenticationbase_url
- The base URL for the API
§Returns
SendblueClient
- A new Sendblue client instance
This is a private function and not intended for public use.
sourcepub async fn send<T: SendableMessage>(
&self,
message: &T,
) -> Result<T::ResponseType, SendblueError>
pub async fn send<T: SendableMessage>( &self, message: &T, ) -> Result<T::ResponseType, SendblueError>
Sends a message using the Sendblue API
§Arguments
message
- The message to be sent
§Returns
MessageResponse
- The response from the Sendblue APISendblueError
- An error that occurred during the request
§Examples
Sending a normal message:
use sendblue::SendblueClient;
use sendblue::models::MessageBuilder;
#[tokio::main]
async fn main() {
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
let message = MessageBuilder::new(phonenumber::parse(None, "+10722971673").unwrap())
.content("Hello, world!".into())
.build()
.unwrap();
match client.send(&message).await {
Ok(response) => println!("Message sent: {:?}", response),
Err(e) => eprintln!("Error sending message: {:?}", e),
}
}
Sending a group message:
use sendblue::SendblueClient;
use sendblue::models::{MessageBuilder, GroupMessage};
#[tokio::main]
async fn main() {
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
let group_message = MessageBuilder::<GroupMessage>::new_group()
.numbers(vec![phonenumber::parse(None, "+10722971673").unwrap(), phonenumber::parse(None, "+10722971673").unwrap()])
.content("Hello, group!".into())
.build()
.unwrap();
match client.send::<>(&group_message).await {
Ok(response) => println!("Group message sent: {:?}", response),
Err(e) => eprintln!("Error sending group message: {:?}", e),
}
}
sourcepub async fn get_messages(
&self,
params: GetMessagesParams,
) -> Result<GetMessagesResponse, SendblueError>
pub async fn get_messages( &self, params: GetMessagesParams, ) -> Result<GetMessagesResponse, SendblueError>
Retrieves messages using the Sendblue API
§Arguments
params
- The parameters for filtering and paginating messages
§Returns
GetMessagesResponse
- The response containing the retrieved messagesSendblueError
- An error that occurred during the request
§Examples
use sendblue::SendblueClient;
use sendblue::models::{GetMessagesParamsBuilder};
#[tokio::main]
async fn main() {
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
let params = GetMessagesParamsBuilder::new()
.limit(Some(50))
.offset(Some(0))
.number(Some(phonenumber::parse(None, "+10722971673").unwrap()))
.from_date(Some("2023-06-15 12:00:00".into()))
.cid(None)
.build();
match client.get_messages(params).await {
Ok(response) => println!("Messages retrieved: {:?}", response.messages),
Err(e) => eprintln!("Error retrieving messages: {:?}", e),
}
}
sourcepub async fn evaluate_service(
&self,
evaluate_service: &EvaluateService,
) -> Result<EvaluateServiceResponse, SendblueError>
pub async fn evaluate_service( &self, evaluate_service: &EvaluateService, ) -> Result<EvaluateServiceResponse, SendblueError>
Evaluates if a number can send/receive iMessages using the Sendblue API
§Arguments
evaluate_service
- The evaluation request containing the phone number in E.164 format
§Returns
EvaluateServiceResponse
- The response containing the evaluation resultSendblueError
- An error that occurred during the request
§Examples
use sendblue::SendblueClient;
use sendblue::models::{EvaluateServiceBuilder};
#[tokio::main]
async fn main() {
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
let evaluate_service = EvaluateServiceBuilder::new()
.number(phonenumber::parse(None, "+10722971673").unwrap())
.build();
match client.evaluate_service(&evaluate_service).await {
Ok(response) => println!("Evaluation result: {:?}", response),
Err(e) => eprintln!("Error evaluating number: {:?}", e),
}
}
sourcepub async fn send_typing_indicator(
&self,
number: &PhoneNumber,
) -> Result<TypingIndicatorResponse, SendblueError>
pub async fn send_typing_indicator( &self, number: &PhoneNumber, ) -> Result<TypingIndicatorResponse, SendblueError>
Sends a typing indicator to a recipient using the Sendblue API
§Arguments
number
- The recipient’s phone number in E.164 format
§Returns
TypingIndicatorResponse
- The response from the Sendblue APISendblueError
- An error that occurred during the request
§Examples
use sendblue::SendblueClient;
#[tokio::main]
async fn main() {
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
let number = phonenumber::parse(None, "+10722971673").unwrap();
match client.send_typing_indicator(&number).await {
Ok(response) => println!("Typing indicator sent: {:?}", response),
Err(e) => eprintln!("Error sending typing indicator: {:?}", e),
}
}
Auto Trait Implementations§
impl Freeze for SendblueClient
impl !RefUnwindSafe for SendblueClient
impl Send for SendblueClient
impl Sync for SendblueClient
impl Unpin for SendblueClient
impl !UnwindSafe for SendblueClient
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more