numberjuani / ibkr-cp-api-client

Rust Client for Interactive Brokers Client Portal API
MIT License
8 stars 2 forks source link

change AuthStatus #12

Closed era127 closed 1 year ago

era127 commented 1 year ago

The message and server_info fields would not be present if the session is not authenticated and tickle is called. I would propose making them serde default or Option<>.

I also would propose using the same AuthStatus as the return type of pub async fn check_auth_status(&self) instead of Value.

Please let me know if this would break your functionality.

pub struct AuthStatus {
    #[serde(rename = "MAC")]
    pub mac: String,
    pub authenticated: bool,
    pub competing: bool,
    pub connected: bool,
    #[serde(default)]
    pub message: String,
    #[serde(default)]
    pub server_info: ServerInfo,
}
numberjuani commented 1 year ago

Hi @rdavis120 both of those struct implement Default meaning if the keys are not in the json, they will deserialize to empty Strings. They will not make your application crash and you should still be able to catch that you're not authed

era127 commented 1 year ago

Ok. Are you ok with changing the return to AuthStatus?

numberjuani commented 1 year ago

Not sure I understand what you mean

era127 commented 1 year ago

Just to change: pub async fn check_auth_status(&self) -> Result<Value, reqwest::Error> {

To: pub async fn check_auth_status(&self) -> Result<AuthStatus, reqwest::Error> {

numberjuani commented 1 year ago

Sure, I must have forgotten