diff --git a/src/client.rs b/src/client.rs index 273b3f402c42210ffb61adbf9a0ad16cd269613d..9cb5a7adec9b25d4bb4785a5daaf2a6d1d27de91 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,11 +1,46 @@ use jid::Jid; +use transport::SslTransport; +use error::Error; -pub struct XmppClient { - transport: SslTransport, +pub struct ClientBuilder { + jid: Jid, + host: Option, + port: u16, } -impl XmppClient { - pub fn connect(jid: Jid) -> XmppClient { - unimplemented!(); +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 { + let host = &self.host.unwrap_or(self.jid.domain.clone()); + let transport = SslTransport::connect(host, self.port)?; + Ok(Client { + jid: self.jid, + transport: transport + }) } } + +pub struct Client { + jid: Jid, + transport: SslTransport, +} + +impl Client { +} diff --git a/src/lib.rs b/src/lib.rs index 7b83b351d0d110f35b42ec65a3f89a56e429fff3..ca596a6fdf0c8fe47f2b34a28f6e296a0f3c8d47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,3 +5,4 @@ pub mod ns; pub mod transport; pub mod error; pub mod jid; +pub mod client;