Skip to content

Commit

Permalink
Run rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
exul committed May 13, 2017
1 parent 2a436cc commit 7342358
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/matrix-rocketchat/api/matrix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ impl MatrixApi {
debug!(logger, format!("Querying homeserver {} for API versions", url));
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(|| {
let matrix_error_resp: MatrixErrorResponse = serde_json::from_str(&body)
.chain_err(|| {
ErrorKind::InvalidJSON(format!("Could not deserialize error response from Matrix supported versions \
API endpoint: `{}` ",
body))
Expand Down
9 changes: 5 additions & 4 deletions src/matrix-rocketchat/api/matrix/r0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ impl super::MatrixApi for MatrixApi {
return Err(build_error(&endpoint, &body, &status_code));
}

let create_room_response: create_room::Response = serde_json::from_str(&body).chain_err(|| {
let create_room_response: create_room::Response = serde_json::from_str(&body)
.chain_err(|| {
ErrorKind::InvalidJSON(format!("Could not deserialize response from Matrix create_room API endpoint: \
`{}`",
body))
Expand Down Expand Up @@ -107,9 +108,9 @@ impl super::MatrixApi for MatrixApi {

debug!(self.logger, format!("List of room members for room {} successfully received", matrix_room_id));

let room_member_events: get_member_events::Response = serde_json::from_str(&body).chain_err(|| {
ErrorKind::InvalidJSON(format!("Could not deserialize response from Matrix members API endpoint: `{}`",
body))
let room_member_events: get_member_events::Response = serde_json::from_str(&body)
.chain_err(|| {
ErrorKind::InvalidJSON(format!("Could not deserialize response from Matrix members API endpoint: `{}`", body))
})?;
Ok(room_member_events.chunk)
}
Expand Down
22 changes: 13 additions & 9 deletions src/matrix-rocketchat/api/rocketchat/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ impl super::RocketchatApi for RocketchatApi {
return Err(build_error(&me_endpoint.url(), &body, &status_code));
}

let me_response: MeResponse = serde_json::from_str(&body).chain_err(|| {
ErrorKind::InvalidJSON(format!("Could not deserialize response from Rocket.Chat me API endpoint: `{}`",
body))
let me_response: MeResponse = serde_json::from_str(&body)
.chain_err(|| {
ErrorKind::InvalidJSON(format!("Could not deserialize response from Rocket.Chat me API endpoint: `{}`", body))
})?;

Ok(me_response.username)
Expand All @@ -262,7 +262,8 @@ impl super::RocketchatApi for RocketchatApi {
return Err(build_error(&login_endpoint.url(), &body, &status_code));
}

let login_response: LoginResponse = serde_json::from_str(&body).chain_err(|| {
let login_response: LoginResponse = serde_json::from_str(&body)
.chain_err(|| {
ErrorKind::InvalidJSON(format!("Could not deserialize response from Rocket.Chat login API endpoint: `{}`",
body))
})?;
Expand Down Expand Up @@ -308,7 +309,8 @@ impl super::RocketchatApi for RocketchatApi {
return Err(build_error(&users_info_endpoint.url(), &body, &status_code));
}

let users_info_response: UsersInfoResponse = serde_json::from_str(&body).chain_err(|| {
let users_info_response: UsersInfoResponse = serde_json::from_str(&body)
.chain_err(|| {
ErrorKind::InvalidJSON(format!("Could not deserialize response from Rocket.Chat users.info API endpoint: `{}`",
body))
})?;
Expand Down Expand Up @@ -344,9 +346,11 @@ fn build_error(endpoint: &str, body: &str, status_code: &StatusCode) -> Error {
};
}

let msg = rocketchat_error_resp
.message
.clone()
.unwrap_or_else(|| rocketchat_error_resp.error.clone().unwrap_or_else(|| body.to_string()));
let msg = rocketchat_error_resp.message.clone().unwrap_or_else(|| {
rocketchat_error_resp
.error
.clone()
.unwrap_or_else(|| body.to_string())
});
Error::from(ErrorKind::RocketchatError(msg))
}
3 changes: 2 additions & 1 deletion src/matrix-rocketchat/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ error_chain!{

ConnectWithInvalidRocketchatServerId(rocketchat_server_id: String) {
description("Connect command with an invalid Rocket.Chat server ID.")
display("Attempt to connect with the Rocket.Chat server ID {}, which contains invalid characters.", rocketchat_server_id)
display("Attempt to connect with the Rocket.Chat server ID {}, which contains invalid characters.",
rocketchat_server_id)
}

RocketchatServerIdAlreadyInUse(rocketchat_server_id: String) {
Expand Down
17 changes: 7 additions & 10 deletions src/matrix-rocketchat/handlers/events/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,9 @@ impl<'a> CommandHandler<'a> {
if let Some(rocketchat_server) = RocketchatServer::find_by_url(self.connection, rocketchat_url.clone())? {
if rocketchat_server.rocketchat_token.is_some() {
bail_error!(ErrorKind::RocketchatServerAlreadyConnected(rocketchat_url.clone()),
t!(["errors", "rocketchat_server_already_connected"]).with_vars(vec![("rocketchat_url",
rocketchat_url),
("matrix_user_id",
matrix_user_id
.to_string())]));
t!(["errors", "rocketchat_server_already_connected"])
.with_vars(vec![("rocketchat_url", rocketchat_url),
("matrix_user_id", matrix_user_id.to_string())]));
}
}

Expand Down Expand Up @@ -437,11 +435,10 @@ impl<'a> CommandHandler<'a> {
t!(["admin_room", "usage_instructions"]).with_vars(vec![("rocketchat_url",
rocketchat_server.rocketchat_url)])
} else {
t!(["admin_room", "login_instructions"]).with_vars(vec![("rocketchat_url",
rocketchat_server.rocketchat_url),
("as_url", as_url),
("matrix_user_id",
user.matrix_user_id.to_string())])
t!(["admin_room", "login_instructions"])
.with_vars(vec![("rocketchat_url", rocketchat_server.rocketchat_url),
("as_url", as_url),
("matrix_user_id", user.matrix_user_id.to_string())])
}
}
None => {
Expand Down
12 changes: 6 additions & 6 deletions tests/admin_commands_login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn sucessfully_login_via_rest_api() {
let payload = to_string(&login_request).unwrap();
let (response, status_code) = RestApi::call(Method::Post,
&format!("http://{}/rocketchat/login",
test.as_listening.as_ref().unwrap().socket),
test.as_listening.as_ref().unwrap().socket),
&payload,
&HashMap::new(),
None)
Expand Down Expand Up @@ -216,7 +216,7 @@ fn wrong_password_when_logging_in_via_rest_api() {
let payload = to_string(&login_request).unwrap();
let (response, status_code) = RestApi::call(Method::Post,
&format!("http://{}/rocketchat/login",
test.as_listening.as_ref().unwrap().socket),
test.as_listening.as_ref().unwrap().socket),
&payload,
&HashMap::new(),
None)
Expand Down Expand Up @@ -269,7 +269,7 @@ fn login_multiple_times_via_rest_message() {
for _ in 0..2 {
let (response, status_code) = RestApi::call(Method::Post,
&format!("http://{}/rocketchat/login",
test.as_listening.as_ref().unwrap().socket),
test.as_listening.as_ref().unwrap().socket),
&payload,
&HashMap::new(),
None)
Expand All @@ -296,7 +296,7 @@ fn login_via_rest_api_with_invalid_payload() {

let (response, status_code) = RestApi::call(Method::Post,
&format!("http://{}/rocketchat/login",
test.as_listening.as_ref().unwrap().socket),
test.as_listening.as_ref().unwrap().socket),
"not json",
&HashMap::new(),
None)
Expand All @@ -320,7 +320,7 @@ fn login_via_rest_api_with_a_non_existing_rocketchat_server() {

let (response, status_code) = RestApi::call(Method::Post,
&format!("http://{}/rocketchat/login",
test.as_listening.as_ref().unwrap().socket),
test.as_listening.as_ref().unwrap().socket),
&payload,
&HashMap::new(),
None)
Expand All @@ -344,7 +344,7 @@ fn login_via_rest_api_with_a_user_that_has_no_connected_admin_room_for_the_rocke

let (response, status_code) = RestApi::call(Method::Post,
&format!("http://{}/rocketchat/login",
test.as_listening.as_ref().unwrap().socket),
test.as_listening.as_ref().unwrap().socket),
&payload,
&HashMap::new(),
None)
Expand Down

0 comments on commit 7342358

Please sign in to comment.