forked from mirror/Riven
Compare commits
No commits in common. "feat-middleware" and "v/2.x.x" have entirely different histories.
feat-middl
...
v/2.x.x
|
@ -44,7 +44,6 @@ log = "0.4"
|
||||||
num_enum = "0.5"
|
num_enum = "0.5"
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
reqwest = { version = "0.11", default-features = false, features = [ "gzip", "json" ] }
|
reqwest = { version = "0.11", default-features = false, features = [ "gzip", "json" ] }
|
||||||
reqwest-middleware = { git = "https://git.zynh.me/Zynh0722/reqwest-middleware.git" }
|
|
||||||
scan_fmt = { version = "0.2", default-features = false }
|
scan_fmt = { version = "0.2", default-features = false }
|
||||||
serde = { version = "1.0", features = [ "derive" ] }
|
serde = { version = "1.0", features = [ "derive" ] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use reqwest::header::{HeaderMap, HeaderValue};
|
use reqwest::header::{HeaderMap, HeaderValue};
|
||||||
use reqwest_middleware::ClientBuilder;
|
use reqwest::ClientBuilder;
|
||||||
|
|
||||||
/// Configuration for instantiating RiotApi.
|
/// Configuration for instantiating RiotApi.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -80,7 +80,7 @@ impl RiotApiConfig {
|
||||||
method_rate_usage_factor: Self::DEFAULT_RATE_USAGE_FACTOR,
|
method_rate_usage_factor: Self::DEFAULT_RATE_USAGE_FACTOR,
|
||||||
burst_factor: Self::PRECONFIG_BURST_BURST_FACTOR,
|
burst_factor: Self::PRECONFIG_BURST_BURST_FACTOR,
|
||||||
duration_overhead: Self::PRECONFIG_BURST_DURATION_OVERHEAD,
|
duration_overhead: Self::PRECONFIG_BURST_DURATION_OVERHEAD,
|
||||||
client_builder: Some(ClientBuilder::new(reqwest::ClientBuilder::new().default_headers(default_headers).build().unwrap())),
|
client_builder: Some(ClientBuilder::new().default_headers(default_headers)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use reqwest::{Response, StatusCode};
|
use reqwest::{Error, Response, StatusCode};
|
||||||
use reqwest_middleware::Error;
|
|
||||||
|
|
||||||
/// Result containing RiotApiError on failure.
|
/// Result containing RiotApiError on failure.
|
||||||
pub type Result<T> = std::result::Result<T, RiotApiError>;
|
pub type Result<T> = std::result::Result<T, RiotApiError>;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use reqwest::StatusCode;
|
use reqwest::{RequestBuilder, StatusCode};
|
||||||
use reqwest_middleware::RequestBuilder;
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
use tracing as log;
|
use tracing as log;
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
|
@ -103,7 +102,7 @@ impl RegionalRequester {
|
||||||
retries
|
retries
|
||||||
);
|
);
|
||||||
break Err(RiotApiError::new(
|
break Err(RiotApiError::new(
|
||||||
reqwest_middleware::Error::Reqwest(err),
|
err,
|
||||||
retries,
|
retries,
|
||||||
Some(response),
|
Some(response),
|
||||||
Some(status),
|
Some(status),
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use reqwest::Method;
|
use reqwest::{Client, Method, RequestBuilder};
|
||||||
use reqwest_middleware::{ClientWithMiddleware, RequestBuilder};
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
use tracing as log;
|
use tracing as log;
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ pub struct RiotApi {
|
||||||
/// Configuration settings.
|
/// Configuration settings.
|
||||||
config: RiotApiConfig,
|
config: RiotApiConfig,
|
||||||
/// Client for making requests.
|
/// Client for making requests.
|
||||||
client: ClientWithMiddleware,
|
client: Client,
|
||||||
|
|
||||||
/// Per-region requesters.
|
/// Per-region requesters.
|
||||||
regional_requesters: InsertOnlyCHashMap<&'static str, RegionalRequester>,
|
regional_requesters: InsertOnlyCHashMap<&'static str, RegionalRequester>,
|
||||||
|
@ -60,7 +59,9 @@ impl RiotApi {
|
||||||
.expect("CLIENT_BUILDER IN CONFIG SHOULD NOT BE NONE.");
|
.expect("CLIENT_BUILDER IN CONFIG SHOULD NOT BE NONE.");
|
||||||
Self {
|
Self {
|
||||||
config,
|
config,
|
||||||
client: client_builder.build(),
|
client: client_builder
|
||||||
|
.build()
|
||||||
|
.expect("Failed to create client from builder."),
|
||||||
regional_requesters: InsertOnlyCHashMap::new(),
|
regional_requesters: InsertOnlyCHashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,14 +103,7 @@ impl RiotApi {
|
||||||
let retries = rinfo.retries;
|
let retries = rinfo.retries;
|
||||||
let status = rinfo.response.status();
|
let status = rinfo.response.status();
|
||||||
let value = rinfo.response.json::<T>().await;
|
let value = rinfo.response.json::<T>().await;
|
||||||
value.map_err(|e| {
|
value.map_err(|e| RiotApiError::new(e, retries, None, Some(status)))
|
||||||
RiotApiError::new(
|
|
||||||
reqwest_middleware::Error::Reqwest(e),
|
|
||||||
retries,
|
|
||||||
None,
|
|
||||||
Some(status),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method should generally not be used directly. Consider using endpoint wrappers instead.
|
/// This method should generally not be used directly. Consider using endpoint wrappers instead.
|
||||||
|
@ -138,14 +132,7 @@ impl RiotApi {
|
||||||
let retries = rinfo.retries;
|
let retries = rinfo.retries;
|
||||||
let status = rinfo.response.status();
|
let status = rinfo.response.status();
|
||||||
let value = rinfo.response.json::<Option<T>>().await;
|
let value = rinfo.response.json::<Option<T>>().await;
|
||||||
value.map_err(|e| {
|
value.map_err(|e| RiotApiError::new(e, retries, None, Some(status)))
|
||||||
RiotApiError::new(
|
|
||||||
reqwest_middleware::Error::Reqwest(e),
|
|
||||||
retries,
|
|
||||||
None,
|
|
||||||
Some(status),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method should generally not be used directly. Consider using endpoint wrappers instead.
|
/// This method should generally not be used directly. Consider using endpoint wrappers instead.
|
||||||
|
@ -170,14 +157,11 @@ impl RiotApi {
|
||||||
.await?;
|
.await?;
|
||||||
let retries = rinfo.retries;
|
let retries = rinfo.retries;
|
||||||
let status = rinfo.response.status();
|
let status = rinfo.response.status();
|
||||||
rinfo.response.error_for_status().map(|_| ()).map_err(|e| {
|
rinfo
|
||||||
RiotApiError::new(
|
.response
|
||||||
reqwest_middleware::Error::Reqwest(e),
|
.error_for_status()
|
||||||
retries,
|
.map(|_| ())
|
||||||
None,
|
.map_err(|e| RiotApiError::new(e, retries, None, Some(status)))
|
||||||
Some(status),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method should generally not be used directly. Consider using endpoint wrappers instead.
|
/// This method should generally not be used directly. Consider using endpoint wrappers instead.
|
||||||
|
|
Loading…
Reference in New Issue