Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ serde_with = { version = "^3.8", default-features = false, features = ["base64",
serde_json = "^1.0"
serde_repr = "^0.1"
url = "^2.5"
reqwest = { version = "^0.12", default-features = false, features = ["json", "cookies", "multipart"] }
reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] }
reqwest-middleware = { version = "^0.4", features = ["json", "multipart"] }

[features]
default = ["native-tls"]
default = ["reqwest/cookies"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]

Expand Down
3 changes: 2 additions & 1 deletion examples/cookies_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ async fn main() {
config.client = reqwest::Client::builder()
.cookie_provider(jar)
.build()
.unwrap();
.unwrap()
.into();

let user = ::vrchatapi::apis::authentication_api::get_current_user(&config)
.await
Expand Down
3 changes: 2 additions & 1 deletion examples/cookies_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ async fn main() {
config.client = reqwest::Client::builder()
.cookie_provider(cookie_store.clone())
.build()
.unwrap();
.unwrap()
.into();

match ::vrchatapi::apis::authentication_api::get_current_user(&config)
.await
Expand Down
4 changes: 2 additions & 2 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rm src/apis src/models docs -rf

./node_modules/\@openapitools/openapi-generator-cli/main.js generate \
-g rust \
--additional-properties=packageName=vrchatapi,supportAsync=true,avoidBoxedModels=true \
--additional-properties=packageName=vrchatapi,supportAsync=true,avoidBoxedModels=true,library=reqwest,reqwestDefaultFeatures=reqwest/cookies,supportMiddleware=true \
--git-user-id=vrchatapi \
--git-repo-id=vrchatapi-rust \
-o . \
Expand All @@ -34,7 +34,7 @@ find src -type f -exec sed -i '/^\s*\/\/\/\s*$/d' {} \;

# Cookie storage
sed -i 's/Client::new()/Client::builder().cookie_store(true).build().unwrap()/g' src/apis/configuration.rs
sed -i 's/, features = \["json", "multipart"\]/, features = \["json", "cookies", "multipart"\]/g' Cargo.toml
#sed -i 's/, features = \["json", "multipart"\]/, features = \["json", "cookies", "multipart"\]/g' Cargo.toml

#Fix example
printf "\n[dev-dependencies]\ntokio = { version = '1', features = ['macros', 'rt-multi-thread'] }" >> Cargo.toml
Expand Down
13 changes: 8 additions & 5 deletions src/apis/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
pub struct Configuration {
pub base_path: String,
pub user_agent: Option<String>,
pub client: reqwest::Client,
pub client: reqwest_middleware::ClientWithMiddleware,
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub bearer_access_token: Option<String>,
Expand All @@ -36,10 +36,13 @@ impl Default for Configuration {
Configuration {
base_path: "https://api.vrchat.cloud/api/1".to_owned(),
user_agent: Some("vrchatapi-rust".to_owned()),
client: reqwest::Client::builder()
.cookie_store(true)
.build()
.unwrap(),
client: reqwest_middleware::ClientBuilder::new(
reqwest::Client::builder()
.cookie_store(true)
.build()
.unwrap(),
)
.build(),
basic_auth: None,
oauth_access_token: None,
bearer_access_token: None,
Expand Down
9 changes: 9 additions & 0 deletions src/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct ResponseContent<T> {
#[derive(Debug)]
pub enum Error<T> {
Reqwest(reqwest::Error),
ReqwestMiddleware(reqwest_middleware::Error),
Serde(serde_json::Error),
Io(std::io::Error),
ResponseError(ResponseContent<T>),
Expand All @@ -20,6 +21,7 @@ impl<T> fmt::Display for Error<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (module, e) = match self {
Error::Reqwest(e) => ("reqwest", e.to_string()),
Error::ReqwestMiddleware(e) => ("reqwest-middleware", e.to_string()),
Error::Serde(e) => ("serde", e.to_string()),
Error::Io(e) => ("IO", e.to_string()),
Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
Expand All @@ -32,6 +34,7 @@ impl<T: fmt::Debug> error::Error for Error<T> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
Some(match self {
Error::Reqwest(e) => e,
Error::ReqwestMiddleware(e) => e,
Error::Serde(e) => e,
Error::Io(e) => e,
Error::ResponseError(_) => return None,
Expand All @@ -45,6 +48,12 @@ impl<T> From<reqwest::Error> for Error<T> {
}
}

impl<T> From<reqwest_middleware::Error> for Error<T> {
fn from(e: reqwest_middleware::Error) -> Self {
Error::ReqwestMiddleware(e)
}
}

impl<T> From<serde_json::Error> for Error<T> {
fn from(e: serde_json::Error) -> Self {
Error::Serde(e)
Expand Down