pub struct Client { /* private fields */ }Expand description
Represents the main client for interacting with Zulip servers.
Implementations§
Source§impl Client
impl Client
Sourcepub fn encode_filename(&self, file_path: &str) -> Result<String>
pub fn encode_filename(&self, file_path: &str) -> Result<String>
Gets the base64-encoded filename for TUS resumable uploads.
Sourcepub async fn tus_create(
&self,
file_name: &str,
file_len: usize,
) -> Result<String>
pub async fn tus_create( &self, file_name: &str, file_len: usize, ) -> Result<String>
Creates a TUS resumable upload link.
Returns the resumable file URL path for further TUS requests.
Sourcepub async fn tus_upload(
&self,
file_url: &str,
file_path: &str,
) -> Result<Response>
pub async fn tus_upload( &self, file_url: &str, file_path: &str, ) -> Result<Response>
Uploads a file using TUS resumable upload.
Returns the resumable file URL path for further TUS requests.
Sourcepub async fn tus_create_and_upload(&self, file_path: &str) -> Result<Response>
pub async fn tus_create_and_upload(&self, file_path: &str) -> Result<Response>
Creates and uploads a file using the TUS resumable upload protocol.
Source§impl Client
impl Client
Sourcepub fn new(url: Uri, user: User, key: ApiKey) -> Result<Self>
pub fn new(url: Uri, user: User, key: ApiKey) -> Result<Self>
Creates a new Client from the provided Zulip server URL.
Sourcepub fn from_zuliprc(path: &str) -> Result<Self>
pub fn from_zuliprc(path: &str) -> Result<Self>
Attempts to read Client configuration from a zuliprc INI file.
Sourcepub fn http_client() -> Result<Client>
pub fn http_client() -> Result<Client>
Creates a HTTP client for making requests to the Zulip API server.
Sourcepub fn user_agent() -> String
pub fn user_agent() -> String
Gets the Client’s UserAgent.
Sourcepub fn auth_header(&self) -> String
pub fn auth_header(&self) -> String
Gets the Authorization header.
Sourcepub async fn load_page(&self, path: &str) -> Result<String>
pub async fn load_page(&self, path: &str) -> Result<String>
Loads a page from the Zulip.
path: optional path of the page to load, empty string loads the base path
Sourcepub async fn send_message(&self, msg: &Request) -> Result<Response>
pub async fn send_message(&self, msg: &Request) -> Result<Response>
Sends a message to the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::send_message;
use zulip_api::message::{MessageTo, MessageType};
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = send_message::Request::new()
.with_msg_type(MessageType::Channel)
.with_topic("test topic")
.with_to(MessageTo::ChannelName("general".into()))
.with_content("test message".to_string());
let res = client.send_message(&req).await.unwrap();
println!("Send message response: {res:?}");Sourcepub async fn get_messages(&self, req: &Request) -> Result<Response>
pub async fn get_messages(&self, req: &Request) -> Result<Response>
Gets a list of messages from the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::get_messages;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = get_messages::Request::new();
let res = client.get_messages(&req).await.unwrap();
println!("Get messages response: {res:?}");Sourcepub async fn upload_file(&self, req: &Request) -> Result<Response>
pub async fn upload_file(&self, req: &Request) -> Result<Response>
Uploads a file to the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::upload_file;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = upload_file::Request::new().with_file_path("/path/to/file.txt");
let res = client.upload_file(&req).await.unwrap();
println!("Upload file response: {res}");Sourcepub async fn get_file_temporary_url(&self, req: &Request) -> Result<Response>
pub async fn get_file_temporary_url(&self, req: &Request) -> Result<Response>
Get a temporary URL for access to an uploaded file that doesn’t require authentication.
§Example
use zulip_api::client::Client;
use zulip_api::{get_file_temporary_url, upload_file};
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = upload_file::Request::new().with_file_path("/path/to/file.txt");
let res = client.upload_file(&req).await.unwrap();
println!("Upload file response: {res}");
let req = get_file_temporary_url::Request::new()
.with_realm_id(res.realm_id().unwrap())
.with_filename(res.filename_path().unwrap());
let res = client.get_file_temporary_url(&req).await.unwrap();
println!("Get file temporary URL response: {res}");Sourcepub async fn edit_message(&self, req: &Request) -> Result<Response>
pub async fn edit_message(&self, req: &Request) -> Result<Response>
Edit a message on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::edit_message;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = edit_message::Request::new()
.with_message_id(1)
.with_content("edited content");
let res = client.edit_message(&req).await.unwrap();
println!("Edit message response: {res:?}");Sourcepub async fn delete_message(&self, req: &Request) -> Result<Response>
pub async fn delete_message(&self, req: &Request) -> Result<Response>
Delete a message on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::delete_message;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = delete_message::Request::new()
.with_message_id(1);
let res = client.delete_message(&req).await.unwrap();
println!("Delete message response: {res:?}");Sourcepub async fn get_message(&self, req: &Request) -> Result<Response>
pub async fn get_message(&self, req: &Request) -> Result<Response>
Gets a message on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::get_message;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = get_message::Request::new()
.with_message_id(1);
let res = client.get_message(&req).await.unwrap();
println!("Get message response: {res:?}");Sourcepub async fn get_message_history(&self, req: &Request) -> Result<Response>
pub async fn get_message_history(&self, req: &Request) -> Result<Response>
Gets a message edit history on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::get_message_history;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = get_message_history::Request::new()
.with_message_id(1);
let res = client.get_message_history(&req).await.unwrap();
println!("Get message history response: {res:?}");Sourcepub async fn report_message(&self, req: &Request) -> Result<Response>
pub async fn report_message(&self, req: &Request) -> Result<Response>
Reports a message for moderation on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::{report_message, ReportType};
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = report_message::Request::new()
.with_message_id(1)
.with_report_type(ReportType::Other)
.with_description("This message insults and mocks Frodo, which is against the code of conduct.");
let res = client.report_message(&req).await.unwrap();
println!("Report message response: {res:?}");Sourcepub async fn matches_narrow(&self, req: &Request) -> Result<Response>
pub async fn matches_narrow(&self, req: &Request) -> Result<Response>
Gets narrow matches on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::filter::{Narrow, Operand, Operator};
use zulip_api::matches_narrow;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let msg_ids = [1u64];
let narrow = [Narrow::new()
.with_operator(Operator::Has)
.with_operand(Operand::text("link"))];
let req = matches_narrow::Request::new()
.with_msg_ids(msg_ids.as_ref())
.with_narrow(narrow.as_ref());
let res = client.matches_narrow(&req).await.unwrap();
println!("Matches narrow response: {res:?}");Sourcepub async fn add_reaction(&self, req: &Request) -> Result<Response>
pub async fn add_reaction(&self, req: &Request) -> Result<Response>
Adds an emoji reaction to a message on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::emoji_reaction;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = emoji_reaction::Request::new()
.with_message_id(1)
.with_emoji_name("+1");
let res = client.add_reaction(&req).await.unwrap();
println!("Add emoji reaction response: {res:?}");Sourcepub async fn remove_reaction(&self, req: &Request) -> Result<Response>
pub async fn remove_reaction(&self, req: &Request) -> Result<Response>
Removes an emoji reaction from a message on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::emoji_reaction;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = emoji_reaction::Request::new()
.with_message_id(1)
.with_emoji_name("+1");
let res = client.remove_reaction(&req).await.unwrap();
println!("Remove emoji reaction response: {res:?}");Sourcepub async fn render(&self, req: &Request) -> Result<Response>
pub async fn render(&self, req: &Request) -> Result<Response>
Renders a message from the Zulip server into HTML.
§Example
use zulip_api::client::Client;
use zulip_api::render;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = render::Request::new()
.with_content("test message");
let res = client.render(&req).await.unwrap();
println!("Render response: {res:?}");Sourcepub async fn update_message_flags(&self, req: &Request) -> Result<Response>
pub async fn update_message_flags(&self, req: &Request) -> Result<Response>
Update message flags on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::{update_message_flags, Flag, Operation};
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = update_message_flags::Request::new()
.with_messages([1u64].as_ref())
.with_op(Operation::Add)
.with_flag(Flag::Read);
let res = client.update_message_flags(&req).await.unwrap();
println!("Update message flags response: {res}");Sourcepub async fn update_message_flags_narrow(
&self,
req: &Request,
) -> Result<Response>
pub async fn update_message_flags_narrow( &self, req: &Request, ) -> Result<Response>
Update message flags for a narrow on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::{update_message_flags_narrow, Flag, Operation};
use zulip_api::filter::{Anchor, Narrow};
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = update_message_flags_narrow::Request::new()
.with_anchor(Anchor::new())
.with_include_anchor(true)
.with_num_before(1)
.with_num_after(1)
.with_narrow(vec![Narrow::new()])
.with_op(Operation::Add)
.with_flag(Flag::Read);
let res = client.update_message_flags_narrow(&req).await.unwrap();
println!("Update message flags for narrow response: {res}");Sourcepub async fn mark_all_as_read(&self) -> Result<Response>
pub async fn mark_all_as_read(&self) -> Result<Response>
Marks all messages as read on the Zulip server.
§Example
use zulip_api::client::Client;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let res = client.mark_all_as_read().await.unwrap();
println!("Mark all as read response: {res:?}");Sourcepub async fn mark_stream_as_read(&self, req: &Request) -> Result<Response>
pub async fn mark_stream_as_read(&self, req: &Request) -> Result<Response>
Marks all messages in a channel as read on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::mark_stream_as_read;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = mark_stream_as_read::Request::new().with_stream_id(1);
let res = client.mark_stream_as_read(&req).await.unwrap();
println!("Mark stream as read response: {res:?}");Sourcepub async fn mark_topic_as_read(&self, req: &Request) -> Result<Response>
pub async fn mark_topic_as_read(&self, req: &Request) -> Result<Response>
Marks all messages in a topic as read on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::mark_topic_as_read;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = mark_topic_as_read::Request::new()
.with_stream_id(1)
.with_topic_name("test topic");
let res = client.mark_topic_as_read(&req).await.unwrap();
println!("Mark topic as read response: {res:?}");Sourcepub async fn get_read_receipts(&self, req: &Request) -> Result<Response>
pub async fn get_read_receipts(&self, req: &Request) -> Result<Response>
Gets a message’s read receipts on the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::get_read_receipts;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = get_read_receipts::Request::new()
.with_message_id(1);
let res = client.get_read_receipts(&req).await.unwrap();
println!("Get read receipts response: {res:?}");Sourcepub async fn register(&self, req: &Request) -> Result<Response>
pub async fn register(&self, req: &Request) -> Result<Response>
Registers an event queue with the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::register;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let req = register::Request::new();
let res = client.register(&req).await.unwrap();
println!("Register response: {res:?}");Sourcepub async fn fetch_api_key(&self, req: &Request) -> Result<Response>
pub async fn fetch_api_key(&self, req: &Request) -> Result<Response>
Fetches a user’s API key using a username-password authentication method with the Zulip server.
§Example
use zulip_api::client::Client;
use zulip_api::fetch_api_key;
let client = Client::from_zuliprc(".zuliprc").unwrap();
let algo = jwt::Algorithm::HS256;
let key = jwt::EncodingKey::from_base64_secret("MWFlMTgyZjg3NzM1MzMyYmUxNDEwYWMyM2RlMDRkNzRlOWIwNmI4Mjc2YjQwMmZmYWMzNjllNTA5ZThiN2I0Mg==").unwrap();
let email = fetch_api_key::Email::new("user@example.dev");
let password = fetch_api_key::Password::new("super_secret_password");
let req = fetch_api_key::Request::create(algo, &key, &email, &password).unwrap();
let res = client.fetch_api_key(&req).await.unwrap();
println!("Fetch API key response: {res:?}");