-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use builders for api clients - Use builders for api clients - Add request timeout to reqwest client * fix async tests * export ureq * fix default value for reqwest client * fix client in async tests * address code review comments * address comments * add comments * bump version * fix changelog entry * Update src/api/async_telegram_api_impl.rs Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de> * Update src/api/async_telegram_api_impl.rs Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de> * Update src/api/telegram_api_impl.rs Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de> * Update src/api/telegram_api_impl.rs Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de> Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de>
- Loading branch information
Showing
8 changed files
with
154 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "frankenstein" | ||
version = "0.18.0" | ||
version = "0.19.0" | ||
authors = ["Ayrat Badykov <[email protected]>"] | ||
description = "Telegram bot API client for Rust" | ||
edition = "2018" | ||
|
@@ -26,6 +26,10 @@ required-features = ["http-client"] | |
name = "inline_keyboard" | ||
required-features = ["http-client"] | ||
|
||
[[example]] | ||
name = "custom_client" | ||
required-features = ["http-client"] | ||
|
||
[[example]] | ||
name = "async_get_me" | ||
required-features = ["async-http-client"] | ||
|
@@ -38,6 +42,10 @@ required-features = ["async-http-client"] | |
name = "async_file_upload" | ||
required-features = ["async-http-client"] | ||
|
||
[[example]] | ||
name = "async_custom_client" | ||
required-features = ["async-http-client"] | ||
|
||
[[example]] | ||
name = "api_trait_implementation" | ||
required-features = ["telegram-trait"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use frankenstein::reqwest; | ||
use frankenstein::AsyncApi; | ||
use frankenstein::AsyncTelegramApi; | ||
use std::time::Duration; | ||
|
||
static TOKEN: &str = "API_TOKEN"; | ||
static BASE_API_URL: &str = "https://api.telegram.org/bot"; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let api = custom_client(); | ||
|
||
match api.get_me().await { | ||
Ok(response) => { | ||
let user = response.result; | ||
println!( | ||
"Hello, I'm @{}, https://t.me/{}", | ||
user.first_name, | ||
user.username.expect("The bot must have a username.") | ||
); | ||
} | ||
Err(error) => { | ||
eprintln!("Failed to get me: {:?}", error); | ||
} | ||
} | ||
} | ||
|
||
fn custom_client() -> AsyncApi { | ||
let client = reqwest::ClientBuilder::new() | ||
.connect_timeout(Duration::from_secs(100)) | ||
.timeout(Duration::from_secs(100)) | ||
.build() | ||
.unwrap(); | ||
let api_url = format!("{}{}", BASE_API_URL, TOKEN); | ||
|
||
AsyncApi::builder().api_url(api_url).client(client).build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use frankenstein::ureq; | ||
use frankenstein::Api; | ||
use frankenstein::TelegramApi; | ||
use std::time::Duration; | ||
|
||
static TOKEN: &str = "API_TOKEN"; | ||
static BASE_API_URL: &str = "https://api.telegram.org/bot"; | ||
|
||
fn main() { | ||
let api = custom_client(); | ||
|
||
match api.get_me() { | ||
Ok(response) => { | ||
let user = response.result; | ||
println!( | ||
"Hello, I'm @{}, https://t.me/{}", | ||
user.first_name, | ||
user.username.expect("The bot must have a username.") | ||
); | ||
} | ||
Err(error) => { | ||
eprintln!("Failed to get me: {:?}", error); | ||
} | ||
} | ||
} | ||
|
||
fn custom_client() -> Api { | ||
let request_agent = ureq::builder().timeout(Duration::from_secs(100)).build(); | ||
let api_url = format!("{}{}", BASE_API_URL, TOKEN); | ||
|
||
Api::builder() | ||
.api_url(api_url) | ||
.request_agent(request_agent) | ||
.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters