2017-02-18 21:16:20 +00:00
|
|
|
use jid::Jid;
|
2017-02-18 23:01:39 +00:00
|
|
|
use transport::SslTransport;
|
|
|
|
use error::Error;
|
2017-02-18 21:16:20 +00:00
|
|
|
|
2017-02-18 23:01:39 +00:00
|
|
|
pub struct ClientBuilder {
|
|
|
|
jid: Jid,
|
|
|
|
host: Option<String>,
|
|
|
|
port: u16,
|
2017-02-18 21:16:20 +00:00
|
|
|
}
|
|
|
|
|
2017-02-18 23:01:39 +00:00
|
|
|
impl ClientBuilder {
|
|
|
|
pub fn new(jid: Jid) -> ClientBuilder {
|
|
|
|
ClientBuilder {
|
|
|
|
jid: jid,
|
|
|
|
host: None,
|
|
|
|
port: 5222,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn host(mut self, host: String) -> ClientBuilder {
|
|
|
|
self.host = Some(host);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn port(mut self, port: u16) -> ClientBuilder {
|
|
|
|
self.port = port;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn connect(self) -> Result<Client, Error> {
|
|
|
|
let host = &self.host.unwrap_or(self.jid.domain.clone());
|
|
|
|
let transport = SslTransport::connect(host, self.port)?;
|
|
|
|
Ok(Client {
|
|
|
|
jid: self.jid,
|
|
|
|
transport: transport
|
|
|
|
})
|
2017-02-18 21:16:20 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-18 23:01:39 +00:00
|
|
|
|
|
|
|
pub struct Client {
|
|
|
|
jid: Jid,
|
|
|
|
transport: SslTransport,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Client {
|
|
|
|
}
|