Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
exul committed Feb 5, 2019
1 parent 8884b8d commit 46988ec
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/matrix-rocketchat/api/matrix/mod.rs
Expand Up @@ -103,7 +103,7 @@ impl MatrixApi {
let params = HashMap::new();

debug!(logger, "Querying homeserver {} for API versions", url);
let (body, status_code) = RestApi::call_matrix(&GetSupportedVersionsEndpoint::method(), &url, "", &params)?;
let (body, status_code) = RestApi::call_matrix(GetSupportedVersionsEndpoint::method(), &url, "", &params)?;
if !status_code.is_success() {
let matrix_error_resp: MatrixErrorResponse = serde_json::from_str(&body).chain_err(|| {
ErrorKind::InvalidJSON(format!(
Expand Down
48 changes: 24 additions & 24 deletions src/matrix-rocketchat/api/matrix/r0.rs
Expand Up @@ -83,7 +83,7 @@ impl super::MatrixApi for MatrixApi {
let mut params = self.params_hash();
params.insert("user_id", &user_id);

let (body, status_code) = RestApi::call_matrix(&CreateRoomEndpoint::method(), &endpoint, payload, &params)?;
let (body, status_code) = RestApi::call_matrix(CreateRoomEndpoint::method(), &endpoint, payload, &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -103,7 +103,7 @@ impl super::MatrixApi for MatrixApi {
let endpoint = self.base_url.clone() + &format!("/_matrix/client/r0/directory/room/{}", &encoded_room_alias);
let params = self.params_hash();

let (body, status_code) = RestApi::call_matrix(&DeleteAliasEndpoint::method(), &endpoint, "{}", &params)?;
let (body, status_code) = RestApi::call_matrix(DeleteAliasEndpoint::method(), &endpoint, "{}", &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -118,7 +118,7 @@ impl super::MatrixApi for MatrixApi {
let mut params = self.params_hash();
params.insert("user_id", &user_id);

let (body, status_code) = RestApi::call_matrix(&ForgetRoomEndpoint::method(), &endpoint, "{}", &params)?;
let (body, status_code) = RestApi::call_matrix(ForgetRoomEndpoint::method(), &endpoint, "{}", &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -130,7 +130,7 @@ impl super::MatrixApi for MatrixApi {
let endpoint = self.base_url.clone() + &GetContentEndpoint::request_path(path_params);
let params = self.params_hash();

let mut resp = RestApi::get_matrix_file(&GetContentEndpoint::method(), &endpoint, "", &params)?;
let mut resp = RestApi::get_matrix_file(GetContentEndpoint::method(), &endpoint, "", &params)?;
if !resp.status().is_success() {
let mut body = String::new();
resp.read_to_string(&mut body).chain_err(|| ErrorKind::ApiCallFailed(endpoint.clone()))?;
Expand All @@ -148,7 +148,7 @@ impl super::MatrixApi for MatrixApi {
let endpoint = self.base_url.clone() + &GetDisplayNameEndpoint::request_path(path_params);
let params = self.params_hash();

let (body, status_code) = RestApi::call_matrix(&GetDisplayNameEndpoint::method(), &endpoint, "", &params)?;
let (body, status_code) = RestApi::call_matrix(GetDisplayNameEndpoint::method(), &endpoint, "", &params)?;
if status_code == StatusCode::NOT_FOUND {
return Ok(None);
}
Expand All @@ -173,7 +173,7 @@ impl super::MatrixApi for MatrixApi {
let mut params = self.params_hash();
params.insert("user_id", &user_id);

let (body, status_code) = RestApi::call_matrix(&SyncEventsEndpoint::method(), &endpoint, "", &params)?;
let (body, status_code) = RestApi::call_matrix(SyncEventsEndpoint::method(), &endpoint, "", &params)?;

if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
Expand All @@ -196,7 +196,7 @@ impl super::MatrixApi for MatrixApi {
let endpoint = self.base_url.clone() + &format!("/_matrix/client/r0/directory/room/{}", &encoded_room_alias);
let params = self.params_hash();

let (body, status_code) = RestApi::call_matrix(&GetAliasEndpoint::method(), &endpoint, "{}", &params)?;
let (body, status_code) = RestApi::call_matrix(GetAliasEndpoint::method(), &endpoint, "{}", &params)?;
if status_code == StatusCode::NOT_FOUND {
return Ok(None);
}
Expand All @@ -219,7 +219,7 @@ impl super::MatrixApi for MatrixApi {
let mut params = self.params_hash();
params.insert("user_id", &user_id);

let (body, status_code) = RestApi::call_matrix(&GetStateEvents::method(), &endpoint, "", &params)?;
let (body, status_code) = RestApi::call_matrix(GetStateEvents::method(), &endpoint, "", &params)?;

if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
Expand Down Expand Up @@ -248,7 +248,7 @@ impl super::MatrixApi for MatrixApi {
let endpoint = self.base_url.clone() + &GetStateEventsForEmptyKeyEndpoint::request_path(path_params);
let params = self.params_hash();

let (body, status_code) = RestApi::call_matrix(&GetStateEventsForEmptyKeyEndpoint::method(), &endpoint, "{}", &params)?;
let (body, status_code) = RestApi::call_matrix(GetStateEventsForEmptyKeyEndpoint::method(), &endpoint, "{}", &params)?;
if status_code == StatusCode::NOT_FOUND {
return Ok(None);
}
Expand Down Expand Up @@ -278,7 +278,7 @@ impl super::MatrixApi for MatrixApi {
let endpoint = self.base_url.clone() + &GetStateEventsForEmptyKeyEndpoint::request_path(path_params);
let params = self.params_hash();

let (body, status_code) = RestApi::call_matrix(&GetStateEventsForEmptyKeyEndpoint::method(), &endpoint, "{}", &params)?;
let (body, status_code) = RestApi::call_matrix(GetStateEventsForEmptyKeyEndpoint::method(), &endpoint, "{}", &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -305,7 +305,7 @@ impl super::MatrixApi for MatrixApi {
params.insert("user_id", &user_id);
}

let (body, status_code) = RestApi::call_matrix(&GetMemberEventsEndpoint::method(), &endpoint, "{}", &params)?;
let (body, status_code) = RestApi::call_matrix(GetMemberEventsEndpoint::method(), &endpoint, "{}", &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -323,7 +323,7 @@ impl super::MatrixApi for MatrixApi {
let endpoint = self.base_url.clone() + &GetStateEventsForEmptyKeyEndpoint::request_path(path_params);
let params = self.params_hash();

let (body, status_code) = RestApi::call_matrix(&GetStateEventsForEmptyKeyEndpoint::method(), &endpoint, "{}", &params)?;
let (body, status_code) = RestApi::call_matrix(GetStateEventsForEmptyKeyEndpoint::method(), &endpoint, "{}", &params)?;
if status_code == StatusCode::NOT_FOUND {
return Ok(None);
}
Expand Down Expand Up @@ -351,7 +351,7 @@ impl super::MatrixApi for MatrixApi {
let body_params = invite_user::BodyParams { user_id: receiver_user_id.clone() };
let payload = serde_json::to_string(&body_params).chain_err(|| body_params_error!("invite"))?;

let (body, status_code) = RestApi::call_matrix(&InviteUserEndpoint::method(), &endpoint, payload, &params)?;
let (body, status_code) = RestApi::call_matrix(InviteUserEndpoint::method(), &endpoint, payload, &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -365,7 +365,7 @@ impl super::MatrixApi for MatrixApi {
let endpoint = self.base_url.clone() + &GetStateEventsForEmptyKeyEndpoint::request_path(path_params);
let params = self.params_hash();

let (_, status_code) = RestApi::call_matrix(&GetStateEventsForEmptyKeyEndpoint::method(), &endpoint, "{}", &params)?;
let (_, status_code) = RestApi::call_matrix(GetStateEventsForEmptyKeyEndpoint::method(), &endpoint, "{}", &params)?;

Ok(status_code != StatusCode::FORBIDDEN)
}
Expand All @@ -377,7 +377,7 @@ impl super::MatrixApi for MatrixApi {
let mut params = self.params_hash();
params.insert("user_id", &user_id);

let (body, status_code) = RestApi::call_matrix(&JoinRoomByIdEndpoint::method(), &endpoint, "{}", &params)?;
let (body, status_code) = RestApi::call_matrix(JoinRoomByIdEndpoint::method(), &endpoint, "{}", &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -393,7 +393,7 @@ impl super::MatrixApi for MatrixApi {
let mut params = self.params_hash();
params.insert("user_id", &user_id);

let (body, status_code) = RestApi::call_matrix(&LeaveRoomEndpoint::method(), &endpoint, "{}", &params)?;
let (body, status_code) = RestApi::call_matrix(LeaveRoomEndpoint::method(), &endpoint, "{}", &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -414,7 +414,7 @@ impl super::MatrixApi for MatrixApi {
let payload = serde_json::to_string(&body_params).chain_err(|| body_params_error!("canonical room alias"))?;

let (body, status_code) =
RestApi::call_matrix(&SendStateEventForEmptyKeyEndpoint::method(), &endpoint, payload, &params)?;
RestApi::call_matrix(SendStateEventForEmptyKeyEndpoint::method(), &endpoint, payload, &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -434,7 +434,7 @@ impl super::MatrixApi for MatrixApi {
};
let payload = serde_json::to_string(&body_params).chain_err(|| body_params_error!("account"))?;

let (body, status_code) = RestApi::call_matrix(&RegisterEndpoint::method(), &endpoint, payload, &params)?;
let (body, status_code) = RestApi::call_matrix(RegisterEndpoint::method(), &endpoint, payload, &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -460,7 +460,7 @@ impl super::MatrixApi for MatrixApi {
let mut params = self.params_hash();
params.insert("user_id", &user_id);

let (body, status_code) = RestApi::call_matrix(&SendMessageEventEndpoint::method(), &endpoint, payload, &params)?;
let (body, status_code) = RestApi::call_matrix(SendMessageEventEndpoint::method(), &endpoint, payload, &params)?;

if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
Expand All @@ -487,7 +487,7 @@ impl super::MatrixApi for MatrixApi {
let mut params = self.params_hash();
params.insert("user_id", &user_id);

let (body, status_code) = RestApi::call_matrix(&SendMessageEventEndpoint::method(), &endpoint, payload, &params)?;
let (body, status_code) = RestApi::call_matrix(SendMessageEventEndpoint::method(), &endpoint, payload, &params)?;

if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
Expand Down Expand Up @@ -515,7 +515,7 @@ impl super::MatrixApi for MatrixApi {
let payload = serde_json::to_string(&body_params).chain_err(|| body_params_error!("power levels"))?;

let (body, status_code) =
RestApi::call_matrix(&SendStateEventForEmptyKeyEndpoint::method(), &endpoint, payload, &params)?;
RestApi::call_matrix(SendStateEventForEmptyKeyEndpoint::method(), &endpoint, payload, &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -531,7 +531,7 @@ impl super::MatrixApi for MatrixApi {
let body_params = set_display_name::BodyParams { displayname: Some(name) };
let payload = serde_json::to_string(&body_params).chain_err(|| body_params_error!("set display name"))?;

let (body, status_code) = RestApi::call_matrix(&SetDisplayNameEndpoint::method(), &endpoint, payload, &params)?;
let (body, status_code) = RestApi::call_matrix(SetDisplayNameEndpoint::method(), &endpoint, payload, &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -547,7 +547,7 @@ impl super::MatrixApi for MatrixApi {
let payload = serde_json::to_string(&body_params).chain_err(|| body_params_error!("room name"))?;

let (body, status_code) =
RestApi::call_matrix(&SendStateEventForEmptyKeyEndpoint::method(), &endpoint, payload, &params)?;
RestApi::call_matrix(SendStateEventForEmptyKeyEndpoint::method(), &endpoint, payload, &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand All @@ -563,7 +563,7 @@ impl super::MatrixApi for MatrixApi {
let payload = serde_json::to_string(&body_params).chain_err(|| body_params_error!("room topic"))?;

let (body, status_code) =
RestApi::call_matrix(&SendStateEventForEmptyKeyEndpoint::method(), &endpoint, payload, &params)?;
RestApi::call_matrix(SendStateEventForEmptyKeyEndpoint::method(), &endpoint, payload, &params)?;
if !status_code.is_success() {
return Err(build_error(&endpoint, &body, &status_code));
}
Expand Down
8 changes: 4 additions & 4 deletions src/matrix-rocketchat/api/rest_api.rs
Expand Up @@ -24,12 +24,12 @@ pub struct RestApi {}
impl RestApi {
/// Call a matrix REST API endpoint
pub fn call_matrix<'a, T: Into<Body>>(
method: &RumaHttpMethod,
method: RumaHttpMethod,
url: &str,
payload: T,
params: &HashMap<&str, &'a str>,
) -> Result<(String, StatusCode)> {
let method = match *method {
let method = match method {
RumaHttpMethod::Delete => Method::DELETE,
RumaHttpMethod::Get => Method::GET,
RumaHttpMethod::Post => Method::POST,
Expand All @@ -42,12 +42,12 @@ impl RestApi {

/// Get a file that was uploaded to a Matrix homeserver
pub fn get_matrix_file<'a, T: Into<Body>>(
method: &RumaHttpMethod,
method: RumaHttpMethod,
url: &str,
payload: T,
params: &HashMap<&str, &'a str>,
) -> Result<Response> {
let method = match *method {
let method = match method {
RumaHttpMethod::Delete => Method::DELETE,
RumaHttpMethod::Get => Method::GET,
RumaHttpMethod::Post => Method::POST,
Expand Down

0 comments on commit 46988ec

Please sign in to comment.