Skip to content

Commit

Permalink
Merged
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Dec 27, 2020
2 parents 516f99d + d16e8c7 commit b259173
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 24 deletions.
16 changes: 9 additions & 7 deletions src/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "slack-morphism"
version = "0.3.1"
version = "0.4.0"
authors = ["Abdulla Abdurakhmanov <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -18,20 +18,22 @@ name = "slack_morphism"
path = "src/lib.rs"

[dependencies]
slack-morphism-models = { path = "../models", version = "^0.3.0" }
slack-morphism-models = { path = "../models", version = "^0.4.0" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = "1.5"
serde_with = "1.6"
rvstruct = "0.2"
rsb_derive = "0.3"
hyper = "0.13"
tokio = { version = "0.2", features = ["full"] }
hyper-tls = "0.4"
hyper = { version ="0.14", features = ["full"] }
tokio = { version = "1.0", features = ["full"] }
tokio-stream = { version = "0.1.0" }
hyper-rustls = "0.22"
#hyper-tls = "0.4"
url = "2.2"
mime = "0.3"
futures = "0.3"
futures-util = "0.3"
bytes = "0.5"
bytes = "1.0"
base64 = "0.13"
hex = "0.4"
log = "0.4"
Expand Down
9 changes: 5 additions & 4 deletions src/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use crate::errors;
use crate::listener::*;
use crate::token::*;

use bytes::buf::BufExt as _;
use bytes::Buf;
use futures::future::TryFutureExt;
use hyper::body::HttpBody;
use hyper::client::*;
use hyper::http::StatusCode;
use hyper::{Body, Request, Response, Uri};
use hyper_tls::HttpsConnector;
use hyper_rustls::HttpsConnector;
use lazy_static::*;
use mime::Mime;
use rvstruct::ValueStruct;
Expand Down Expand Up @@ -59,9 +59,10 @@ impl SlackClientHttpApi {
const SLACK_API_URI_STR: &'static str = "https://slack.com/api";

fn new() -> Self {
let https_connector = HttpsConnector::new();
let https_connector = HttpsConnector::with_native_roots();
let http_client = Client::builder().build::<_, hyper::Body>(https_connector);
Self {
connector: Client::builder().build(https_connector),
connector: http_client,
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/client/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum SlackClientError {
HttpError(SlackClientHttpError),
EndOfStream(SlackClientEndOfStreamError),
SystemError(SlackClientSystemError),
ProtocolError(SlackClientProtocolError),
}

impl SlackClientError {
Expand All @@ -26,6 +27,7 @@ impl Display for SlackClientError {
SlackClientError::ApiError(ref err) => err.fmt(f),
SlackClientError::HttpError(ref err) => err.fmt(f),
SlackClientError::EndOfStream(ref err) => err.fmt(f),
SlackClientError::ProtocolError(ref err) => err.fmt(f),
SlackClientError::SystemError(ref err) => err.fmt(f),
}
}
Expand All @@ -37,6 +39,7 @@ impl Error for SlackClientError {
SlackClientError::ApiError(ref err) => Some(err),
SlackClientError::HttpError(ref err) => Some(err),
SlackClientError::EndOfStream(ref err) => Some(err),
SlackClientError::ProtocolError(ref err) => Some(err),
SlackClientError::SystemError(ref err) => Some(err),
}
}
Expand Down Expand Up @@ -87,6 +90,20 @@ impl Display for SlackClientEndOfStreamError {

impl std::error::Error for SlackClientEndOfStreamError {}

#[derive(Debug)]
pub struct SlackClientProtocolError {
pub json_error: serde_json::Error,
pub http_response_body: String,
}

impl Display for SlackClientProtocolError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "Slack protocol error: {}", self)
}
}

impl std::error::Error for SlackClientProtocolError {}

#[derive(Debug, PartialEq, Clone, Builder)]
pub struct SlackClientSystemError {
message: String,
Expand Down
2 changes: 1 addition & 1 deletion src/client/src/listener/interaction_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl SlackClientEventsListener {

payload.and_then(|payload_value| {
serde_json::from_str::<SlackInteractionEvent>(payload_value)
.map_err(|e| e.into())
.map_err(|e| SlackClientProtocolError{ json_error: e, http_response_body: payload_value.clone() }.into())
})
})
.and_then(|event| async move {
Expand Down
10 changes: 8 additions & 2 deletions src/client/src/listener/push_events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rsb_derive::Builder;

use crate::errors::SlackClientProtocolError;
use crate::listener::signature_verifier::SlackEventSignatureVerifier;
use crate::listener::SlackClientEventsListener;
use crate::{SlackClient, SlackClientHttpApi};
Expand Down Expand Up @@ -62,8 +63,13 @@ impl SlackClientEventsListener {
(&Method::POST, url) if url == cfg.events_path => {
SlackClientHttpApi::decode_signed_response(req, &sign_verifier)
.map_ok(|body| {
serde_json::from_str::<SlackPushEvent>(body.as_str())
.map_err(|e| e.into())
serde_json::from_str::<SlackPushEvent>(body.as_str()).map_err(|e| {
SlackClientProtocolError {
json_error: e,
http_response_body: body.clone(),
}
.into()
})
})
.and_then(|event| async move {
match event {
Expand Down
4 changes: 3 additions & 1 deletion src/client/src/scroller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ where
session: &'a SlackClientSession<'s>,
throttle_duration: Duration,
) -> BoxFuture<'a, ClientResult<Vec<Self::ResponseItemType>>> {
tokio::time::throttle(throttle_duration, self.to_stream(session))
use tokio_stream::StreamExt;
self.to_stream(session)
.throttle(throttle_duration)
.map_ok(|rs| {
rs.scrollable_items()
.cloned()
Expand Down
12 changes: 6 additions & 6 deletions src/examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "slack-morphism-examples"
version = "0.1.0"
version = "0.2.0"
authors = ["Abdulla Abdurakhmanov <[email protected]>"]
edition = "2018"
publish = false

[dependencies]
slack-morphism-models = { path = "../models", version = "0.3" }
slack-morphism = { path = "../client", version = "0.3.1" }
slack-morphism-models = { path = "../models", version = "0.4" }
slack-morphism = { path = "../client", version = "0.4" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = "1.4"
futures = "0.3"
tokio = { version = "0.2", features = ["full"] }
tokio = { version = "1.0", features = ["full"] }
chrono = { version = "0.4", features = ["serde"] }
hyper = "0.13"
hyper = { version ="0.14", features = ["full"] }
log = "0.4"
fern = { version = "0.6", features = ["colored"] }
rsb_derive = "0.2"
rsb_derive = "0.3"
4 changes: 2 additions & 2 deletions src/models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "slack-morphism-models"
version = "0.3.1"
version = "0.4.0"
authors = ["Abdulla Abdurakhmanov <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -20,7 +20,7 @@ path = "src/lib.rs"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = "1.5"
serde_with = "1.6"
rvstruct = "0.2"
rsb_derive = "0.3"
chrono = { version = "0.4", features = ["serde"] }
2 changes: 1 addition & 1 deletion src/models/src/events/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct SlackEventCallback {
pub event: SlackEventCallbackBody,
pub event_id: SlackEventId,
pub event_time: SlackDateTime,
pub event_context: SlackEventContext,
pub event_context: Option<SlackEventContext>,
pub authed_users: Option<Vec<SlackUserId>>,
pub authorizations: Option<Vec<SlackEventAuthorization>>,
}
Expand Down

0 comments on commit b259173

Please sign in to comment.