IopClient

Struct IopClient 

Source
pub struct IopClient { /* private fields */ }

Implementations§

Source§

impl IopClient

Source

pub fn generate_url( &self, base_url: String, params: HashMap<String, String>, sign: String, ) -> String

Construct a URL with the given base URL, query parameters, and signature.

§Arguments
  • base_url - The base URL to use for the constructed URL.
  • params - A HashMap containing the query parameters to include in the URL.
  • sign - The signature to append to the URL.
§Returns

A String representing the constructed URL.

Source

pub fn generate_sign( &self, method: Option<String>, payload: HashMap<String, String>, ) -> String

Generates a signature based on the provided HTTP method and payload.

拼接参数名与参数值 官方文档

This function sorts the payload by key, concatenates the keys and values, and prepends the optional HTTP method if provided. It then generates an HMAC-SHA256 hash of the resulting string using the app’s secret key.

§Arguments
  • method - An optional string representing the HTTP method to be included in the signature calculation.
  • payload - A HashMap containing the parameters to be signed, where keys are parameter names and values are parameter values.
§Returns

A String representing the computed HMAC-SHA256 signature in hexadecimal format.

Source

pub fn generate_hmac_sha256(&self, data: &[u8]) -> String

Generates an HMAC-SHA256 signature of the provided data.

The signature is generated by creating an HMAC context with the app’s secret key, updating the context with the provided data, and then finalizing the context to obtain the signature. The signature is then converted to a hexadecimal string and returned.

§Arguments
  • data - The data to be signed, represented as a byte slice.
§Returns

A String representing the computed HMAC-SHA256 signature in hexadecimal format.

Source

pub async fn build_request_params( &self, params: HashMap<String, String>, ) -> HashMap<String, String>

Builds a complete set of request parameters for API calls.

This function constructs a HashMap containing both common and business-specific parameters required for API requests. It includes parameters such as app_key, timestamp, sign_method, and language, and attempts to include an access_token if available. The provided params are added to the map as business-specific parameters.

§Arguments
  • params - A HashMap containing business-specific parameters to be included in the API request.
§Returns
Source§

impl IopClient

Source

pub async fn list_photo_bank_groups( &self, id: Option<i32>, ) -> Result<Vec<PhotoAlbumGroup>, Box<dyn Error>>

图片银行分组信息获取

官方文档

Lists all photo bank groups, or a specific photo bank group by its identifier.

The photo bank groups are ordered by parent_id and then id in descending order.

§Arguments
  • id - The identifier of the photo bank group to retrieve. If None, all groups are retrieved.
§Returns

A Result containing a vector of PhotoAlbumGroup models if successful, or an error if the process fails.

Source§

impl IopClient

Source

pub async fn list_product_categories( &self, cat_id: i32, ) -> Result<NewCategory, Box<dyn Error>>

(新)ICBU类目树获取接口

官方文档

Get the specified category by cat_id.

§Arguments
  • cat_id - The category ID.
§Returns

A Result containing the NewCategory model if successful, or an error if the process fails.

The function first retrieves an access token, constructs a map of parameters required for the API call, and includes the category ID and language. A signature is then generated for the request, and the request is sent to the API endpoint. Upon successful completion, the category information is returned.

Source

pub async fn get_category_attributes( self, cat_id: i32, ) -> Result<CategoryAttributeGroup, Box<dyn Error>>

类目属性获取

官方文档

Retrieve the category attributes for the specified category by cat_id.

§Arguments
  • cat_id - The category ID.
§Returns

A Result containing the CategoryAttributeGroup model if successful, or an error if the process fails.

The function first retrieves an access token, constructs a map of parameters required for the API call, and includes the category ID and language. A signature is then generated for the request, and the request is sent to the API endpoint. Upon successful completion, the category attributes are returned.

Source§

impl IopClient

Source

pub async fn list_product_countries( &self, _language: Option<String>, ) -> Result<ProductCountryDto, Box<dyn Error>>

国际站获取商品国家列表

官方文档

Retrieves a list of product countries available from the Alibaba ICBU API.

This function constructs the necessary request parameters, generates a signature, and sends a request to the Alibaba API to obtain a list of product countries. The request includes a language option, though it is currently unused.

§Arguments
  • _language - An optional language parameter that can be provided for localization, though it is not currently utilized in the request.
§Returns

A Result containing a vector of PhotoAlbumGroup models if successful, or an error if the process fails. The function logs the constructed parameters, the request URL, and the response result for debugging purposes.

Source§

impl IopClient

Source

pub async fn get_product_groups( &self, id: i32, ) -> Result<Vec<ProductGroup>, Box<dyn Error>>

方法: 分组信息获取

描述:分组信息获取, 官方文档

Retrieves the product group information for the specified group ID.

This function constructs the necessary request parameters, generates a signature, and sends a request to the Alibaba API to obtain information about a product group.

§Arguments
  • id - The identifier for the product group.
§Returns

A Result containing the ProductGroup model if successful, or an error if the process fails.

The function first retrieves an access token, constructs a map of parameters required for the API call, and includes the group ID and language. A signature is then generated for the request, and the request is sent to the API endpoint. Upon successful completion, the product group information is returned.

Source§

impl IopClient

Source

pub fn get_redirect_url( &self, redirect_uri: String, state: Option<String>, ) -> String

Constructs and returns a redirect URL for the OAuth authorization process.

§Arguments
  • redirect_uri - The URI to which the response should be sent after authorization.
  • state - An optional parameter to maintain state between the request and callback.
§Returns

A String representing the complete redirect URL, including query parameters for response type, client ID, redirect URI, and state.

Source

pub async fn generate_access_token( &self, code: String, ) -> Result<AccessToken, Box<dyn Error>>

Generates an access token using the provided authorization code. [GenerateAccessToken]https://open.alibaba.com/doc/api.htm?spm=a2o9m.11193494.0.0.24813a3aBw28pU#/api?cid=2&path=/auth/token/create&methodType=GET/POST

§Arguments
  • code - The authorization code received after user authorization.
§Returns

A Result containing the AccessToken model if successful, or an error if the process fails.

This function constructs the necessary request parameters, generates a signature, and sends a request to the Alibaba API to obtain an access token. The token is then stored in Redis for future access.

Source

pub async fn get_access_token(&self) -> Result<AccessToken, Box<dyn Error>>

Retrieves the access token associated with the client from Redis.

§Returns

A Result containing the AccessToken model if the token exists, or an error if the token is not found in Redis.

Source

pub async fn refresh_access_token(&self) -> Result<AccessToken, Box<dyn Error>>

Refreshes the access token using the stored refresh token.

This function retrieves the current access token and uses its refresh token to request a new access token from the Alibaba API. The newly obtained access token is then stored in Redis for future access.

§Returns

A Result containing the AccessToken model if successful, or an error if the process fails.

§Errors

Returns an error if retrieving the current access token fails, or if the request to refresh the token is unsuccessful.

Source§

impl IopClient

Source

pub async fn new( appid: String, app_secret: String, redis_addr: String, ) -> Result<Self, Box<dyn Error>>

Creates a new instance of IopClient.

This function initializes an IopClient with the specified application ID, application secret, and Redis address. It attempts to create a connection pool to the Redis server using the provided address and verifies the connection by setting a test key. If the connection is successful, an IopClient object is returned; otherwise, the function panics with an error message.

§Arguments
  • appid - The application ID for the client.
  • app_secret - The secret key associated with the application ID.
  • redis_addr - The address of the Redis server to connect to.
§Returns

A Result containing the IopClient instance if successful, or an error if the Redis connection could not be established.

Trait Implementations§

Source§

impl Clone for IopClient

Source§

fn clone(&self) -> IopClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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