pub struct PexelsClient { /* private fields */ }Expand description
Pexels API 的主要客户端
此客户端提供与 Pexels API 所有端点交互的方法, 并处理认证、请求构建和响应解析。
Implementations§
Source§impl PexelsClient
impl PexelsClient
Sourcepub fn with_config<S: Into<String>>(
api_key: S,
timeout: u64,
max_idle_connections: usize,
) -> Self
pub fn with_config<S: Into<String>>( api_key: S, timeout: u64, max_idle_connections: usize, ) -> Self
Sourcepub fn with_base_url<S: Into<String>>(self, base_url: S) -> Self
pub fn with_base_url<S: Into<String>>(self, base_url: S) -> Self
Sourcepub async fn search_photos(
&self,
query: &str,
params: &SearchParams,
) -> Result<PhotosPage, PexelsError>
pub async fn search_photos( &self, query: &str, params: &SearchParams, ) -> Result<PhotosPage, PexelsError>
搜索与指定查询和参数匹配的照片
§参数
query- 搜索查询params- 其他搜索参数(分页、过滤器等)
§返回
包含照片搜索响应或错误的结果
§示例
use pexels_sdk::{PexelsClient, SearchParams, Size};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = PexelsClient::new("your_api_key");
let params = SearchParams::new()
.page(1)
.per_page(15)
.size(Size::Large);
match client.search_photos("nature", ¶ms).await {
Ok(photos) => println!("Found {} photos", photos.total_results),
Err(e) => println!("搜索失败: {}", e),
}
Ok(())
}Sourcepub async fn curated_photos(
&self,
params: &PaginationParams,
) -> Result<PhotosPage, PexelsError>
pub async fn curated_photos( &self, params: &PaginationParams, ) -> Result<PhotosPage, PexelsError>
Sourcepub async fn get_photo(&self, id: u64) -> Result<Photo, PexelsError>
pub async fn get_photo(&self, id: u64) -> Result<Photo, PexelsError>
Sourcepub async fn search_videos(
&self,
query: &str,
params: &VideoSearchParams,
) -> Result<VideosPage, PexelsError>
pub async fn search_videos( &self, query: &str, params: &VideoSearchParams, ) -> Result<VideosPage, PexelsError>
Sourcepub async fn popular_videos(
&self,
params: &PaginationParams,
) -> Result<VideosPage, PexelsError>
pub async fn popular_videos( &self, params: &PaginationParams, ) -> Result<VideosPage, PexelsError>
Sourcepub async fn get_video(&self, id: u64) -> Result<Video, PexelsError>
pub async fn get_video(&self, id: u64) -> Result<Video, PexelsError>
Sourcepub async fn get_collections(
&self,
params: &PaginationParams,
) -> Result<CollectionsPage, PexelsError>
pub async fn get_collections( &self, params: &PaginationParams, ) -> Result<CollectionsPage, PexelsError>
Sourcepub async fn get_collection_media(
&self,
id: &str,
params: &PaginationParams,
) -> Result<MediaPage, PexelsError>
pub async fn get_collection_media( &self, id: &str, params: &PaginationParams, ) -> Result<MediaPage, PexelsError>
Auto Trait Implementations§
impl Freeze for PexelsClient
impl !RefUnwindSafe for PexelsClient
impl Send for PexelsClient
impl Sync for PexelsClient
impl Unpin for PexelsClient
impl !UnwindSafe for PexelsClient
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