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

source

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");
source

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");
source

pub fn set_param_attr( &mut self, key: &str, value: &str, attribs: Vec<Attributes> ) -> Result<(), &str>

You can set multiple

source

pub fn open_element(&mut self, element: &str) -> Result<(), &str>

You can use this to open an xml element in your xml output to the server

c.open_element("userObject");

This will append

<userObject>
source

pub fn close_element(&mut self, element: &str) -> Result<(), &str>

You can use this to close an xml element in your xml output to the server

c.close_element("userObject");

This will append

</userObject>
source

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();
source

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()
source

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");
source

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);
source

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();
source

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");
source

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");
source

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");
source

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);
source

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();
source

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();
source

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();
source

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();
source

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();

Auto Trait Implementations§

§

impl Freeze for Xmlmc

§

impl !RefUnwindSafe for Xmlmc

§

impl Send for Xmlmc

§

impl Sync for Xmlmc

§

impl Unpin for Xmlmc

§

impl !UnwindSafe for Xmlmc

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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