Skip to content

Commit

Permalink
Reexport async-stripe-std from root
Browse files Browse the repository at this point in the history
  • Loading branch information
mzeitlin11 committed Jul 7, 2024
1 parent 4efa17a commit c9369a2
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 120 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ members = [
"examples/*",
"async-stripe-client-core",
"async-stripe",
"async-stripe-async-std"
]

# Skip "examples/*" when running default commands since that adds a bunch of deps that makes
# development feedback loop slower.
default-members = ["async-stripe", "async-stripe-types", "async-stripe-webhook", "async-stripe-client-core", "generated/*", "async-stripe-async-std"]
default-members = ["async-stripe", "async-stripe-types", "async-stripe-webhook", "async-stripe-client-core", "generated/*"]
resolver = "2"
# Makes dependency management simpler to allow codegen crate to use whichever dep versions
# it wants without affecting dependency resolution of the user-facing library crates
Expand Down
35 changes: 0 additions & 35 deletions async-stripe-async-std/Cargo.toml

This file was deleted.

34 changes: 0 additions & 34 deletions async-stripe-async-std/src/error.rs

This file was deleted.

15 changes: 0 additions & 15 deletions async-stripe-async-std/src/lib.rs

This file was deleted.

21 changes: 15 additions & 6 deletions async-stripe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,35 @@ edition.workspace = true
name = "stripe"

[dependencies]
hyper = { version = "0.14.28", default-features = false, features = ["http1", "http2", "client", "tcp"] }
hyper = { version = "0.14.28", default-features = false, features = ["http1", "http2", "client", "tcp"], optional = true }
hyper-tls = { version = "0.5", optional = true }
hyper-rustls = { version = "0.24", default-features = false, features = ["http1", "http2", "tls12", "logging"], optional = true }
thiserror = "1.0.58"
miniserde.workspace = true
bytes = "1.6.0"
tokio = { version = "1.24.1", features = ["rt", "macros"] }

# async-std-surf deps
async-std = { version = "1.12.0", optional = true }
surf = { version = "2.1", optional = true }
http-types = { version = "2.12.0", default-features = false, optional = true }

async-stripe-shared = { path = "../generated/async-stripe-shared" }
async-stripe-client-core = { path = "../async-stripe-client-core" }

[features]
default = ["default-tls"]

default-tls = ["dep:hyper-tls"]
native-tls = ["default-tls"]
rustls-tls-webpki-roots = ["__rustls", "hyper-rustls/webpki-tokio"]
rustls-tls-native = ["__rustls", "hyper-rustls/native-tokio"]
default-tls = ["dep:hyper-tls", "__hyper"]
native-tls = ["default-tls", "__hyper"]
rustls-tls-webpki-roots = ["__rustls", "hyper-rustls/webpki-tokio", "__hyper"]
rustls-tls-native = ["__rustls", "hyper-rustls/native-tokio", "__hyper"]
__rustls = ["dep:hyper-rustls"]
__hyper = ["dep:hyper"]

blocking = ["__hyper"]
async-std-surf = ["async-std", "surf", "http-types"]

blocking = []
uuid = ["async-stripe-client-core/uuid"]

[dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use stripe_client_core::{
};
use stripe_shared::AccountId;

use crate::config::ClientConfig;
use crate::{ClientBuilder, StripeError};
use crate::async_std::config::ClientConfig;
use crate::async_std::ClientBuilder;
use crate::StripeError;

/// A client for making Stripe API requests.
#[derive(Clone, Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use http_types::Url;
use stripe_client_core::{RequestStrategy, SharedConfigBuilder};
use stripe_shared::{AccountId, ApiVersion, ApplicationId};

use crate::{Client, StripeError};
use crate::async_std::Client;
use crate::StripeError;

static DEFAULT_USER_AGENT: &str = concat!("Stripe/v1 RustBindings/", env!("CARGO_PKG_VERSION"));
const DEFAULT_API_BASE: &str = "https://api.stripe.com/";
Expand Down
7 changes: 7 additions & 0 deletions async-stripe/src/async_std/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! This module provides Rust bindings to the Stripe HTTP API, using the
//! `async-std` runtime and a `surf` HTTP client.
mod client;
mod config;

pub use client::Client;
pub use config::ClientBuilder;
9 changes: 9 additions & 0 deletions async-stripe/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,23 @@ impl StripeClientErr for StripeError {
}
}

#[cfg(feature = "__hyper")]
impl From<hyper::Error> for StripeError {
fn from(err: hyper::Error) -> StripeError {
StripeError::ClientError(err.to_string())
}
}

#[cfg(feature = "__hyper")]
impl From<hyper::http::Error> for StripeError {
fn from(err: hyper::http::Error) -> StripeError {
StripeError::ClientError(err.to_string())
}
}

#[cfg(feature = "async-std-surf")]
impl From<http_types::Error> for StripeError {
fn from(err: http_types::Error) -> StripeError {
StripeError::ClientError(err.to_string())
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use stripe_client_core::{CustomizedStripeRequest, RequestBuilder, StripeMethod};
use stripe_client_core::{Outcome, RequestStrategy};
use stripe_shared::AccountId;

use crate::client_builder::{ClientBuilder, ClientConfig};
use crate::hyper::client_builder::{ClientBuilder, ClientConfig};
use crate::StripeError;

/// A client for making Stripe API requests.
#[derive(Clone, Debug)]
pub struct Client {
client: hyper::Client<crate::connector::Connector, Body>,
client: hyper::Client<crate::hyper::connector::Connector, Body>,
config: ClientConfig,
}

Expand All @@ -36,7 +36,7 @@ impl Client {
Self {
client: hyper::Client::builder()
.pool_max_idle_per_host(0)
.build(crate::connector::create()),
.build(crate::hyper::connector::create()),
config,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use hyper::http::{HeaderValue, Uri};
use stripe_client_core::{RequestStrategy, SharedConfigBuilder};
use stripe_shared::{AccountId, ApplicationId};

use crate::{Client, StripeError};
use crate::hyper::client::Client;
use crate::StripeError;

static DEFAULT_USER_AGENT: &str = concat!("Stripe/v1 RustBindings/", env!("CARGO_PKG_VERSION"));
const DEFAULT_API_BASE: &str = "https://api.stripe.com/";
Expand Down Expand Up @@ -121,8 +122,8 @@ impl ClientBuilder {
/// # Panics
/// This method panics if called from within an async runtime.
#[cfg(feature = "blocking")]
pub fn build_sync(self) -> Result<crate::blocking::Client, StripeError> {
Ok(crate::blocking::Client::from_async(self.build()?))
pub fn build_sync(self) -> Result<crate::hyper::blocking::Client, StripeError> {
Ok(crate::hyper::blocking::Client::from_async(self.build()?))
}
}

Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions async-stripe/src/hyper/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[cfg(feature = "blocking")]
pub mod blocking;
mod client;
mod client_builder;
mod connector;

pub use client::Client;
pub use client_builder::ClientBuilder;
15 changes: 7 additions & 8 deletions async-stripe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//! To get started, we need to create a [Client]:
//!
//! ```
//! # #[cfg(feature = "__hyper")]
//! let client = stripe::Client::new("sk_test_YOUR_STRIPE_SECRET");
//! ```
//!
Expand Down Expand Up @@ -56,18 +57,16 @@
#![deny(missing_docs, missing_debug_implementations)]
#![forbid(unsafe_code)]

mod client;
mod client_builder;
mod error;

pub use client_builder::ClientBuilder;
#[cfg(feature = "async-std-surf")]
pub mod async_std;

#[cfg(feature = "blocking")]
pub mod blocking;
mod connector;

pub use client::Client;
#[cfg(feature = "__hyper")]
mod hyper;
pub use error::StripeError;
#[cfg(feature = "__hyper")]
pub use hyper::*;
pub use stripe_client_core::{
CustomizedStripeRequest, ListPaginator, PaginationExt, RequestStrategy,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use http_types::convert::{Deserialize, Serialize};
use httpmock::prelude::*;
use stripe_async_std::{Client, ClientBuilder, StripeError};
use stripe::async_std::{Client, ClientBuilder};
use stripe::StripeError;
use stripe_client_core::{
CustomizableStripeRequest, RequestBuilder, RequestStrategy, StripeMethod,
};
Expand Down Expand Up @@ -59,15 +60,15 @@ async fn user_error() {
let client = get_client_for(&server);

let mock = server.mock(|when, then| {
when.method(GET).path("/v1/missing");
then.status(404).body("{
when.method(GET).path("/v1/missing");
then.status(404).body("{
\"error\": {
\"message\": \"Unrecognized request URL (GET: /v1/missing). Please see https://stripe.com/docs or we can help at https://support.stripe.com/.\",
\"type\": \"invalid_request_error\"
}
}
");
});
});

let req = RequestBuilder::new(StripeMethod::Get, "/missing")
.customize::<()>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ async fn user_error() {
let client = get_client_for(&server);

let mock = server.mock(|when, then| {
when.method(GET).path("/v1/missing");
then.status(404).body("{
when.method(GET).path("/v1/missing");
then.status(404).body("{
\"error\": {
\"message\": \"Unrecognized request URL (GET: /v1/missing). Please see https://stripe.com/docs or we can help at https://support.stripe.com/.\",
\"type\": \"invalid_request_error\"
}
}
");
});
});

let res = RequestBuilder::new(StripeMethod::Get, "/missing")
.customize::<TestData>()
Expand Down
4 changes: 4 additions & 0 deletions async-stripe/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[cfg(feature = "async-std-surf")]
mod async_std;
#[cfg(feature = "__hyper")]
mod hyper;
3 changes: 1 addition & 2 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ bytes = "1.6.0"
tokio = { version = "1.24.1", features = ["rt", "macros"] }
async-stripe-types = { path = "../async-stripe-types", features = ["serialize"] }
async-stripe-client-core = { path = "../async-stripe-client-core" }
async-stripe-async-std = { path = "../async-stripe-async-std" }
async-stripe-connect = { path = "../generated/async-stripe-connect", features = ["account", "transfer_reversal", "serialize", "deserialize"] }
async-stripe-billing = { path = "../generated/async-stripe-billing", features = ["invoice", "plan", "subscription", "subscription_item", "usage_record", "serialize"] }
async-stripe-core = { path = "../generated/async-stripe-core", features = ["customer", "charge", "token", "serialize"] }
Expand All @@ -30,7 +29,7 @@ async-stripe-fraud = { path = "../generated/async-stripe-fraud", features = ["se
async-stripe-issuing = { path = "../generated/async-stripe-issuing", features = ["serialize"] }
async-stripe-misc = { path = "../generated/async-stripe-misc", features = ["serialize"] }

async-stripe = { path = "../async-stripe", default-features = false, features = ["blocking"] }
async-stripe = { path = "../async-stripe", default-features = false, features = ["blocking", "async-std-surf"] }

# Copied from async-stripe/Cargo.toml features so that we can run with all those features too
[features]
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/it/async_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod pagination;
#[derive(Clone)]
pub enum StripeClient {
Hyper(stripe::Client),
AsyncStd(Box<stripe_async_std::Client>),
AsyncStd(Box<stripe::async_std::Client>),
}

#[derive(Debug)]
Expand Down Expand Up @@ -56,7 +56,7 @@ impl StripeClient {

fn async_std() -> Self {
Self::AsyncStd(Box::new(
stripe_async_std::ClientBuilder::new(SECRET).url(STRIPE_MOCK_LINK).build().unwrap(),
stripe::async_std::ClientBuilder::new(SECRET).url(STRIPE_MOCK_LINK).build().unwrap(),
))
}
}
Expand Down

0 comments on commit c9369a2

Please sign in to comment.