Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to get the trader price #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions src/trading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,34 @@ impl Tarkov {
handle_error(res.error, res.data)
}

/// Get list of price trader is willing to pay for in users inventory
pub async fn get_trader_prices(&self, trader_id: &str) -> Result<HashMap<String, Price>> {
if trader_id.is_empty() {
return Err(Error::InvalidParameters);
}

let mut result: HashMap<String, Price> = HashMap::new();

let mut prices = self.get_trader_prices_raw(trader_id).await?;

for (id, price_w) in prices.drain() {
if price_w.len() != 1 {
panic!("The price structure top is wrong");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't panic but instead return a proper error type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I originally had a proper error type here, but I saw that in places like the get_trader_prices_raw if the response doesn't match up, you panic with expect. I am all for errors though, I just couldn't find an appropriate error type.

}
let ww = price_w.get(0).unwrap();
if ww.len() != 1 {
panic!("The price structure is wrong!");
}
let pw = ww.get(0).unwrap();

if result.insert(id, pw.clone()).is_some() {
panic!("We found it double!");
}
}

Ok(result)
}

/// Get a list of items for sale by trader ID.
pub async fn get_trader_items(&self, trader_id: &str) -> Result<Vec<TraderItem>> {
if trader_id.is_empty() {
Expand Down