pub struct ClientBuilder { /* private fields */ }Expand description
Builder for creating a customized Client
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn base_url(self, url: impl Into<String>) -> Self
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();Sourcepub fn api_key(self, key: impl Into<String>) -> Self
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}Sourcepub fn timeout(self, timeout: Duration) -> Self
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}Sourcepub fn client_builder(self, builder: ClientBuilder) -> Self
pub fn client_builder(self, builder: ClientBuilder) -> Self
Configure the underlying reqwest client builder
This allows advanced configuration of the HTTP client.
Sourcepub fn build(self) -> Result<Client, Error>
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§
Auto Trait Implementations§
impl Freeze for ClientBuilder
impl !RefUnwindSafe for ClientBuilder
impl Send for ClientBuilder
impl Sync for ClientBuilder
impl Unpin for ClientBuilder
impl !UnwindSafe for ClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more