Skip to content

Deduplicate code and fix a few clippy complaints#549

Merged
jacksongoode merged 1 commit intojpochyla:mainfrom
itsjunetime:deduplicate_and_clippy
Oct 24, 2024
Merged

Deduplicate code and fix a few clippy complaints#549
jacksongoode merged 1 commit intojpochyla:mainfrom
itsjunetime:deduplicate_and_clippy

Conversation

@itsjunetime
Copy link
Copy Markdown
Contributor

While I was working on #548, I noticed a few areas where code was unnecessarily copied or did extra work/computation that it didn't need to do. Most of that was in the WebApi client struct, but there were a few other instances elsewhere as well. There were also some issues that clippy was complaining about which I took care of.

As far as I can tell, everything still works just as expected after these changes.

@jacksongoode
Copy link
Copy Markdown
Collaborator

Awesome! Thank you for your contribution - I'll have a look now!

Copy link
Copy Markdown
Collaborator

@jacksongoode jacksongoode left a comment

Choose a reason for hiding this comment

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

Looks great! I'll merge it in!

Comment on lines -1064 to -1065
self.send_empty_json(request)?;
Ok(())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah thank you for taking care of these, I thought they might be redundant

Comment on lines +1057 to +1063
// From https://github.com/KRTirtho/spotube/blob/9b024120601c0d381edeab4460cb22f87149d0f8/lib%2Fservices%2Fcustom_spotify_endpoints%2Fspotify_endpoints.dart keep and eye on this and change accordingly
const EXTENSIONS_JSON: &str = r#"{
"persistedQuery": {
"version": 1,
"sha256Hash": "eb3fba2d388cf4fc4d696b1757a58584e9538a3b515ea742e9cc9465807340be"
}
}"#;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wondering if there's a better place to put this, but here is fine for now.

Comment on lines -1121 to +1111
// 0JQ5DAUnp4wcj0bCb3wh3S -> Daily mixes
let json_query = self.build_home_request("spotify:section:0JQ5DAUnp4wcj0bCb3wh3S");
pub fn get_section(&self, section_uri: &str) -> Result<MixedView, Error> {
let request = self
.get("pathfinder/v1/query", Some("api-partner.spotify.com"))?
.query("operationName", "homeSection")
.query("variables", &json_query.0.to_string())
.query("extensions", &json_query.1.to_string());
.query("variables", &self.build_home_request(section_uri)?)
.query("extensions", EXTENSIONS_JSON);

// Extract the playlists
let result = self.load_and_return_home_section(request)?;
self.load_and_return_home_section(request)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice abstraction for this.

@jacksongoode jacksongoode merged commit bb143b6 into jpochyla:main Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants