PexelsClient

Struct PexelsClient 

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

Pexels API 的主要客户端

此客户端提供与 Pexels API 所有端点交互的方法, 并处理认证、请求构建和响应解析。

Implementations§

Source§

impl PexelsClient

Source

pub fn new<S: Into<String>>(api_key: S) -> Self

使用提供的 API 密钥创建新的 PexelsClient

§参数
  • api_key - Pexels API 密钥
§返回

PexelsClient 的新实例

§示例
use pexels_sdk::PexelsClient;

let client = PexelsClient::new("your_api_key");
Source

pub fn with_config<S: Into<String>>( api_key: S, timeout: u64, max_idle_connections: usize, ) -> Self

使用自定义配置创建新的 PexelsClient

§参数
  • api_key - Pexels API 密钥
  • timeout - 请求超时时间(秒)
  • max_idle_connections - 每个主机的最大空闲连接数
§返回

PexelsClient 的新实例

Source

pub fn with_base_url<S: Into<String>>(self, base_url: S) -> Self

为 Pexels API 设置自定义基础 URL

§参数
  • base_url - 自定义基础 URL
§返回

用于方法链的 Self

Source

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", &params).await {
        Ok(photos) => println!("Found {} photos", photos.total_results),
        Err(e) => println!("搜索失败: {}", e),
    }
    Ok(())
}
Source

pub async fn curated_photos( &self, params: &PaginationParams, ) -> Result<PhotosPage, PexelsError>

获取精选/推荐照片

§参数
  • params - 分页参数
§返回

包含精选照片响应或错误的结果

Source

pub async fn get_photo(&self, id: u64) -> Result<Photo, PexelsError>

根据 ID 获取特定照片

§参数
  • id - 照片 ID
§返回

包含照片或错误的结果

Source

pub async fn search_videos( &self, query: &str, params: &VideoSearchParams, ) -> Result<VideosPage, PexelsError>

搜索与指定查询和参数匹配的视频

§参数
  • query - 搜索查询
  • params - 其他搜索参数(分页、过滤器等)
§返回

包含视频搜索响应或错误的结果

Source

pub async fn popular_videos( &self, params: &PaginationParams, ) -> Result<VideosPage, PexelsError>

获取热门视频

§参数
  • params - 分页参数
§返回

包含热门视频响应或错误的结果

Source

pub async fn get_video(&self, id: u64) -> Result<Video, PexelsError>

根据 ID 获取特定视频

§参数
  • id - 视频 ID
§返回

包含视频或错误的结果

Source

pub async fn get_collections( &self, params: &PaginationParams, ) -> Result<CollectionsPage, PexelsError>

获取收藏列表

§参数
  • params - 分页参数
§返回

包含收藏响应或错误的结果

Source

pub async fn get_collection_media( &self, id: &str, params: &PaginationParams, ) -> Result<MediaPage, PexelsError>

获取收藏中的媒体项目(照片和视频)

§参数
  • id - 收藏 ID
  • params - 分页参数
§返回

包含媒体响应或错误的结果

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