Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ Cargo.lock
.env*
samples
.DS_Store
.vscode
.vscode
.idea
/schemas
/tmp
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"cli",
"walmart-partner-api"
"walmart-partner-api",
"openapi"
]
11 changes: 7 additions & 4 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
name = "cli"
version = "0.1.0"
authors = ["Flux Xu <fluxxu@gmail.com>"]
edition = "2018"
edition = "2021"

[dependencies]
clap = "2.26.0"
dotenv = "0.10.1"
clap = { version = "4.0.26", features = ["derive"] }
dotenv = "0.15.0"
chrono = { version = "0.4", features = ["serde"] }
walmart_partner_api = { path = "../walmart-partner-api" }
serde_json = "1.0.2"
env_logger = "0.6.2"
anyhow = "1.0.66"
tokio = { version = "1.0", features = ["rt"] }
tracing-subscriber = "0.3.16"
tracing = "0.1.37"
120 changes: 106 additions & 14 deletions cli/src/feed.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,112 @@
use std::fs::File;
use walmart_partner_api::Client;
use anyhow::Result;
use clap::{Parser, Subcommand};

pub fn upload(client: &Client, feed_type: &str, path: &str) {
let f = File::open(path).unwrap();
let ack = client.bulk_upload_xml(feed_type, f).unwrap();
println!("{:#?}", ack);
#[derive(Subcommand)]
pub enum CaFeedCommand {
ListStatuses(FeedStatus),
GetStatusItem(FeedStatusItem),
UploadXml(CaUploadXml),
}

pub fn status(client: &Client) {
let status = client.get_all_feed_statuses(&Default::default()).unwrap();
println!("{:#?}", status);
#[derive(Subcommand)]
pub enum UsFeedCommand {
ListStatuses(FeedStatus),
GetStatusItem(FeedStatusItem),
}

pub fn inspect(client: &Client, id: &str) {
let status = client
.get_feed_and_item_status(id, &Default::default())
.unwrap();
println!("{:#?}", status);
#[derive(Parser)]
pub struct FeedStatus {
#[clap(long)]
pub feed_id: Option<String>,
#[clap(long)]
pub limit: Option<i32>,
#[clap(long)]
pub offset: Option<i32>,
}

#[derive(Parser)]
pub struct FeedStatusItem {
#[clap(long)]
pub id: String,
#[clap(long)]
pub include_details: Option<bool>,
#[clap(long)]
pub limit: Option<i32>,
#[clap(long)]
pub offset: Option<i32>,
}

#[derive(Parser)]
pub struct CaUploadXml {
#[clap(long)]
pub feed_type: String,
#[clap(long)]
pub path: String,
}

impl CaFeedCommand {
pub async fn run(self, client: walmart_partner_api::ca::Client) -> Result<()> {
match self {
CaFeedCommand::ListStatuses(cmd) => {
let r = client
.get_all_feed_statuses(walmart_partner_api::ca::GetAllFeedStatusesQuery {
feed_id: cmd.feed_id,
limit: cmd.limit,
offset: cmd.offset,
})
.await?;
println!("{:#?}", r)
}
CaFeedCommand::GetStatusItem(cmd) => {
let r = client
.get_feed_and_item_status(
&cmd.id,
walmart_partner_api::ca::GetFeedAndItemStatusQuery {
include_details: cmd.include_details,
limit: cmd.limit,
offset: cmd.offset,
},
)
.await?;
println!("{:#?}", r)
}
CaFeedCommand::UploadXml(cmd) => {
let f = std::fs::File::open(cmd.path).unwrap();
let r = client.bulk_upload_xml(&cmd.feed_type, f).await?;
println!("{:#?}", r)
}
}
Ok(())
}
}

impl UsFeedCommand {
pub async fn run(self, client: walmart_partner_api::us::Client) -> Result<()> {
match self {
UsFeedCommand::ListStatuses(cmd) => {
let r = client
.get_all_feed_statuses(walmart_partner_api::us::GetAllFeedStatusesQuery {
feed_id: cmd.feed_id,
limit: cmd.limit,
offset: cmd.offset,
})
.await?;
println!("{:#?}", r)
}
UsFeedCommand::GetStatusItem(cmd) => {
let r = client
.get_feed_and_item_status(
&cmd.id,
walmart_partner_api::us::GetFeedAndItemStatusQuery {
include_details: cmd.include_details,
limit: cmd.limit,
offset: cmd.offset,
},
)
.await?;
println!("{:#?}", r)
}
}
Ok(())
}
}
110 changes: 96 additions & 14 deletions cli/src/inventory.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,97 @@
use walmart_partner_api::inventory::*;
use walmart_partner_api::Client;

pub fn set_inventory(client: &Client, sku: &str, quantity: i32, lagtime: i32) {
let inventory = Inventory {
quantity: Quantity {
unit: "EACH".to_string(),
amount: quantity,
},
sku: sku.to_string(),
fulfillmentLagTime: lagtime,
};
let res = client.update_item_inventory(&inventory).unwrap();
println!("{}", serde_json::to_string_pretty(&res).unwrap());
use anyhow::Result;
use clap::{Parser, Subcommand};

#[derive(Subcommand)]
pub enum CaInventoryCommand {
Get(Get),
Update(CaUpdate),
}

#[derive(Subcommand)]
pub enum UsInventoryCommand {
Get(Get),
Update(UsUpdate),
}

#[derive(Parser)]
pub struct Get {
#[clap(long)]
pub sku: String,
}

#[derive(Parser)]
pub struct CaUpdate {
#[clap(long)]
pub sku: String,
#[clap(long)]
pub unit: String,
#[clap(long)]
pub amount: i32,
#[clap(long)]
pub fulfillment_lag_time: i32,
#[clap(long)]
pub partner_id: Option<String>,
#[clap(long)]
pub offer_id: Option<String>,
}

#[derive(Parser)]
pub struct UsUpdate {
#[clap(long)]
pub sku: String,
#[clap(long)]
pub unit: String,
#[clap(long)]
pub amount: i32,
}

impl CaInventoryCommand {
pub async fn run(self, client: walmart_partner_api::ca::Client) -> Result<()> {
match self {
CaInventoryCommand::Get(cmd) => {
let r = client.get_item_inventory(cmd.sku).await?;
println!("{:#?}", r)
}
CaInventoryCommand::Update(cmd) => {
let r = client
.update_item_inventory(walmart_partner_api::ca::Inventory {
sku: cmd.sku,
fulfillment_lag_time: cmd.fulfillment_lag_time,
partner_id: cmd.partner_id,
offer_id: cmd.offer_id,
quantity: walmart_partner_api::ca::InventoryQuantity {
unit: cmd.unit,
amount: cmd.amount,
},
})
.await?;
println!("{:#?}", r)
}
}
Ok(())
}
}

impl UsInventoryCommand {
pub async fn run(self, client: walmart_partner_api::us::Client) -> Result<()> {
match self {
UsInventoryCommand::Get(cmd) => {
let r = client.get_item_inventory(cmd.sku).await?;
println!("{:#?}", r)
}
UsInventoryCommand::Update(cmd) => {
let r = client
.update_item_inventory(walmart_partner_api::us::Inventory {
sku: cmd.sku,
quantity: walmart_partner_api::us::InventoryQuantity {
unit: cmd.unit,
amount: cmd.amount,
},
})
.await?;
println!("{:#?}", r)
}
}
Ok(())
}
}
Loading