Skip to content

Commit

Permalink
Merge pull request #58 from Nabushika/master
Browse files Browse the repository at this point in the history
Move from hyper -> reqwest
  • Loading branch information
aknarts authored Aug 22, 2024
2 parents 70c9b57 + e1e9608 commit 6192708
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 237 deletions.
8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "webex"
version = "0.9.4"
version = "0.10.0"
authors = [
"Scott Hutton <[email protected]>",
"Milan Stastny <[email protected]>",
Expand All @@ -15,23 +15,17 @@ readme = "README.md"
repository = "https://github.com/wr-org/webex-rust"

[dependencies]
async-std = "1.12"
base64 = "0.22.1"
futures = "0.3.30"
futures-util = "0.3.30"
hyper = { version = "1.4", features = ["client", "http1"] }
hyper-tls = "0.6"
log = "0.4"
serde_json = "1.0"
tokio-native-tls = "0.3"
tungstenite = "0.23.0"
url = "2.5"
lazy_static = "1.5.0"
serde_html_form = "0.2.6"
serde_with = { version = "3.9.0", features = ["macros"] }
thiserror = "1.0.63"
hyper-util = { version = "0.1.7", features = ["client", "http1"] }
http-body-util = "0.1.2"
reqwest = { version = "0.12.5", features = ["json"] }

[dependencies.chrono]
Expand Down
5 changes: 4 additions & 1 deletion examples/auto-reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ async fn main() {
// Dig out the useful bit
if event.activity_type() == webex::ActivityType::Message(webex::MessageActivity::Posted) {
// The event stream doesn't contain the message -- you have to go fetch it
if let Ok(msg) = webex.get::<webex::Message>(&event.try_global_id().unwrap()).await {
if let Ok(msg) = webex
.get::<webex::Message>(&event.try_global_id().unwrap())
.await
{
match &msg.person_email {
// Reply as long as it doesn't appear to be our own message
// In practice, this shouldn't happen since bots can't see messages
Expand Down
19 changes: 17 additions & 2 deletions src/adaptive_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct AdaptiveCard {
pub card_type: String,
/// Schema version that this card requires. If a client is lower than this version, the fallbackText will be rendered.
/// Maximum version is 1.1
#[serde(default = "default_version")] // Workaround for Webex not always providing it :/
pub version: String,
/// The card elements to show in the primary card region.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -39,7 +40,8 @@ pub struct AdaptiveCard {
/// The Adaptive Card schema.
/// <http://adaptivecards.io/schemas/adaptive-card.json>
#[serde(rename = "$schema")]
pub schema: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub schema: Option<String>,
}

impl AdaptiveCard {
Expand All @@ -55,7 +57,7 @@ impl AdaptiveCard {
fallback_text: None,
min_height: None,
lang: None,
schema: "http://adaptivecards.io/schemas/adaptive-card.json".to_string(),
schema: Some("http://adaptivecards.io/schemas/adaptive-card.json".to_string()),
}
}

Expand Down Expand Up @@ -949,12 +951,19 @@ pub enum ContainerStyle {
#[allow(missing_docs)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum Spacing {
#[serde(alias = "default")]
Default,
#[serde(alias = "none")]
None,
#[serde(alias = "small")]
Small,
#[serde(alias = "medium")]
Medium,
#[serde(alias = "large")]
Large,
#[serde(alias = "extraLarge")]
ExtraLarge,
#[serde(alias = "padding")]
Padding,
}

Expand All @@ -969,6 +978,7 @@ pub enum ChoiceInputStyle {
/// Vertical alignment of content
#[allow(missing_docs)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum VerticalContentAlignment {
Top,
Center,
Expand Down Expand Up @@ -1022,6 +1032,7 @@ pub enum FontType {
/// Text Size
#[allow(missing_docs)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum Size {
Default,
Small,
Expand Down Expand Up @@ -1115,3 +1126,7 @@ pub struct Choice {
/// The raw value for the choice. **NOTE:** do not use a , in the value, since a `ChoiceSet` with isMultiSelect set to true returns a comma-delimited string of choice values.
pub value: String,
}

fn default_version() -> String {
"1.1".to_string()
}
21 changes: 8 additions & 13 deletions src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![deny(missing_docs)]
//! Ways to authenticate with the Webex API
use crate::utils::serialize_to_body;
use crate::{AuthorizationType, RequestBody, RestClient};
use hyper::StatusCode;
use crate::{AuthorizationType, RestClient};
use reqwest::StatusCode;
use serde::Deserialize;
use tokio::time::{self, Duration, Instant};

Expand Down Expand Up @@ -69,12 +68,10 @@ impl DeviceAuthenticator {
let params = &[("client_id", self.client_id.as_str()), ("scope", SCOPE)];
let verification_token = self
.client
.api_post::<VerificationToken, _>(
.api_post_form_urlencoded::<VerificationToken>(
"device/authorize",
RequestBody {
media_type: "application/x-www-form-urlencoded; charset=utf-8",
content: serialize_to_body(params)?,
},
params,
None::<()>,
AuthorizationType::None,
)
.await?;
Expand Down Expand Up @@ -104,12 +101,10 @@ impl DeviceAuthenticator {

match self
.client
.api_post::<TokenResponse, _>(
.api_post_form_urlencoded::<TokenResponse>(
"device/token",
RequestBody {
media_type: "application/x-www-form-urlencoded; charset=utf-8",
content: serialize_to_body(&params)?,
},
params,
None::<()>,
AuthorizationType::Basic {
username: &self.client_id,
password: &self.client_secret,
Expand Down
6 changes: 1 addition & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hyper::StatusCode;
use reqwest::StatusCode;

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand All @@ -11,10 +11,6 @@ pub enum Error {
FormEncoding(#[from] serde_html_form::ser::Error),
#[error("UTF8 error: {0}")]
UTF8(#[from] std::str::Utf8Error),
#[error("Hyper error: {0}")]
Hyper(#[from] hyper::Error),
#[error("Hyper util error: {0}")]
HyperUtil(#[from] hyper_util::client::legacy::Error),

#[error("reqwest error: {0}")]
Reqwest(#[from] reqwest::Error),
Expand Down
Loading

0 comments on commit 6192708

Please sign in to comment.