Struct rust_woocommerce::controllers::ApiClient
source · pub struct ApiClient { /* private fields */ }
Expand description
Struct representing the configured API client.
§Example from environment
let client = rust_woocommerce::ApiClient::from_env().unwrap();
let result = client
.list_all::<Attribute>(Entity::ProductAttribute)
.await?;
§Example with builder
let site_url = "google.com";
let customer_key = "super6secret9";
let customer_secret = "customer4secret2";
let client = rust_woocommerce::ApiClient::builder()
.auth(customer_key, customer_secret)
.site_url(site_url)
.build();
Implementations§
source§impl ApiClient
impl ApiClient
sourcepub async fn retrieve<T>(
&self,
entity: Entity,
entity_id: impl Display
) -> Result<T>where
T: DeserializeOwned,
pub async fn retrieve<T>(
&self,
entity: Entity,
entity_id: impl Display
) -> Result<T>where
T: DeserializeOwned,
Asynchronously retrieves an entity of a specific type.
§Arguments
entity
- The type of entity to retrieve.entity_id
- The ID of the entity to retrieve.
§Returns
A Result containing the deserialized entity or an error if retrieval fails.
§Example
let attribute_id = 4;
let result = client
.retrieve::<Attribute>(Entity::ProductAttribute, attribute_id)
.await?;
sourcepub async fn retrieve_current_currency(&self) -> Result<Currency>
pub async fn retrieve_current_currency(&self) -> Result<Currency>
retrieve current currency
sourcepub async fn create<T>(
&self,
entity: Entity,
object: impl Serialize
) -> Result<T>where
T: DeserializeOwned,
pub async fn create<T>(
&self,
entity: Entity,
object: impl Serialize
) -> Result<T>where
T: DeserializeOwned,
Asynchronously creates entity of a specific type.
§Arguments
entity
- The type of entity to list.object
- The serialized object containing the updated data for the entity.
§Returns
A Result containing the created entity or an error if the create fails.
§Example
let attribute = AttributeDTO::builder()
.name("test attribute")
.option("69")
.build();
let product_to_create = Product::create()
.name("Test product")
.sku("test product")
.regular_price("10000")
.attribute(attribute)
.build();
let created_product: Product = client
.create(Entity::Product, product_to_create)
.await?;
sourcepub async fn update<T>(
&self,
entity: Entity,
entity_id: impl Display,
object: impl Serialize
) -> Result<T>where
T: DeserializeOwned,
pub async fn update<T>(
&self,
entity: Entity,
entity_id: impl Display,
object: impl Serialize
) -> Result<T>where
T: DeserializeOwned,
Asynchronously updates an entity of a specific type.
§Arguments
entity
- The type of entity to update.entity_id
- The ID of the entity to update.object
- The serialized object containing the updated data for the entity.
§Returns
A Result containing the updated entity or an error if the update fails.
§Example
let product_id = 69;
let product_to_update = Product::update().regular_price("5000").build();
let updated_product: Product = client
.update(Entity::Product, product_id, product_to_update)
.await?;
sourcepub async fn delete<T>(
&self,
entity: Entity,
entity_id: impl Display
) -> Result<T>where
T: DeserializeOwned,
pub async fn delete<T>(
&self,
entity: Entity,
entity_id: impl Display
) -> Result<T>where
T: DeserializeOwned,
Asynchronously deletes an entity of a specific type.
§Arguments
entity
- The type of entity to delete.entity_id
- The ID of the entity to delete.
§Returns
A Result containing the deleted entity or an error if the deletion fails.
§Example
let id = 69;
let deleted: Product = client.delete(Entity::Product, id).await?;
sourcepub async fn batch_update<T, O>(
&self,
entity: Entity,
batch_object: BatchObject<O>
) -> Result<BatchObject<T>>
pub async fn batch_update<T, O>( &self, entity: Entity, batch_object: BatchObject<O> ) -> Result<BatchObject<T>>
Asynchronously updates a batch of entities for a specific type.
§Arguments
entity
- The type of entity to update.batch_object
- The batch object containing the entities to update.
§Returns
A Result containing the modified batch object or an error if the update fails.
§Example
let product_id = 69;
let product_to_update = Product::update().id(product_id).regular_price("5000").build();
let batch = BatchObject::builder().add_update(product_to_update).build();
let updated_products: BatchObject<Product> =
client.batch_update(Entity::Product, batch).await?;
sourcepub async fn search<T>(
&self,
entity: Entity,
search_string: impl Into<String>
) -> Result<Vec<T>>where
T: DeserializeOwned,
pub async fn search<T>(
&self,
entity: Entity,
search_string: impl Into<String>
) -> Result<Vec<T>>where
T: DeserializeOwned,
Asynchronously searches for entities of a specific type based on a provided search string.
§Arguments
entity
- The type of entity to search.search_string
- The search string used to filter entities.
§Returns
A Result containing a vector of entities matching the search criteria or an error if the search fails.
§Example
let search_string = "string to search";
let search_result: Vec<Product> =
client.search(Entity::Product, search_string).await?;
source§impl ApiClient
impl ApiClient
sourcepub async fn retrieve_subentity<T>(
&self,
entity: Entity,
entity_id: impl Display,
subentity: SubEntity,
subentity_id: impl Display
) -> Result<T>where
T: DeserializeOwned,
pub async fn retrieve_subentity<T>(
&self,
entity: Entity,
entity_id: impl Display,
subentity: SubEntity,
subentity_id: impl Display
) -> Result<T>where
T: DeserializeOwned,
Asynchronously retrieves a specific subentity of a given entity.
§Arguments
entity
- The type of the main entity.entity_id
- The ID of the main entity.subentity
- The subentity to retrieve.subentity_id
- The ID of the subentity to retrieve.
§Returns
A Result containing the deserialized subentity or an error if retrieval fails.
§Example
let product_id = 69;
let variation_id = 42;
let result: ProductVariation = client
.retrieve_subentity(Entity::Product, product_id, SubEntity::ProductVariation, variation_id)
.await?;
sourcepub async fn list_all_subentities<T>(
&self,
entity: Entity,
entity_id: impl Display,
subentity: SubEntity
) -> Result<Vec<T>>where
T: DeserializeOwned,
pub async fn list_all_subentities<T>(
&self,
entity: Entity,
entity_id: impl Display,
subentity: SubEntity
) -> Result<Vec<T>>where
T: DeserializeOwned,
Asynchronously lists all subentities of a specific entity.
§Arguments
entity
- The type of the main entity.entity_id
- The ID of the main entity.subentity
- The type of subentity to list.
§Returns
A Result containing a vector of the retrieved subentities or an error if retrieval fails.
§Example
let product_id = 69;
let result: Vec<ProductVariation> = client
.list_all_subentities(Entity::Product, product_id, SubEntity::ProductVariation)
.await?;
sourcepub async fn create_subentity<T>(
&self,
entity: Entity,
entity_id: impl Display,
subentity: SubEntity,
object: impl Serialize
) -> Result<T>where
T: DeserializeOwned,
pub async fn create_subentity<T>(
&self,
entity: Entity,
entity_id: impl Display,
subentity: SubEntity,
object: impl Serialize
) -> Result<T>where
T: DeserializeOwned,
Asynchronously reates a specific subentity of a given entity.
§Arguments
entity
- The type of the main entity.entity_id
- The ID of the main entity.subentity
- The type of the subentity to update.object
- The serialized object containing the data to create for the subentity.
§Returns
A Result containing the created subentity or an error if the update fails.
§Example
let product_id = 69;
let variation_to_create = ProductVariation::create().sku("test-sku").build();
let created: ProductVariation = client
.create_subentity(
Entity::Product,
product_id,
SubEntity::ProductVariation,
variation_to_create,
)
.await?;
sourcepub async fn update_subentity<T>(
&self,
entity: Entity,
entity_id: impl Display,
subentity: SubEntity,
subentity_id: impl Display,
object: impl Serialize
) -> Result<T>where
T: DeserializeOwned,
pub async fn update_subentity<T>(
&self,
entity: Entity,
entity_id: impl Display,
subentity: SubEntity,
subentity_id: impl Display,
object: impl Serialize
) -> Result<T>where
T: DeserializeOwned,
Asynchronously updates a specific subentity of a given entity.
§Arguments
entity
- The type of the main entity.entity_id
- The ID of the main entity.subentity
- The type of the subentity to update.subentity_id
- The ID of the subentity to update.object
- The serialized object containing the updated data for the subentity.
§Returns
A Result containing the updated subentity or an error if the update fails.
§Example
let product_id = 69;
let variation_id = 69;
let update = ProductVariation::update().regular_price("4000").build();
let updated: ProductVariation = client
.update_subentity(
Entity::Product,
product_id,
SubEntity::ProductVariation,
variation_id,
update,
)
.await?;
sourcepub async fn delete_subentity<T>(
&self,
entity: Entity,
entity_id: impl Display,
subentity: SubEntity,
subentity_id: impl Display
) -> Result<T>where
T: DeserializeOwned,
pub async fn delete_subentity<T>(
&self,
entity: Entity,
entity_id: impl Display,
subentity: SubEntity,
subentity_id: impl Display
) -> Result<T>where
T: DeserializeOwned,
Asynchronously deletes a specific subentity of a given entity.
§Arguments
entity
- The type of the main entity.entity_id
- The ID of the main entity.subentity
- The type of the subentity to delete.subentity_id
- The ID of the subentity to delete.
§Returns
A Result containing the status of the deletion operation or an error if the deletion fails.
§Example
let product_id = 69;
let variation_id = 69;
let deleted: ProductVariation = client
.delete_subentity(Entity::Product, product_id, SubEntity::ProductVariation, variation_id)
.await?;
source§impl ApiClient
impl ApiClient
sourcepub async fn retrieve_sales_report_with_period(
&self,
period: Period
) -> Result<Vec<SaleReport>>
pub async fn retrieve_sales_report_with_period( &self, period: Period ) -> Result<Vec<SaleReport>>
Retrieves and views a sales report for the specified period.
§Arguments
period
- APeriod
object indicating the time period for the sales report.
§Returns
Result<Vec<SaleReport>>
- A result containing a vector ofSaleReport
objects if the operation is successful, or an error.
§Example
let result_with_period = client
.retrieve_sales_report_with_period(Period::Week)
.await?;
sourcepub async fn retrieve_sales_report_with_min_max_dates(
&self,
date_min: impl Into<String>,
date_max: impl Into<String>
) -> Result<Vec<SaleReport>>
pub async fn retrieve_sales_report_with_min_max_dates( &self, date_min: impl Into<String>, date_max: impl Into<String> ) -> Result<Vec<SaleReport>>
Retrieves and views a sales report for the specified date range.
§Arguments
date_min
- A string representing the minimum date for the sales report need to be in the YYYY-MM-DD format..date_max
- A string representing the maximum date for the sales report need to be in the YYYY-MM-DD format..
§Returns
Result<Vec<SaleReport>>
- A result containing a vector ofSaleReport
objects if the operation is successful, or an error.
§Example
let result_with_dates = client
.retrieve_sales_report_with_min_max_dates("2023-12-01", "2023-12-31")
.await?;
sourcepub async fn retrieve_top_sellers_report_with_period(
&self,
period: Period
) -> Result<Vec<TopSellersReport>>
pub async fn retrieve_top_sellers_report_with_period( &self, period: Period ) -> Result<Vec<TopSellersReport>>
Retrieves and views a top sellers report for the specified period.
§Arguments
period
- APeriod
object indicating the time period for the sales report.
§Returns
Result<Vec<TopSellersReport>>
- A result containing a vector ofTopSellersReport
objects if the operation is successful, or an error.
§Example
let result_with_period = client
.retrieve_top_sellers_report_with_period(Period::Week)
.await?;
sourcepub async fn retrieve_top_sellers_report_with_min_max_dates(
&self,
date_min: impl Into<String>,
date_max: impl Into<String>
) -> Result<Vec<TopSellersReport>>
pub async fn retrieve_top_sellers_report_with_min_max_dates( &self, date_min: impl Into<String>, date_max: impl Into<String> ) -> Result<Vec<TopSellersReport>>
Retrieves and views a top sellers report for the specified date range.
§Arguments
date_min
- A string representing the minimum date for the sales report need to be in the YYYY-MM-DD format..date_max
- A string representing the maximum date for the sales report need to be in the YYYY-MM-DD format..
§Returns
Result<Vec<TopSellersReport>>
- A result containing a vector ofTopSellersReport
objects if the operation is successful, or an error.
§Example
let result_with_dates = client
.retrieve_top_sellers_report_with_min_max_dates("2023-12-01", "2023-12-31")
.await?;