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