Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Represents the main client for interacting with Zulip servers.

Implementations§

Source§

impl Client

Source

pub fn encode_filename(&self, file_path: &str) -> Result<String>

Gets the base64-encoded filename for TUS resumable uploads.

Source

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.

Source

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.

Source

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

Source

pub fn new(url: Uri, user: User, key: ApiKey) -> Result<Self>

Creates a new Client from the provided Zulip server URL.

Source

pub fn with_http(self, http: Client) -> Self

Builder function that sets the HTTP client.

Source

pub fn from_zuliprc(path: &str) -> Result<Self>

Attempts to read Client configuration from a zuliprc INI file.

Source

pub fn http_client() -> Result<Client>

Creates a HTTP client for making requests to the Zulip API server.

Source

pub fn user_agent() -> String

Gets the Client’s UserAgent.

Source

pub fn auth_header(&self) -> String

Gets the Authorization header.

Source

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
Source

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:?}");
Source

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:?}");
Source

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}");
Source

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}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

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}");
Source

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}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

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:?}");
Source

pub fn endpoint(&self, endpoint: Endpoint) -> String

Gets the URL for the provided Endpoint.

Source

pub fn base_url(&self) -> String

Gets the base URL for the Zulip API server.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !UnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more