Client

Struct Client 

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

The network client to use to interact with the Etebase server

This is in charge of actually connecting to the server and making network requests. If the "networking" crate feature is enabled, it uses an internal HTTP client based on the reqwest crate. If the feature is not enabled, an external HTTP(S) client implementation implementing the ClientImplementation trait needs to be supplied.

Implementations§

Source§

impl Client

Source

pub fn new(client_name: &str, server_url: &str) -> Result<Self>

Creates a new client object for the server located at server_url.

The client_name will be used to populate the User-Agent header in all requests to the server.

§Examples
use etebase::Client;

// For an application called "FancyClient"
let my_client = Client::new("FancyClient", "https://myhost.example");
Examples found in repository?
examples/etebase_test.rs (line 34)
22fn main() -> Result<()> {
23    let args: Vec<String> = env::args().collect();
24
25    if args.len() < 4 {
26        println!("Help: ./etebase_test USERNAME PASSWORD SERVER_URL [COLLECTION_UID]");
27        std::process::exit(1);
28    }
29
30    let username = &args[1];
31    let password = &args[2];
32    let server_url = &args[3];
33
34    let client = Client::new(CLIENT_NAME, server_url)?;
35    let etebase = Account::login(client, username, password)?;
36    let col_mgr = etebase.collection_manager()?;
37    if args.len() >= 5 {
38        let col_uid = &args[4];
39        let col = col_mgr.fetch(col_uid, None)?;
40        let it_mgr = col_mgr.item_manager(&col)?;
41        let items = it_mgr.list(None)?;
42
43        print_collection(&col);
44        for item in items.data() {
45            print_item(item);
46        }
47    } else {
48        let collections = col_mgr.list("some.coltype", None)?;
49        for col in collections.data() {
50            print_collection(col);
51        }
52    }
53
54    etebase.logout()?;
55
56    Ok(())
57}
Source

pub fn is_server_valid(&self) -> Result<bool>

Checks whether the Client is pointing to a valid Etebase server.

§Examples
use etebase::Client;

let invalid_client = Client::new("ExampleClient", "https://example.com").unwrap();
assert!(!invalid_client.is_server_valid().unwrap());

let valid_client = Client::new("ExampleClient", "https://api.etebase.com/").unwrap();
assert!(valid_client.is_server_valid().unwrap());
Source

pub fn set_server_url(&mut self, server_url: &str) -> Result<()>

Set the server url associated with this client

§Examples
use etebase::Client;

let mut client = Client::new("ExampleClient", "https://invalid.example").unwrap();
client.set_server_url("https://another.example");

assert_eq!(client.server_url().to_string(), "https://another.example/");
Source

pub fn server_url(&self) -> &Url

Return the server url associated with this client

§Examples
use etebase::Client;

let client = Client::new("ExampleClient", "https://invalid.example").unwrap();

assert_eq!(client.server_url().to_string(), "https://invalid.example/");

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe 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<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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<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