- allow extracting the http client from web api transport - refactor most commands so that they can accept an external transport - update confirmer to use transport's http client - update remove command - update TwoFactorClient so it doesn't need to be mutable - update get_server_time so it requires a transport - update remove_authenticator - update login proceedure to use given transport - update usages of do_login - update setup - update trade - update code command - update qr-login command - make borrowcheck happy - make WebApiTransport Clone and remove Default impl - remove dead code - fix lints closes #177
37 lines
1 KiB
Rust
37 lines
1 KiB
Rust
pub mod webapi;
|
|
|
|
use protobuf::MessageFull;
|
|
pub use webapi::WebApiTransport;
|
|
|
|
use crate::steamapi::{ApiRequest, ApiResponse, BuildableRequest};
|
|
|
|
pub trait Transport {
|
|
fn send_request<Req: BuildableRequest + MessageFull, Res: MessageFull>(
|
|
&self,
|
|
req: ApiRequest<Req>,
|
|
) -> Result<ApiResponse<Res>, TransportError>;
|
|
|
|
fn close(&mut self);
|
|
|
|
fn innner_http_client(&self) -> anyhow::Result<reqwest::blocking::Client> {
|
|
bail!("Transport does not support extracting HTTP client")
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum TransportError {
|
|
#[error("Transport failed to parse response headers")]
|
|
HeaderParseFailure {
|
|
header: String,
|
|
#[source]
|
|
source: anyhow::Error,
|
|
},
|
|
#[error("Transport failed to parse response body")]
|
|
ProtobufError(#[from] protobuf::Error),
|
|
#[error("Unauthorized: Access token is missing or invalid")]
|
|
Unauthorized,
|
|
#[error("NetworkFailure: Transport failed to make request: {0}")]
|
|
NetworkFailure(#[from] reqwest::Error),
|
|
#[error("Unexpected error when transport was making request: {0}")]
|
|
Unknown(#[from] anyhow::Error),
|
|
}
|