[−][src]Struct hiven_rs::client::Client
Authentication of a user on hiven.
With authentication of a user, you can call API endpoints as that user, or start a gateway connection.
Getting Your Token
To be able to authenticate a user, you must have a token. To get a token of a user, you must be logged in as them in the browser. These are the steps to get your token if you are logged in:
- Go to app.hiven.io
- Enter any room that you have permission to speak in
- Press CTRL+SHIFT+I, opening up Developer Tools
- Go to the network tab on the Developer Tools window
- Start typing in the room
- Select the new
typing
request that appears. If two show up, select the one with a 200 status code - Look for the
authorization
header under Request Headers, under Headers - The long string to the right is your token
Please remember, tokens should be treated exactly like passwords. Never give out your token, and if you do, only give it to people you would trust with your password. Another thing to keep in mind; it's always good etiquette to automate seperate accounts, dedicated for automation, rather than your own.
Implementations
impl<'u, 't> Client<'u, 't>
[src]
pub fn new(token: &'t str) -> Self
[src]
Creates a new client with an authentication token. Uses the official hiven.io servers.
pub fn new_at(token: &'t str, api_base: &'u str, gateway_base: &'u str) -> Self
[src]
Creates a new client with an authentication token, allows you to specify a base domain for the api and gateway.
pub async fn new_gate_keeper<'c, E>(
&'c self,
event_handler: E
) -> GateKeeper<'c, 'u, 't, E> where
E: EventHandler,
[src]
&'c self,
event_handler: E
) -> GateKeeper<'c, 'u, 't, E> where
E: EventHandler,
pub async fn start_gateway<E, '_>(
&'_ self,
event_handler: E
) -> STDResult<(), Error> where
E: EventHandler,
[src]
&'_ self,
event_handler: E
) -> STDResult<(), Error> where
E: EventHandler,
Takes control of this thread, starting a connection to the gateway and dispatching gateway events asynchronously.
This method takes an event handler to handle all gateway events. Gateway
events you do not implement will default to a method that does nothing
(NoOp). Due to limitations with traits (and the async_trait macro), event
handlers are not marked as async
, but are asynchronous in spirit.
Implementing an event listener can be done like this...
use hiven_rs::{client::{Client, EventHandler}, data::Message}; use std::{future::Future, pin::Pin}; // ... impl EventHandler for MyEventHandler { fn on_message<'c>(&self, client: &'c Client, event: Message) -> Pin<Box<dyn Future<Output = ()> + 'c>> { Box::pin(async move { // Asynchronous code goes here. }) } }
This method currently is not expected to return ever, unless during panic
unwinding, and it's return value should be treated as !
(the never
type).
pub async fn send_message<R, '_>(
&'_ self,
room: R,
content: String
) -> STDResult<(), Error> where
R: Into<u64>,
[src]
&'_ self,
room: R,
content: String
) -> STDResult<(), Error> where
R: Into<u64>,
pub async fn edit_message<'_>(
&'_ self,
room: impl Into<u64>,
message: impl Into<u64>,
content: String
) -> STDResult<(), Error>
[src]
&'_ self,
room: impl Into<u64>,
message: impl Into<u64>,
content: String
) -> STDResult<(), Error>
pub async fn delete_message<'_>(
&'_ self,
room: impl Into<u64>,
message: impl Into<u64>
) -> STDResult<(), Error>
[src]
&'_ self,
room: impl Into<u64>,
message: impl Into<u64>
) -> STDResult<(), Error>
pub async fn trigger_typing<R, '_>(&'_ self, room: R) -> STDResult<(), Error> where
R: Into<u64>,
[src]
R: Into<u64>,
impl Client<'static, 'static>
[src]
pub fn start_gateway_later<E>(
self: Arc<Self>,
event_handler: E
) -> JoinHandle<()> where
E: EventHandler + 'static,
[src]
self: Arc<Self>,
event_handler: E
) -> JoinHandle<()> where
E: EventHandler + 'static,
Auto Trait Implementations
impl<'u, 't> !RefUnwindSafe for Client<'u, 't>
impl<'u, 't> Send for Client<'u, 't>
impl<'u, 't> Sync for Client<'u, 't>
impl<'u, 't> Unpin for Client<'u, 't>
impl<'u, 't> !UnwindSafe for Client<'u, 't>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,