Commit df795c14 authored by Ben Boeckel's avatar Ben Boeckel Committed by Kitware Robot
Browse files

Merge topic 'builder-pattern'

479e8a74

 gitlab: Enable construction via builder pattern
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Ben Boeckel's avatarBen Boeckel <ben.boeckel@kitware.com>
Merge-request: !111
parents 8c056425 479e8a74
......@@ -112,6 +112,14 @@ impl Gitlab {
Ok(api)
}
/// Create a new Gitlab API client builder.
pub fn builder<H, T>(host: H, token: T) -> GitlabBuilder
where H: ToString,
T: ToString,
{
GitlabBuilder::new(host, token)
}
/// The user the API is acting as.
pub fn current_user(&self) -> Result<UserPublic> {
self.get("user")
......@@ -607,3 +615,34 @@ impl Gitlab {
Ok(results)
}
}
pub struct GitlabBuilder {
protocol: &'static str,
host: String,
token: String,
}
impl GitlabBuilder {
/// Create a new Gitlab API client builder.
pub fn new<H, T>(host: H, token: T) -> Self
where H: ToString,
T: ToString,
{
Self {
protocol: "https",
host: host.to_string(),
token: token.to_string(),
}
}
/// Switch to an insecure protocol (http instead of https).
pub fn insecure(&mut self) -> &mut Self
{
self.protocol = "http";
self
}
pub fn build(&self) -> Result<Gitlab> {
Gitlab::new_impl(self.protocol, &self.host, self.token.clone())
}
}
......@@ -51,6 +51,7 @@ pub use error::*;
pub use gitlab::CommitStatusInfo;
pub use gitlab::MergeRequestStateFilter;
pub use gitlab::Gitlab;
pub use gitlab::GitlabBuilder;
pub use types::*;
#[cfg(test)]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment