pub struct RibbitClient { /* private fields */ }
Expand description
Ribbit TCP client for querying Blizzard version services
The client supports multiple regions and both V1 (MIME) and V2 (raw PSV) protocols. It also supports automatic retries with exponential backoff for transient network errors.
§Example
use ribbit_client::{RibbitClient, Region, ProtocolVersion, Endpoint};
// Create a client for EU region with V2 protocol
let client = RibbitClient::new(Region::EU)
.with_protocol_version(ProtocolVersion::V2)
.with_max_retries(3);
// Request version information
let endpoint = Endpoint::ProductVersions("wow".to_string());
let response = client.request(&endpoint).await?;
Implementations§
Source§impl RibbitClient
impl RibbitClient
Sourcepub fn with_protocol_version(self, version: ProtocolVersion) -> Self
pub fn with_protocol_version(self, version: ProtocolVersion) -> Self
Set the protocol version to use
Sourcepub fn with_max_retries(self, max_retries: u32) -> Self
pub fn with_max_retries(self, max_retries: u32) -> Self
Set the maximum number of retries for failed requests
Default is 0 (no retries) to maintain backward compatibility. Only network and connection errors are retried, not parsing errors.
Sourcepub fn with_initial_backoff_ms(self, initial_backoff_ms: u64) -> Self
pub fn with_initial_backoff_ms(self, initial_backoff_ms: u64) -> Self
Set the initial backoff duration in milliseconds
Default is 100ms. This is the base delay before the first retry.
Sourcepub fn with_max_backoff_ms(self, max_backoff_ms: u64) -> Self
pub fn with_max_backoff_ms(self, max_backoff_ms: u64) -> Self
Set the maximum backoff duration in milliseconds
Default is 10,000ms (10 seconds). Backoff will not exceed this value.
Sourcepub fn with_backoff_multiplier(self, backoff_multiplier: f64) -> Self
pub fn with_backoff_multiplier(self, backoff_multiplier: f64) -> Self
Set the backoff multiplier
Default is 2.0. The backoff duration is multiplied by this value after each retry.
Sourcepub fn with_jitter_factor(self, jitter_factor: f64) -> Self
pub fn with_jitter_factor(self, jitter_factor: f64) -> Self
Set the jitter factor (0.0 to 1.0)
Default is 0.1 (10% jitter). Adds randomness to prevent thundering herd.
Sourcepub fn with_dns_cache_ttl(self, ttl: Duration) -> Self
pub fn with_dns_cache_ttl(self, ttl: Duration) -> Self
Set the DNS cache TTL
Default is 300 seconds (5 minutes).
Sourcepub fn set_region(&mut self, region: Region)
pub fn set_region(&mut self, region: Region)
Set the region
Sourcepub fn protocol_version(&self) -> ProtocolVersion
pub fn protocol_version(&self) -> ProtocolVersion
Get the current protocol version
Sourcepub fn set_protocol_version(&mut self, version: ProtocolVersion)
pub fn set_protocol_version(&mut self, version: ProtocolVersion)
Set the protocol version
Sourcepub async fn request_raw(&self, endpoint: &Endpoint) -> Result<Vec<u8>>
pub async fn request_raw(&self, endpoint: &Endpoint) -> Result<Vec<u8>>
Send a request to the Ribbit service and get the raw response
This method supports automatic retries with exponential backoff for transient network errors. Parsing errors are not retried.
§Example
let client = RibbitClient::new(Region::US)
.with_max_retries(3);
let raw_data = client.request_raw(&Endpoint::Summary).await?;
println!("Received {} bytes", raw_data.len());
§Errors
Returns an error if:
- The connection to the Ribbit server fails after all retries
- Sending the request fails
- Receiving the response fails
- The response is invalid or incomplete
Sourcepub async fn request(&self, endpoint: &Endpoint) -> Result<Response>
pub async fn request(&self, endpoint: &Endpoint) -> Result<Response>
Send a request to the Ribbit service and parse the response
§Errors
Returns an error if:
- The raw request fails (see
request_raw
) - Parsing the response fails
- V1 responses fail checksum validation
- V1 responses have invalid MIME structure
Sourcepub async fn request_typed<T: TypedResponse>(
&self,
endpoint: &Endpoint,
) -> Result<T>
pub async fn request_typed<T: TypedResponse>( &self, endpoint: &Endpoint, ) -> Result<T>
Request with automatic type parsing
This method automatically parses the response into the appropriate typed structure based on the type parameter.
§Example
let client = RibbitClient::new(Region::US);
let versions: ProductVersionsResponse = client
.request_typed(&Endpoint::ProductVersions("wow".to_string()))
.await?;
for entry in &versions.entries {
println!("{}: {} (build {})", entry.region, entry.versions_name, entry.build_id);
}
§Errors
Returns an error if:
- The request fails
- The response cannot be parsed as BPSV
- The BPSV data doesn’t match the expected schema
Sourcepub async fn get_product_versions(
&self,
product: &str,
) -> Result<ProductVersionsResponse>
pub async fn get_product_versions( &self, product: &str, ) -> Result<ProductVersionsResponse>
Request product versions with typed response
Convenience method for requesting product version information.
§Example
let client = RibbitClient::new(Region::US);
let versions = client.get_product_versions("wow").await?;
if let Some(us_version) = versions.get_region("us") {
println!("US version: {}", us_version.versions_name);
}
§Errors
Returns an error if:
- The request fails
- The response cannot be parsed as BPSV
- The BPSV data doesn’t match the expected schema
Sourcepub async fn get_product_cdns(
&self,
product: &str,
) -> Result<ProductCdnsResponse>
pub async fn get_product_cdns( &self, product: &str, ) -> Result<ProductCdnsResponse>
Request product CDNs with typed response
Convenience method for requesting CDN server information.
§Errors
Returns an error if:
- The request fails
- The response cannot be parsed as BPSV
- The BPSV data doesn’t match the expected schema
Sourcepub async fn get_product_bgdl(
&self,
product: &str,
) -> Result<ProductBgdlResponse>
pub async fn get_product_bgdl( &self, product: &str, ) -> Result<ProductBgdlResponse>
Request product background download config with typed response
Convenience method for requesting background download configuration.
§Errors
Returns an error if:
- The request fails
- The response cannot be parsed as BPSV
- The BPSV data doesn’t match the expected schema
Sourcepub async fn get_summary(&self) -> Result<SummaryResponse>
pub async fn get_summary(&self) -> Result<SummaryResponse>
Request summary of all products with typed response
Convenience method for requesting the summary of all available products.
§Example
let client = RibbitClient::new(Region::US);
let summary = client.get_summary().await?;
for product in &summary.products {
println!("{}: seqn {}", product.product, product.seqn);
}
§Errors
Returns an error if:
- The request fails
- The response cannot be parsed as BPSV
- The BPSV data doesn’t match the expected schema
Trait Implementations§
Source§impl Clone for RibbitClient
impl Clone for RibbitClient
Source§fn clone(&self) -> RibbitClient
fn clone(&self) -> RibbitClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more