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
impl Client
Sourcepub fn new(client_name: &str, server_url: &str) -> Result<Self>
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}Sourcepub fn is_server_valid(&self) -> Result<bool>
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());Sourcepub fn set_server_url(&mut self, server_url: &str) -> Result<()>
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/");Sourcepub fn server_url(&self) -> &Url
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§
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> 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