Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use post request and correct content type #1

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/api_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl racal::reqwest::ApiClient<NoAuthentication> for UnauthenticatedCVR {
&self, req: RequestBuilder,
) -> Result<RequestBuilder, racal::reqwest::ApiError> {
self.http_rate_limiter.until_ready().await;
Ok(req)
Ok(req.header("Content-Type", "application/json"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added to ApiConfiguration::to_headers instead, as some requests may want to overwrite this, and setting it explicitly always just before making the requests would stop that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I've looked into this a bit more and I'd say it should be included in the racal package anyway since the body function inside of Queryable returns an Option with a serde_json::Result and I think it's safe to assume that if something is there then it's json data.
but correct me if anything I've said here is wrong since I'm not fully confident about this

I also found that neos_rs had the same header issue, so fixing it only in this package wouldn't actually fix everything

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eeeh, could provide it as a default there, but other types of data can be posted too, for example I'd expect that image uploads might be a thing that would be neat to support, so it would need to at least be something that can be overridden in the end...

}
}

Expand Down
4 changes: 4 additions & 0 deletions src/query/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ impl Queryable<NoAuthentication, ResponseDataWrapper<UserAuth>> for AuthType {
fn body(&self, _: &NoAuthentication) -> Option<serde_json::Result<Vec<u8>>> {
Some(serde_json::to_vec(self))
}

fn method(&self, _state: &NoAuthentication) -> racal::RequestMethod {
racal::RequestMethod::Post
}
}

/// Adds an user to the blocked users list
Expand Down
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use chilloutvr::{
};
use once_cell::sync::Lazy;

const USER_AGENT: &str = concat!(
pub const USER_AGENT: &str = concat!(
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
" (",
art0007i marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
28 changes: 28 additions & 0 deletions tests/login.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![cfg(feature = "http_client")]

use chilloutvr::{
api_client::{ApiClient, ApiError, ApiConfiguration},
query::{LoginCredentials, AuthType},
};

mod common;

#[tokio::test]
#[ignore]
async fn login() -> Result<(), ApiError> {
let config = ApiConfiguration::new(common::USER_AGENT.to_owned());
let client = chilloutvr::api_client::UnauthenticatedCVR::new(config).expect("Failed to create unauthenticated client.");

let query = AuthType::LoginProfile(LoginCredentials {
email: "email@Address".to_owned(),
password: "pa$$word".to_owned(),
});

let results = client.query(query).await?.data;

dbg!(&results);

assert!(!results.access_key.is_empty());

Ok(())
}
ljoonal marked this conversation as resolved.
Show resolved Hide resolved