Skip to content

Commit

Permalink
Merge pull request #88 from Jaltaire/master
Browse files Browse the repository at this point in the history
Remove '?' prefix in FeedOption::build_url
  • Loading branch information
beanpuppy authored Jul 17, 2024
2 parents 52b85f4 + a8bd5df commit e4eed92
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ tags

/target
**/*.rs.bk
.vscode
.vscode
.idea
6 changes: 3 additions & 3 deletions src/models/me/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Me {
#[maybe_async::maybe_async]
pub async fn saved(&self, options: Option<FeedOption>) -> Result<Saved, RouxError> {
let url = &mut format!(
"user/{}/saved/.json",
"user/{}/saved/.json?",
self.config.username.to_owned().unwrap()
);

Expand All @@ -192,7 +192,7 @@ impl Me {
#[maybe_async::maybe_async]
pub async fn upvoted(&self, options: Option<FeedOption>) -> Result<Saved, RouxError> {
let url = &mut format!(
"user/{}/upvoted/.json",
"user/{}/upvoted/.json?",
self.config.username.to_owned().unwrap()
);

Expand All @@ -207,7 +207,7 @@ impl Me {
#[maybe_async::maybe_async]
pub async fn downvoted(&self, options: Option<FeedOption>) -> Result<Saved, RouxError> {
let url = &mut format!(
"user/{}/downvoted/.json",
"user/{}/downvoted/.json?",
self.config.username.to_owned().unwrap()
);

Expand Down
8 changes: 4 additions & 4 deletions src/models/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl User {
/// Get user's overview.
#[maybe_async::maybe_async]
pub async fn overview(&self, options: Option<FeedOption>) -> Result<Overview, RouxError> {
let url = &mut format!("https://www.reddit.com/user/{}/overview/.json", self.user);
let url = &mut format!("https://www.reddit.com/user/{}/overview/.json?", self.user);

if let Some(options) = options {
options.build_url(url);
Expand All @@ -70,7 +70,7 @@ impl User {
/// Get user's submitted posts.
#[maybe_async::maybe_async]
pub async fn submitted(&self, options: Option<FeedOption>) -> Result<Submissions, RouxError> {
let url = &mut format!("https://www.reddit.com/user/{}/submitted/.json", self.user);
let url = &mut format!("https://www.reddit.com/user/{}/submitted/.json?", self.user);

if let Some(options) = options {
options.build_url(url);
Expand All @@ -88,7 +88,7 @@ impl User {
/// Get user's submitted comments.
#[maybe_async::maybe_async]
pub async fn comments(&self, options: Option<FeedOption>) -> Result<Comments, RouxError> {
let url = &mut format!("https://www.reddit.com/user/{}/comments/.json", self.user);
let url = &mut format!("https://www.reddit.com/user/{}/comments/.json?", self.user);

if let Some(options) = options {
options.build_url(url);
Expand All @@ -106,7 +106,7 @@ impl User {
/// Get user's about page
#[maybe_async::maybe_async]
pub async fn about(&self, options: Option<FeedOption>) -> Result<About, RouxError> {
let url = &mut format!("https://www.reddit.com/user/{}/about/.json", self.user);
let url = &mut format!("https://www.reddit.com/user/{}/about/.json?", self.user);

if let Some(options) = options {
options.build_url(url);
Expand Down
9 changes: 3 additions & 6 deletions src/util/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ impl FeedOption {

/// Build a url from `FeedOption`
pub fn build_url(self, url: &mut String) {
// Add a fake url attr so I don't have to parse things
url.push_str(&String::from("?"));

if let Some(after) = self.after {
url.push_str(&format!("&after={}", after));
} else if let Some(before) = self.before {
Expand Down Expand Up @@ -150,7 +147,7 @@ mod tests {
let url = &mut String::from("");
options.build_url(url);

assert!(*url == format!("?&after={}&", after))
assert!(*url == format!("&after={}&", after))
}

#[test]
Expand All @@ -161,7 +158,7 @@ mod tests {
let url = &mut String::from("");
options.build_url(url);

assert!(*url == format!("?&before={}&", before))
assert!(*url == format!("&before={}&", before))
}

#[test]
Expand All @@ -172,6 +169,6 @@ mod tests {
let url = &mut String::from("");
options.build_url(url);

assert!(*url == format!("?&count={}&", count))
assert!(*url == format!("&count={}&", count))
}
}

0 comments on commit e4eed92

Please sign in to comment.