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

Comments from multiple subreddits #211

Closed
jonerer opened this issue Jan 7, 2018 · 3 comments
Closed

Comments from multiple subreddits #211

jonerer opened this issue Jan 7, 2018 · 3 comments

Comments

@jonerer
Copy link

jonerer commented Jan 7, 2018

Hello!

I'm using jraw version 1.0.0

I'm trying to get comments from multiple subreddits. When getting comments for one, I do this:

    var r = reddit.subreddit("first").comments().build();

But when trying to do the same thing for multiple subscriptions I face this:

    var r = reddit.subreddits("first", "second").comments().build(); // <--- unresolved reference "comments"

I found the reason in the source code in RedditClient.kt on line 301:

    fun subreddits(first: String, second: String, vararg others: String) =
        SubredditReference(this, arrayOf(first, second, *others).joinToString("+")).posts()

The fact that subreddit returns a SubredditReference but subreddits returns a posts iterator seems confusing. Is there a way for me to get comments for multiple subreddits?

As a temporary solution I borrowed the code from RedditClient, and did this: reddit.subreddit(arrayOf("btc", "bitcoin").joinToString("+")).comments().build(); which works fine, but seems like I'm working against the library.

@mattbdean
Copy link
Owner

You're right, that is pretty confusing. I'm going to take .posts() off of the body of subreddits so that it returns a SubredditReference instead of jumping right to the posts:

fun subreddits(first: String, second: String, vararg others: String) =
    SubredditReference(this, arrayOf(first, second, *others).joinToString("+"))

For now you should continue using arrayOf(...).joinToString("+") until this gets patched in 1.1.0

@mattbdean
Copy link
Owner

Fixed. You can continue to use your solution and wait until 1.1.0 or use JitPack:

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.github.mattbdean:JRAW:998642f2db'
}

@jonerer
Copy link
Author

jonerer commented Jan 8, 2018

Thanks for the quick response and an awesome library!

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

No branches or pull requests

2 participants