Struct hornbill_apilib::Xmlmc
source · pub struct Xmlmc { /* private fields */ }
Expand description
The xmlmc struct which contains all the methods required to interact with the hornbill api.
Implementations§
source§impl Xmlmc
impl Xmlmc
sourcepub fn new(s: &str) -> Result<Xmlmc, Box<dyn Error>>
pub fn new(s: &str) -> Result<Xmlmc, Box<dyn Error>>
You can can create a xmlmc object that can be used to send data to your hornbill instance This will be created with a default timeout of 30 seconds and user_agent of “rust_apilib/1.1”
let mut c = Xmlmc::new(&url).expect("Could not create client");
sourcepub fn set_param(&mut self, key: &str, value: &str) -> Result<(), &str>
pub fn set_param(&mut self, key: &str, value: &str) -> Result<(), &str>
You can add parameters to the xml you will be sending to the server. Any not utf8 text in value will be replace with the utf8 replacement character.
c.set_param("username","admin");
sourcepub fn set_param_attr(
&mut self,
key: &str,
value: &str,
attribs: Vec<Attributes>
) -> Result<(), &str>
pub fn set_param_attr( &mut self, key: &str, value: &str, attribs: Vec<Attributes> ) -> Result<(), &str>
You can set multiple
sourcepub fn get_params(&self) -> String
pub fn get_params(&self) -> String
You can use this to return the full xml we would be sending to the server
let xml_output = c.get_params();
sourcepub fn clear_params(&mut self)
pub fn clear_params(&mut self)
You can use this to clear the contents of the xml you would send to the server. This is automtically called at the end of invoke so you can reuse the connection and send more requests.
c.clear_params()
sourcepub fn set_user_agent(&mut self, user: &str)
pub fn set_user_agent(&mut self, user: &str)
You can use this to set the useragent string that is sent to the hornbill server. This defaults to “rust_apilib/1.1” You should set this to something unique for you so we can see who is calling our api endpoints.
c.set_user_agent("demo_ldapimport/1.1");
sourcepub fn set_json_response(&mut self, b: bool)
pub fn set_json_response(&mut self, b: bool)
You can use this is ask for a json response from the server. It sets the Accept header to “text/json” so it knows to response with json otherwise it uses xml.
c.set_json_response(true);
sourcepub fn get_session_id(&self) -> String
pub fn get_session_id(&self) -> String
You can use this to get the currently set sessionId. This sessionId will be generated when you call userLogon or guestLogon and stored in the Xmlmc object for all other calls after this.
let session_id = c.get_session_id();
sourcepub fn set_apikey(&mut self, s: &str)
pub fn set_apikey(&mut self, s: &str)
You can use this to set an APIkey https://wiki.hornbill.com/index.php/API_keys that can be used to identify youeself rather than the logon APIS.
c.set_apikey("1234567890");
sourcepub fn set_sessionid(&mut self, s: &str)
pub fn set_sessionid(&mut self, s: &str)
You can use this to set a session_id that you have retrieved after calling userLogon or guestLogon
c.set_sessionid("1234567890");
sourcepub fn set_trace(&mut self, s: &str)
pub fn set_trace(&mut self, s: &str)
You can use this to set a a trace identifier. This can then be used to identify in logging this exact api call.
c.set_trace("0987654321zxc");
sourcepub fn set_copy_headers(&mut self, s: bool)
pub fn set_copy_headers(&mut self, s: bool)
You can use this to tell the library to copy out all headers recieved back from the server for later use. You can then use the get_headers() method to view the headers after the invoke call.
c.set_copy_headers(true);
sourcepub fn get_status_code(&self) -> u16
pub fn get_status_code(&self) -> u16
You can use this to check the last http status number the server returned from an invoke call.
let status = c.get_status_code();
sourcepub fn get_server_url(&self) -> String
pub fn get_server_url(&self) -> String
You can use this to get the currently set url for the server you will be connecting to.
let server_url = c.get_server_url();
sourcepub fn get_count(&self) -> u64
pub fn get_count(&self) -> u64
You can use this to get the number of http requests that have been made by this xmlmc object.
let counter = c.get_count();
sourcepub fn get_headers(&self) -> HeaderMap
pub fn get_headers(&self) -> HeaderMap
You can use this to get the headers that were sent by the server for the last http call. You will need to call set_copy_headers(true) before any invoke call so that we save the headers. check out the responseheaders example to see how to query the headers.
let headers = c.get_headers();
sourcepub fn invoke(&mut self, service: &str, method: &str) -> Result<String, String>
pub fn invoke(&mut self, service: &str, method: &str) -> Result<String, String>
You can use this to make the http call to the server with the xml you have built. The result will either contain a Ok(string) with the response body in or an Err(String) with the error message of what failed.
let headers = c.invoke();