Yandex Webmaster API Client
Rust client library for the Yandex Webmaster API.
Features
- OAuth authentication with middleware support
- Automatic user ID fetching on client creation
- Type-safe DTOs for all API responses
- Comprehensive error handling
- Full coverage of Yandex Webmaster API endpoints
- Built on
reqwest with middleware support
- Instrumented with tracing for observability
Installation
Add this to your Cargo.toml:
[dependencies]
yandex-webmaster-api = "1.0.0"
Quick Start
use yandex_webmaster_api::{YandexWebmasterClient, AddHostRequest};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = YandexWebmasterClient::new("your-oauth-token".to_string()).await?;
println!("User ID: {}", client.user_id());
let hosts = client.get_hosts().await?;
for host in hosts.hosts {
println!("Host: {}", host.ascii_host_url);
}
let request = AddHostRequest {
host_url: "https://example.com".to_string(),
};
let new_host = client.add_host(&request).await?;
println!("Added host with ID: {}", new_host.host_id);
Ok(())
}
Authentication
To use this library, you need a valid OAuth token from Yandex. You can obtain one by following the Yandex OAuth documentation.
The client automatically:
- Adds the OAuth token to all requests via middleware
- Fetches the user ID on creation
- Validates authentication by calling the
/user endpoint
Examples
Verification Workflow
use yandex_webmaster_api::{YandexWebmasterClient, VerificationType};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = YandexWebmasterClient::new("your-token".to_string()).await?;
let host_id = "your-host-id";
let verification = client.verify_host(host_id, VerificationType::MetaTag).await?;
println!("Verification token: {:?}", verification.verification_uin);
let status = client.get_verification_status(host_id).await?;
println!("Status: {:?}", status.verification_state);
Ok(())
}
Query Analytics
use yandex_webmaster_api::{YandexWebmasterClient, QueryHistoryRequest};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = YandexWebmasterClient::new("your-token".to_string()).await?;
let request = QueryHistoryRequest {
date_from: Some("2024-01-01".to_string()),
date_to: Some("2024-01-31".to_string()),
};
let analytics = client.get_query_analytics("host-id", &request).await?;
for point in analytics.points {
println!("Date: {}, Clicks: {:?}", point.date, point.clicks);
}
Ok(())
}
Recrawl URLs
use yandex_webmaster_api::{YandexWebmasterClient, RecrawlRequest};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = YandexWebmasterClient::new("your-token".to_string()).await?;
let request = RecrawlRequest {
urls: vec![
"https://example.com/page1".to_string(),
"https://example.com/page2".to_string(),
],
};
let response = client.recrawl_urls("host-id", &request).await?;
println!("Task ID: {}", response.task_id);
println!("Quota remaining: {:?}", response.quota_remainder);
Ok(())
}
License
Licensed under either of:
at your option.
TODOs
- Add local end-to-end tests
- Add RSS feeds supports