pub struct IopClient { /* private fields */ }Implementations§
Source§impl IopClient
impl IopClient
Sourcepub fn generate_url(
&self,
base_url: String,
params: HashMap<String, String>,
sign: String,
) -> String
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- AHashMapcontaining the query parameters to include in the URL.sign- The signature to append to the URL.
§Returns
A String representing the constructed URL.
Sourcepub fn generate_sign(
&self,
method: Option<String>,
payload: HashMap<String, String>,
) -> String
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- AHashMapcontaining 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.
Sourcepub fn generate_hmac_sha256(&self, data: &[u8]) -> String
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.
Sourcepub async fn build_request_params(
&self,
params: HashMap<String, String>,
) -> HashMap<String, String>
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- AHashMapcontaining business-specific parameters to be included in the API request.
§Returns
Source§impl IopClient
impl IopClient
Sourcepub async fn list_photo_bank_groups(
&self,
id: Option<i32>,
) -> Result<Vec<PhotoAlbumGroup>, Box<dyn Error>>
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. IfNone, 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
impl IopClient
Sourcepub async fn list_product_categories(
&self,
cat_id: i32,
) -> Result<NewCategory, Box<dyn Error>>
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.
Sourcepub async fn get_category_attributes(
self,
cat_id: i32,
) -> Result<CategoryAttributeGroup, Box<dyn Error>>
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
impl IopClient
Sourcepub async fn list_product_countries(
&self,
_language: Option<String>,
) -> Result<ProductCountryDto, Box<dyn Error>>
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
impl IopClient
Sourcepub async fn get_product_groups(
&self,
id: i32,
) -> Result<Vec<ProductGroup>, Box<dyn Error>>
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
impl IopClient
Sourcepub fn get_redirect_url(
&self,
redirect_uri: String,
state: Option<String>,
) -> String
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.
Sourcepub async fn generate_access_token(
&self,
code: String,
) -> Result<AccessToken, Box<dyn Error>>
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.
Sourcepub async fn get_access_token(&self) -> Result<AccessToken, Box<dyn Error>>
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.
Sourcepub async fn refresh_access_token(&self) -> Result<AccessToken, Box<dyn Error>>
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
impl IopClient
Sourcepub async fn new(
appid: String,
app_secret: String,
redis_addr: String,
) -> Result<Self, Box<dyn Error>>
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§
Auto Trait Implementations§
impl Freeze for IopClient
impl !RefUnwindSafe for IopClient
impl Send for IopClient
impl Sync for IopClient
impl Unpin for IopClient
impl !UnwindSafe for IopClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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