Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.

Commit 0193e83

Browse files
committed
less unwrap in prices schedule
1 parent 35dfef1 commit 0193e83

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "api"
3-
version = "2.1.5"
3+
version = "2.1.6"
44
edition = "2024"
55

66
[dependencies]

src/schedules/prices.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ pub async fn run(state: State) {
4141
.unwrap()
4242
.json::<serde_json::Value>()
4343
.await
44-
.unwrap()["data"]
45-
.clone(),
44+
.unwrap_or_default()
45+
.get("products")
46+
.cloned()
47+
.unwrap_or_default(),
4648
)
47-
.unwrap()
49+
.unwrap_or_default()
4850
}
4951

5052
for extension in extensions.iter_mut() {
@@ -58,13 +60,12 @@ pub async fn run(state: State) {
5860
),
5961
);
6062

61-
if extension.platforms.contains_key("SOURCEXCHANGE") {
62-
if let Some(sxc_product) = sxc_products
63-
.iter()
64-
.find(|product| product.url == extension.platforms["SOURCEXCHANGE"].url)
63+
if let Some(key) = extension.platforms.get_mut("SOURCEXCHANGE") {
64+
if let Some(sxc_product) =
65+
sxc_products.iter().find(|product| product.url == key.url)
6566
{
66-
*extension.platforms.get_mut("SOURCEXCHANGE").unwrap() = ExtensionPlatform {
67-
url: extension.platforms["SOURCEXCHANGE"].url.clone(),
67+
*key = ExtensionPlatform {
68+
url: key.url.clone(),
6869
price: sxc_product.price,
6970
currency: sxc_product.currency.clone(),
7071
reviews: sxc_product.review_count,
@@ -73,14 +74,13 @@ pub async fn run(state: State) {
7374
}
7475
}
7576

76-
if extension.platforms.contains_key("BUILTBYBIT") {
77-
let product: Option<BbbProduct> = serde_json::from_value(
77+
if let Some(key) = extension.platforms.get_mut("BUILTBYBIT") {
78+
let product: Result<Option<BbbProduct>, _> = serde_json::from_value(
7879
state
7980
.client()
8081
.get(format!(
8182
"https://api.builtbybit.com/v1/resources/{}",
82-
extension.platforms["BUILTBYBIT"]
83-
.url
83+
key.url
8484
.split('.')
8585
.last()
8686
.unwrap()
@@ -91,14 +91,15 @@ pub async fn run(state: State) {
9191
.unwrap()
9292
.json::<serde_json::Value>()
9393
.await
94-
.unwrap()["data"]
95-
.clone(),
96-
)
97-
.ok();
94+
.unwrap_or_default()
95+
.get("data")
96+
.cloned()
97+
.unwrap_or_default(),
98+
);
9899

99-
if let Some(product) = product {
100-
*extension.platforms.get_mut("BUILTBYBIT").unwrap() = ExtensionPlatform {
101-
url: extension.platforms["BUILTBYBIT"].url.clone(),
100+
if let Ok(Some(product)) = product {
101+
*key = ExtensionPlatform {
102+
url: key.url.clone(),
102103
price: product.price,
103104
currency: product.currency.clone(),
104105
reviews: Some(product.review_count),
@@ -107,9 +108,9 @@ pub async fn run(state: State) {
107108
}
108109
}
109110

110-
if extension.platforms.contains_key("GITHUB") {
111-
*extension.platforms.get_mut("GITHUB").unwrap() = ExtensionPlatform {
112-
url: extension.platforms["GITHUB"].url.clone(),
111+
if let Some(key) = extension.platforms.get_mut("GITHUB") {
112+
*key = ExtensionPlatform {
113+
url: key.url.clone(),
113114
price: 0.0,
114115
currency: "USD".to_string(),
115116
reviews: Some(0),

0 commit comments

Comments
 (0)