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

source

pub async fn retrieve<T>( &self, entity: Entity, entity_id: impl Display ) -> Result<T>

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?;
source

pub async fn retrieve_current_currency(&self) -> Result<Currency>

retrieve current currency

source

pub async fn list_all<T>(&self, entity: Entity) -> Result<Vec<T>>

Asynchronously lists all entities of a specific type.

§Arguments
  • entity - The type of entity to list.
§Returns

A Result containing a vector of the retrieved entities or an error if retrieval fails.

§Example
let result = client
    .list_all::<Attribute>(Entity::ProductAttribute)
    .await?;
source

pub async fn create<T>( &self, entity: Entity, object: impl Serialize ) -> Result<T>

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?;
source

pub async fn update<T>( &self, entity: Entity, entity_id: impl Display, object: impl Serialize ) -> Result<T>

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?;
source

pub async fn delete<T>( &self, entity: Entity, entity_id: impl Display ) -> Result<T>

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?;
source

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?;
source

pub async fn search<T>( &self, entity: Entity, search_string: impl Into<String> ) -> Result<Vec<T>>

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

source

pub async fn retrieve_subentity<T>( &self, entity: Entity, entity_id: impl Display, subentity: SubEntity, subentity_id: impl Display ) -> Result<T>

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?;
source

pub async fn list_all_subentities<T>( &self, entity: Entity, entity_id: impl Display, subentity: SubEntity ) -> Result<Vec<T>>

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?;
source

pub async fn create_subentity<T>( &self, entity: Entity, entity_id: impl Display, subentity: SubEntity, object: impl Serialize ) -> Result<T>

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?;
source

pub async fn update_subentity<T>( &self, entity: Entity, entity_id: impl Display, subentity: SubEntity, subentity_id: impl Display, object: impl Serialize ) -> Result<T>

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?;
source

pub async fn delete_subentity<T>( &self, entity: Entity, entity_id: impl Display, subentity: SubEntity, subentity_id: impl Display ) -> Result<T>

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

source

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 - A Period object indicating the time period for the sales report.
§Returns
  • Result<Vec<SaleReport>> - A result containing a vector of SaleReport objects if the operation is successful, or an error.
§Example
let result_with_period = client
    .retrieve_sales_report_with_period(Period::Week)
    .await?;
source

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 of SaleReport 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?;
source

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 - A Period object indicating the time period for the sales report.
§Returns
  • Result<Vec<TopSellersReport>> - A result containing a vector of TopSellersReport objects if the operation is successful, or an error.
§Example
let result_with_period = client
    .retrieve_top_sellers_report_with_period(Period::Week)
    .await?;
source

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 of TopSellersReport 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?;
source§

impl ApiClient

source

pub async fn run_system_status_tool( &self, id: impl Into<String> ) -> Result<SystemStatusTool>

source§

impl ApiClient

source

pub fn from_env() -> Result<Self>

source

pub fn builder() -> ApiClientBuilder<NoAuth, NoBaseUrl>

source

pub fn ck(&self) -> String

source

pub fn cs(&self) -> String

source

pub fn client(&self) -> Client

source

pub fn base_url(&self) -> String

Trait Implementations§

source§

impl Clone for ApiClient

source§

fn clone(&self) -> ApiClient

Returns a copy 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> 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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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