ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder { /* private fields */ }
Expand description

Builder for creating a customized Client

Implementations§

Source§

impl ClientBuilder

Source

pub fn new() -> Self

Create a new builder with default settings

Source

pub fn base_url(self, url: impl Into<String>) -> Self

Set a custom base URL for the API

§Examples
use faceit::HttpClient;

let client = HttpClient::builder()
    .base_url("https://custom-api.example.com")
    .build()
    .unwrap();
Source

pub fn api_key(self, key: impl Into<String>) -> Self

Set the API key or access token

For the Data API, you can use either:

  • An API key (obtained from the FACEIT Developer Portal)
  • An access token (obtained via OAuth2)

Both are passed in the Authorization: Bearer {token} header.

§Examples
use faceit::HttpClient;

// Using an API key
let client = HttpClient::builder()
    .api_key("your-api-key")
    .build()
    .unwrap();

// Using an access token
let client = HttpClient::builder()
    .api_key("your-access-token")
    .build()
    .unwrap();
Examples found in repository?
examples/basic_usage.rs (line 140)
4async fn main() -> Result<(), faceit::error::Error> {
5    // Create a client (without authentication)
6    let client = HttpClient::new();
7
8    // Or create a client with API key or access token:
9    // let client = Client::builder()
10    //     .api_key("your-api-key-or-access-token")
11    //     .build()?;
12
13    // Example 1: Get player by ID
14    println!("Fetching player by ID...");
15    match client.get_player("player-id-here").await {
16        Ok(player) => {
17            println!("Player: {}", player.nickname);
18            if let Some(country) = player.country {
19                println!("Country: {}", country);
20            }
21        }
22        Err(e) => eprintln!("Error fetching player: {}", e),
23    }
24
25    // Example 2: Get player from lookup by nickname
26    println!("\nFetching player from lookup...");
27    match client
28        .get_player_from_lookup(Some("player_nickname"), Some("cs2"), None)
29        .await
30    {
31        Ok(player) => {
32            println!("Player: {}", player.nickname);
33        }
34        Err(e) => eprintln!("Error fetching player: {}", e),
35    }
36
37    // Example 3: Get player stats
38    println!("\nFetching player stats...");
39    match client.get_player_stats("player-id-here", "cs2").await {
40        Ok(stats) => {
41            println!("Player ID: {}", stats.player_id);
42            println!("Game ID: {}", stats.game_id);
43        }
44        Err(e) => eprintln!("Error fetching stats: {}", e),
45    }
46
47    // Example 4: Get player match history
48    println!("\nFetching player match history...");
49    match client
50        .get_player_history("player-id-here", "cs2", None, None, Some(0), Some(20))
51        .await
52    {
53        Ok(history) => {
54            println!("Found {} matches", history.items.len());
55            if let Some(first_match) = history.items.first() {
56                println!("Most recent match: {}", first_match.match_id);
57            }
58        }
59        Err(e) => eprintln!("Error fetching history: {}", e),
60    }
61
62    // Example 5: Get match details
63    println!("\nFetching match details...");
64    match client.get_match("match-id-here").await {
65        Ok(match_details) => {
66            println!("Match ID: {}", match_details.match_id);
67            println!("Game: {}", match_details.game);
68            println!("Status: {}", match_details.status);
69        }
70        Err(e) => eprintln!("Error fetching match: {}", e),
71    }
72
73    // Example 6: Get match stats
74    println!("\nFetching match stats...");
75    match client.get_match_stats("match-id-here").await {
76        Ok(stats) => {
77            println!("Rounds: {}", stats.rounds.len());
78        }
79        Err(e) => eprintln!("Error fetching match stats: {}", e),
80    }
81
82    // Example 7: Search for players
83    println!("\nSearching for players...");
84    match client
85        .search_players("player_name", Some("cs2"), None, Some(0), Some(20))
86        .await
87    {
88        Ok(results) => {
89            println!("Found {} players", results.items.len());
90            for player in results.items.iter().take(5) {
91                println!("  - {} ({})", player.nickname, player.player_id);
92            }
93        }
94        Err(e) => eprintln!("Error searching players: {}", e),
95    }
96
97    // Example 8: Get all games
98    println!("\nFetching all games...");
99    match client.get_all_games(Some(0), Some(20)).await {
100        Ok(games) => {
101            println!("Found {} games", games.items.len());
102            for game in games.items.iter().take(5) {
103                println!("  - {} ({})", game.long_label, game.game_id);
104            }
105        }
106        Err(e) => eprintln!("Error fetching games: {}", e),
107    }
108
109    // Example 9: Get hub details
110    println!("\nFetching hub details...");
111    match client.get_hub("hub-id-here", None).await {
112        Ok(hub) => {
113            println!("Hub: {}", hub.name);
114            println!("Game: {}", hub.game_id);
115        }
116        Err(e) => eprintln!("Error fetching hub: {}", e),
117    }
118
119    // Example 10: Get global ranking
120    println!("\nFetching global ranking...");
121    match client
122        .get_global_ranking("cs2", "EU", None, Some(0), Some(20))
123        .await
124    {
125        Ok(ranking) => {
126            println!("Found {} players in ranking", ranking.items.len());
127            for entry in ranking.items.iter().take(5) {
128                println!(
129                    "  {}: {} - ELO: {}",
130                    entry.position, entry.nickname, entry.faceit_elo
131                );
132            }
133        }
134        Err(e) => eprintln!("Error fetching ranking: {}", e),
135    }
136
137    // Example 11: Using the builder pattern with authentication
138    println!("\nCreating client with builder...");
139    let _custom_client = HttpClient::builder()
140        .api_key("your-api-key-or-access-token-here")
141        .timeout(std::time::Duration::from_secs(60))
142        .build()?;
143
144    println!("Client created with custom configuration");
145
146    Ok(())
147}
Source

pub fn timeout(self, timeout: Duration) -> Self

Set the request timeout

§Examples
use faceit::HttpClient;
use std::time::Duration;

let client = HttpClient::builder()
    .timeout(Duration::from_secs(60))
    .build()
    .unwrap();
Examples found in repository?
examples/basic_usage.rs (line 141)
4async fn main() -> Result<(), faceit::error::Error> {
5    // Create a client (without authentication)
6    let client = HttpClient::new();
7
8    // Or create a client with API key or access token:
9    // let client = Client::builder()
10    //     .api_key("your-api-key-or-access-token")
11    //     .build()?;
12
13    // Example 1: Get player by ID
14    println!("Fetching player by ID...");
15    match client.get_player("player-id-here").await {
16        Ok(player) => {
17            println!("Player: {}", player.nickname);
18            if let Some(country) = player.country {
19                println!("Country: {}", country);
20            }
21        }
22        Err(e) => eprintln!("Error fetching player: {}", e),
23    }
24
25    // Example 2: Get player from lookup by nickname
26    println!("\nFetching player from lookup...");
27    match client
28        .get_player_from_lookup(Some("player_nickname"), Some("cs2"), None)
29        .await
30    {
31        Ok(player) => {
32            println!("Player: {}", player.nickname);
33        }
34        Err(e) => eprintln!("Error fetching player: {}", e),
35    }
36
37    // Example 3: Get player stats
38    println!("\nFetching player stats...");
39    match client.get_player_stats("player-id-here", "cs2").await {
40        Ok(stats) => {
41            println!("Player ID: {}", stats.player_id);
42            println!("Game ID: {}", stats.game_id);
43        }
44        Err(e) => eprintln!("Error fetching stats: {}", e),
45    }
46
47    // Example 4: Get player match history
48    println!("\nFetching player match history...");
49    match client
50        .get_player_history("player-id-here", "cs2", None, None, Some(0), Some(20))
51        .await
52    {
53        Ok(history) => {
54            println!("Found {} matches", history.items.len());
55            if let Some(first_match) = history.items.first() {
56                println!("Most recent match: {}", first_match.match_id);
57            }
58        }
59        Err(e) => eprintln!("Error fetching history: {}", e),
60    }
61
62    // Example 5: Get match details
63    println!("\nFetching match details...");
64    match client.get_match("match-id-here").await {
65        Ok(match_details) => {
66            println!("Match ID: {}", match_details.match_id);
67            println!("Game: {}", match_details.game);
68            println!("Status: {}", match_details.status);
69        }
70        Err(e) => eprintln!("Error fetching match: {}", e),
71    }
72
73    // Example 6: Get match stats
74    println!("\nFetching match stats...");
75    match client.get_match_stats("match-id-here").await {
76        Ok(stats) => {
77            println!("Rounds: {}", stats.rounds.len());
78        }
79        Err(e) => eprintln!("Error fetching match stats: {}", e),
80    }
81
82    // Example 7: Search for players
83    println!("\nSearching for players...");
84    match client
85        .search_players("player_name", Some("cs2"), None, Some(0), Some(20))
86        .await
87    {
88        Ok(results) => {
89            println!("Found {} players", results.items.len());
90            for player in results.items.iter().take(5) {
91                println!("  - {} ({})", player.nickname, player.player_id);
92            }
93        }
94        Err(e) => eprintln!("Error searching players: {}", e),
95    }
96
97    // Example 8: Get all games
98    println!("\nFetching all games...");
99    match client.get_all_games(Some(0), Some(20)).await {
100        Ok(games) => {
101            println!("Found {} games", games.items.len());
102            for game in games.items.iter().take(5) {
103                println!("  - {} ({})", game.long_label, game.game_id);
104            }
105        }
106        Err(e) => eprintln!("Error fetching games: {}", e),
107    }
108
109    // Example 9: Get hub details
110    println!("\nFetching hub details...");
111    match client.get_hub("hub-id-here", None).await {
112        Ok(hub) => {
113            println!("Hub: {}", hub.name);
114            println!("Game: {}", hub.game_id);
115        }
116        Err(e) => eprintln!("Error fetching hub: {}", e),
117    }
118
119    // Example 10: Get global ranking
120    println!("\nFetching global ranking...");
121    match client
122        .get_global_ranking("cs2", "EU", None, Some(0), Some(20))
123        .await
124    {
125        Ok(ranking) => {
126            println!("Found {} players in ranking", ranking.items.len());
127            for entry in ranking.items.iter().take(5) {
128                println!(
129                    "  {}: {} - ELO: {}",
130                    entry.position, entry.nickname, entry.faceit_elo
131                );
132            }
133        }
134        Err(e) => eprintln!("Error fetching ranking: {}", e),
135    }
136
137    // Example 11: Using the builder pattern with authentication
138    println!("\nCreating client with builder...");
139    let _custom_client = HttpClient::builder()
140        .api_key("your-api-key-or-access-token-here")
141        .timeout(std::time::Duration::from_secs(60))
142        .build()?;
143
144    println!("Client created with custom configuration");
145
146    Ok(())
147}
Source

pub fn client_builder(self, builder: ClientBuilder) -> Self

Configure the underlying reqwest client builder

This allows advanced configuration of the HTTP client.

Source

pub fn build(self) -> Result<Client, Error>

Build the client

§Examples
use faceit::HttpClient;

let client = HttpClient::builder()
    .api_key("your-api-key-or-access-token")
    .build()?;
Examples found in repository?
examples/basic_usage.rs (line 142)
4async fn main() -> Result<(), faceit::error::Error> {
5    // Create a client (without authentication)
6    let client = HttpClient::new();
7
8    // Or create a client with API key or access token:
9    // let client = Client::builder()
10    //     .api_key("your-api-key-or-access-token")
11    //     .build()?;
12
13    // Example 1: Get player by ID
14    println!("Fetching player by ID...");
15    match client.get_player("player-id-here").await {
16        Ok(player) => {
17            println!("Player: {}", player.nickname);
18            if let Some(country) = player.country {
19                println!("Country: {}", country);
20            }
21        }
22        Err(e) => eprintln!("Error fetching player: {}", e),
23    }
24
25    // Example 2: Get player from lookup by nickname
26    println!("\nFetching player from lookup...");
27    match client
28        .get_player_from_lookup(Some("player_nickname"), Some("cs2"), None)
29        .await
30    {
31        Ok(player) => {
32            println!("Player: {}", player.nickname);
33        }
34        Err(e) => eprintln!("Error fetching player: {}", e),
35    }
36
37    // Example 3: Get player stats
38    println!("\nFetching player stats...");
39    match client.get_player_stats("player-id-here", "cs2").await {
40        Ok(stats) => {
41            println!("Player ID: {}", stats.player_id);
42            println!("Game ID: {}", stats.game_id);
43        }
44        Err(e) => eprintln!("Error fetching stats: {}", e),
45    }
46
47    // Example 4: Get player match history
48    println!("\nFetching player match history...");
49    match client
50        .get_player_history("player-id-here", "cs2", None, None, Some(0), Some(20))
51        .await
52    {
53        Ok(history) => {
54            println!("Found {} matches", history.items.len());
55            if let Some(first_match) = history.items.first() {
56                println!("Most recent match: {}", first_match.match_id);
57            }
58        }
59        Err(e) => eprintln!("Error fetching history: {}", e),
60    }
61
62    // Example 5: Get match details
63    println!("\nFetching match details...");
64    match client.get_match("match-id-here").await {
65        Ok(match_details) => {
66            println!("Match ID: {}", match_details.match_id);
67            println!("Game: {}", match_details.game);
68            println!("Status: {}", match_details.status);
69        }
70        Err(e) => eprintln!("Error fetching match: {}", e),
71    }
72
73    // Example 6: Get match stats
74    println!("\nFetching match stats...");
75    match client.get_match_stats("match-id-here").await {
76        Ok(stats) => {
77            println!("Rounds: {}", stats.rounds.len());
78        }
79        Err(e) => eprintln!("Error fetching match stats: {}", e),
80    }
81
82    // Example 7: Search for players
83    println!("\nSearching for players...");
84    match client
85        .search_players("player_name", Some("cs2"), None, Some(0), Some(20))
86        .await
87    {
88        Ok(results) => {
89            println!("Found {} players", results.items.len());
90            for player in results.items.iter().take(5) {
91                println!("  - {} ({})", player.nickname, player.player_id);
92            }
93        }
94        Err(e) => eprintln!("Error searching players: {}", e),
95    }
96
97    // Example 8: Get all games
98    println!("\nFetching all games...");
99    match client.get_all_games(Some(0), Some(20)).await {
100        Ok(games) => {
101            println!("Found {} games", games.items.len());
102            for game in games.items.iter().take(5) {
103                println!("  - {} ({})", game.long_label, game.game_id);
104            }
105        }
106        Err(e) => eprintln!("Error fetching games: {}", e),
107    }
108
109    // Example 9: Get hub details
110    println!("\nFetching hub details...");
111    match client.get_hub("hub-id-here", None).await {
112        Ok(hub) => {
113            println!("Hub: {}", hub.name);
114            println!("Game: {}", hub.game_id);
115        }
116        Err(e) => eprintln!("Error fetching hub: {}", e),
117    }
118
119    // Example 10: Get global ranking
120    println!("\nFetching global ranking...");
121    match client
122        .get_global_ranking("cs2", "EU", None, Some(0), Some(20))
123        .await
124    {
125        Ok(ranking) => {
126            println!("Found {} players in ranking", ranking.items.len());
127            for entry in ranking.items.iter().take(5) {
128                println!(
129                    "  {}: {} - ELO: {}",
130                    entry.position, entry.nickname, entry.faceit_elo
131                );
132            }
133        }
134        Err(e) => eprintln!("Error fetching ranking: {}", e),
135    }
136
137    // Example 11: Using the builder pattern with authentication
138    println!("\nCreating client with builder...");
139    let _custom_client = HttpClient::builder()
140        .api_key("your-api-key-or-access-token-here")
141        .timeout(std::time::Duration::from_secs(60))
142        .build()?;
143
144    println!("Client created with custom configuration");
145
146    Ok(())
147}

Trait Implementations§

Source§

impl Default for ClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more