Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mzeitlin11 committed Apr 2, 2024
1 parent 985b85a commit 18d653b
Show file tree
Hide file tree
Showing 294 changed files with 45,612 additions and 33,475 deletions.
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[workspace]
members = [
"async-stripe",
"stripe_types",
"stripe_webhook",
"tests",
"generated/*",
"examples/*",
"examples/*", "stripe_client_core", "async-stripe"
]

# Skip "examples/*" when running default commands since that adds a bunch of deps that makes
Expand Down Expand Up @@ -37,6 +36,5 @@ edition = "2021"

[workspace.dependencies]
serde = { version = ">=1.0.79", features = ["derive"] } # we use `serde(other)` which was introduced in 1.0.79
http-types = { version = "2.12.0", default-features = false }
smol_str = { version = "0.2.0", features = ["serde"] }
serde_json = "1.0"
serde_json = "1.0"
107 changes: 18 additions & 89 deletions async-stripe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,106 +1,35 @@
[package]
name = "async-stripe"
version.workspace = true
edition.workspace = true
description.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
documentation.workspace = true
keywords.workspace = true
categories.workspace = true

[package.metadata.docs.rs]
features = ["runtime-tokio-hyper"]
edition.workspace = true

[lib]
name = "stripe"

[features]
default = ["uuid", "stream"]

stream = []

# runtimes
async = ["futures-util"]
blocking = []

runtime-tokio-hyper = [
"tokio",
"hyper-client",
"hyper-tls",
"async",
]
runtime-tokio-hyper-rustls = [
"tokio",
"hyper-client",
"hyper-rustls",
"hyper-rustls-native",
"async",
]
runtime-tokio-hyper-rustls-webpki = [
"tokio",
"hyper-client",
"hyper-rustls-webpki",
"async",
]
runtime-blocking = [
"tokio",
"tokio/rt",
"hyper-client",
"hyper-tls",
"blocking",
]
runtime-blocking-rustls = [
"tokio",
"tokio/rt",
"hyper-client",
"hyper-rustls-native",
"blocking",
]
runtime-blocking-rustls-webpki = [
"tokio",
"tokio/rt",
"hyper-client",
"hyper-rustls-webpki",
"blocking",
]
runtime-async-std-surf = [
"async-std",
"surf",
"async",
]

# we need the compat crate if using hyper
hyper-client = ["hyper", "http-types/hyperium_http"]

hyper-rustls-native = ["hyper-rustls", "hyper-rustls/native-tokio"]
hyper-rustls-webpki = ["hyper-rustls", "hyper-rustls/webpki-tokio"]

[dependencies]
stripe_types = {path = "../stripe_types"}
stripe_shared = {path = "../generated/stripe_shared"}
async-std = {version = "1.8,<1.11", optional = true}

thiserror = "1.0.24"
hyper = { version = "0.14", 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 }
serde_json.workspace = true
hyper = { version = "0.14.28", default-features = false, features = ["http1", "http2", "client"] }
hyper-tls = { version = "0.5.0" }
stripe_types = { path = "../stripe_types" }
stripe_shared = { path = "../generated/stripe_shared" }
serde = "1.0.197"
thiserror = "1.0.58"
serde_qs = "0.12.0"
serde_path_to_error = "0.1.8"
surf = { version = "2.1", optional = true }
tokio = { version = "1.2", optional = true }
uuid = { version = "1.6.1", optional=true, features=["v4"] }
serde_path_to_error = "0.1.16"
serde_json = "1.0.115"
stripe_client_core = { path = "../stripe_client_core" }
http = "1.1.0"
tokio = { version = "1.24.1", features = ["rt", "macros"] }
bytes = "1.5.0"

serde.workspace = true
http-types.workspace = true
smol_str.workspace = true

# stream for lists
futures-util = { version = "0.3.21", optional = true }

[dev-dependencies]
httpmock = "0.6.7"
async-std = { version = "1.10.0", features = ["attributes"] }
tokio = { version = "1.24.1", features = ["rt", "macros"] }
[features]
blocking = []
23 changes: 0 additions & 23 deletions async-stripe/build.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
#![allow(clippy::missing_errors_doc)]
use std::fmt::Display;
use std::{sync::Arc, time::Duration};

use http_types::Request;
use serde::de::DeserializeOwned;
use stripe_client_core::{CustomizedStripeRequest, StripeBlockingClient, StripeClient};

use crate::client::base::tokio::TokioClient;
use crate::client::request_strategy::RequestStrategy;
use crate::error::StripeError;

/// The delay after which the blocking `Client` will assume the request has failed.
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);

pub type Response<T> = Result<T, StripeError>;

#[inline(always)]
pub(crate) fn err<T>(err: crate::StripeError) -> Response<T> {
Err(err)
}

#[derive(Clone)]
pub struct TokioBlockingClient {
inner: TokioClient,
pub struct Client {
inner: crate::Client,
runtime: Arc<tokio::runtime::Runtime>,
}

impl TokioBlockingClient {
impl Client {
/// Creates a new client pointed to `https://api.stripe.com/`
pub fn new() -> TokioBlockingClient {
TokioBlockingClient::from_async(TokioClient::new())
pub fn new(secret_key: impl Display) -> Client {
Client::from_async(crate::Client::new(secret_key))
}

fn from_async(inner: TokioClient) -> TokioBlockingClient {
fn from_async(inner: crate::Client) -> Client {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time() // use separate `io/time` instead of `all` to ensure `tokio/time` is enabled
.build()
.expect("should be able to get a runtime");
TokioBlockingClient { inner, runtime: Arc::new(runtime) }
Client { inner, runtime: Arc::new(runtime) }
}
}

pub fn execute<T: DeserializeOwned + Send + 'static>(
impl StripeBlockingClient for Client {
type Err = StripeError;

fn execute<T: DeserializeOwned>(
&self,
request: Request,
strategy: &RequestStrategy,
) -> Response<T> {
let future = self.inner.execute(request, strategy);
req: CustomizedStripeRequest<T>,
) -> Result<T, Self::Err> {
let future = self.inner.execute(req);
match self.runtime.block_on(async {
// N.B. The `tokio::time::timeout` must be called from within a running async
// context or else it will panic (it registers with the thread-local timer).
Expand All @@ -55,9 +48,3 @@ impl TokioBlockingClient {
}
}
}

impl Default for TokioBlockingClient {
fn default() -> Self {
Self::new()
}
}
Loading

0 comments on commit 18d653b

Please sign in to comment.