### GitBook Serve with Watch for JRAW Docs Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Installs GitBook dependencies and starts a GitBook server with live reloading enabled for the JRAW documentation. This command is typically run in a separate terminal to monitor changes. ```sh cd docs/build/docs && gitbook install && gitbook serve --watch ``` -------------------------------- ### Add JRAW Dependency (Gradle) Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/quickstart.md This snippet shows how to add the JRAW library as a dependency in a Gradle project. It includes configuring the jcenter() repository and specifying the JRAW artifact with a version placeholder. ```Groovy repositories { jcenter() } dependencies { compile "net.dean.jraw:JRAW:$jrawVersion" } ``` -------------------------------- ### Install gitbook-cli Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Installs the gitbook-cli tool globally using npm. This is a prerequisite for running integration tests. ```shell $ npm install --global gitbook-cli ``` -------------------------------- ### Add JRAW Dependency (Maven) Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/quickstart.md This snippet demonstrates how to add the JRAW library as a dependency in a Maven project. It requires adding the jcenter() repository to the pom.xml and then declaring the JRAW artifact with a version placeholder. ```XML net.dean.jraw JRAW ${jraw.version} ``` -------------------------------- ### Get Basic User Information Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Shows how to fetch basic account information for the authenticated user using JRAW. This includes details like username and karma. ```Java /* Example for getting basic user information */ // Assuming 'reddit' is an authenticated JRAW instance User user = reddit.me(); System.out.println("Username: " + user.getDisplayName()); System.out.println("Karma: " + user.getKarma()); ``` -------------------------------- ### Get User Subscriptions Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Demonstrates how to retrieve a list of subreddits a user is subscribed to using JRAW. This requires user authentication. ```Java /* Example for getting user subscriptions */ // Assuming 'reddit' is an authenticated JRAW instance User user = reddit.me(); for (Subreddit subreddit : user.getSubscriptions()) { System.out.println(subreddit.getDisplayName()); } ``` -------------------------------- ### JRAW Simple Pagination Example Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/pagination.md Demonstrates a basic example of using JRAW's Paginator to fetch paginated data from the Reddit API. It shows how to create a Paginator and retrieve listings. ```Java Listing posts = new DefaultPaginator(reddit, Target.subreddit("java")).build().next(); ``` -------------------------------- ### Get Current Flair Source: https://github.com/mattbdean/jraw/wiki/Fluent-API Provides an example of how to fetch the current flair template for a subreddit. ```Java FlairTemplate currentFlair = fluent.subreddit("pics").flair().current(); ``` -------------------------------- ### Get User Trophies Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Demonstrates how to retrieve a list of trophies associated with a user's account using JRAW. This requires user authentication. ```Java /* Example for getting user trophies */ // Assuming 'reddit' is an authenticated JRAW instance User user = reddit.me(); for (Trophy trophy : user.getTrophies()) { System.out.println(trophy.getName()); } ``` -------------------------------- ### JRAW For-Each Paginator Example Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/pagination.md Demonstrates a more concise way to iterate through JRAW Paginator results using a for-each loop. ```Java for (Listing page : new DefaultPaginator<>(reddit, Target.subreddit("java")).build()) { // Process posts in the page } ``` -------------------------------- ### Send Private Message Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Provides an example of sending a private message to another Reddit user using JRAW. This requires user authentication. ```Java /* Example for sending a private message */ // Assuming 'reddit' is an authenticated JRAW instance User user = reddit.me(); user.sendMessage("recipientUsername", "Subject", "Message body"); ``` -------------------------------- ### Refresh Access Token with JRAW Source: https://github.com/mattbdean/jraw/wiki/OAuth2 Shows how to refresh an access token for web or installed apps in JRAW. This requires the `permanent = true` permission during authorization and uses the `refreshToken` method with the appropriate `Credentials`. ```Java // Provided that 'redditClient' is an already-authenticated RedditClient // and `credentials' is a Credentials object for a web/installed app: OAuthData newAuthData = redditClient.getOAuthHelper().refreshToken(credentials); redditClient.authenticate(newAuthData); ``` -------------------------------- ### Set and Remove Flair Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Provides examples for setting and removing flair for a subreddit or a specific user within a subreddit using JRAW. This functionality requires moderator privileges or user permissions. ```Java /* Example for setting and removing flair */ // Assuming 'reddit' is an authenticated JRAW instance and 'subreddit' is a Subreddit object // Set flair for a user subreddit.flair("username", "flair_text"); // Remove flair for a user subreddit.flair("username", null); ``` -------------------------------- ### JRAW Accumulate Method Example Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/pagination.md Explains and demonstrates the `accumulate` method in JRAW, which fetches a specified number of pages and returns them as separate listings. ```Java List> pages = new DefaultPaginator(reddit, Target.subreddit("java")).build().accumulate(5); ``` -------------------------------- ### Create and Update Multireddit Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Demonstrates how to create a new multireddit or update an existing one using JRAW. This involves specifying the name, description, and subreddits to include. ```Java /* Example for creating/updating a multireddit */ // Assuming 'reddit' is an authenticated JRAW instance String[] subreddits = {"pics", "gifs"}; reddit.createMultireddit("my_new_multireddit", subreddits, "A description", true); // To update an existing one, you would typically fetch it first and then modify. ``` -------------------------------- ### List Multireddits Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Shows how to list all the multireddits created by the authenticated user using JRAW. This requires user authentication. ```Java /* Example for listing multireddits */ // Assuming 'reddit' is an authenticated JRAW instance User user = reddit.me(); for (Multireddit multireddit : user.getMultireddits()) { System.out.println(multireddit.getDisplayName()); } ``` -------------------------------- ### JSON Response Example Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/internals.md An example of a JSON response structure, likely from an API, showing user-related information. This format is common for representing data objects in web services. ```JSON { "...", "verified": false, "is_gold": false, "link_karma": 10, "..." } ``` -------------------------------- ### Get Happening Now Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches live updates for the 'happening now' feature using the GET /api/live/happening_now endpoint. This functionality is provided by the `happeningNow()` method in `RedditClient`. ```Kotlin RedditClient.happeningNow() ``` -------------------------------- ### Continuous Gradle Build for JRAW Docs Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Starts a continuous build process for the JRAW documentation site using Gradle. This command watches for file changes and automatically rebuilds the site. ```sh ./gradlew -t :docs:buildSite ``` -------------------------------- ### JRAW Iterable Paginator Example Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/pagination.md Shows how to use the Iterable interface of JRAW's Paginator to iterate through pages of data using a while loop. ```Java Paginator paginator = new DefaultPaginator<>(reddit, Target.subreddit("java")).build(); while (paginator.hasNext()) { Listing page = paginator.next(); // Process posts in the page } ``` -------------------------------- ### Iterate Front Page Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Demonstrates how to iterate through the front page submissions using JRAW. This is a fundamental operation for fetching content from Reddit. ```Java /* Example for iterating the front page */ // Assuming 'reddit' is an authenticated JRAW instance for (Submission submission : reddit.front()) { System.out.println(submission.getTitle()); } ``` -------------------------------- ### Get Multireddit Description Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves the description of a multireddit via the GET /api/multi/{multipath}/description endpoint. The `description()` method in `MultiredditReference` is used for this. ```Kotlin MultiredditReference.description() ``` -------------------------------- ### Get Best Posts Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves posts from the 'best' listing of Reddit using the GET /best endpoint. The `posts()` method in `SubredditReference` is used for this. ```Kotlin SubredditReference.posts() ``` -------------------------------- ### AccountHelper Initialization with OAuth2 Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/oauth2.md Demonstrates how to initialize the AccountHelper with OAuth2 credentials to create authenticated Reddit clients. This is a common starting point for interacting with the Reddit API using JRAW. ```Java AccountHelper accountHelper = OAuth2.accountHelper(); ``` -------------------------------- ### Get Info for Subreddit Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves information for a given subreddit using the GET /r/{subreddit}/api/info endpoint. This method is implemented in the `lookup()` function of the `RedditClient` class. ```Kotlin RedditClient.lookup() ``` -------------------------------- ### JRAW AccumulateMerged Method Example Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/pagination.md Illustrates the `accumulateMerged` method in JRAW, which fetches a specified number of pages and merges all the data into a single list. ```Java List posts = new DefaultPaginator(reddit, Target.subreddit("java")).build().accumulateMerged(5); ``` -------------------------------- ### Find Imgur Links from Multiple Subreddits Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Shows how to find Imgur links from multiple specified subreddits using JRAW. This is useful for aggregating image content across different communities. ```Java /* Example for finding Imgur links from multiple subreddits */ // Assuming 'reddit' is an authenticated JRAW instance String[] subreddits = {"pics", "aww", "gifs"}; for (Submission submission : reddit.getSubreddits(subreddits).hot()) { if (submission.getUrl().contains("imgur.com")) { System.out.println(submission.getUrl()); } } ``` -------------------------------- ### Get Link Flair Options Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches available link flair options for a subreddit via the JRAW library. This maps to the GET [/r/{subreddit}]/api/link_flair endpoint. ```Kotlin SubredditReference.linkFlairOptions() ``` -------------------------------- ### JSON Envelope Structure Example Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/internals.md An example of a JSON response containing an 'envelope' structure, where data is nested under a 'data' key and a 'kind' field indicates the type of data. This pattern is common in APIs like Reddit's. ```JSON { "kind": "", "data": { ... } } ``` -------------------------------- ### Authenticate Script/Application-Only App with JRAW Source: https://github.com/mattbdean/jraw/wiki/OAuth2 Demonstrates how to authenticate a script or application-only app using JRAW's `easyAuth` method. This requires a `Credentials` object and results in an `OAuthData` instance for authentication. ```Java RedditClient redditClient = new RedditClient(...); // This could also be Credentials.userless() or .userlessApp() Credentials credentials = Credentials.script(...); OAuthData authData = redditClient.getOAuthHelper().easyAuth(credentials); redditClient.authenticate(authData); ``` -------------------------------- ### Iterate Specific Multireddit Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Demonstrates how to iterate through the submissions within a specific multireddit using JRAW. This allows fetching content aggregated by a multireddit. ```Java /* Example for iterating a specific multireddit */ // Assuming 'reddit' is an authenticated JRAW instance and 'multiredditName' is the name of the multireddit Multireddit multireddit = reddit.getMultireddit("multiredditName"); for (Submission submission : multireddit.hot()) { System.out.println(submission.getTitle()); } ``` -------------------------------- ### Iterate Inbox Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Shows how to iterate through a user's inbox messages using JRAW. This requires the user to be logged in. ```Java /* Example for iterating the inbox */ // Assuming 'reddit' is an authenticated JRAW instance User user = reddit.me(); for (Message message : user.getInbox()) { System.out.println(message.getSubject()); } ``` -------------------------------- ### Get Wiki Pages - JRAW Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves a list of all wiki pages for a given subreddit using the JRAW library. This method corresponds to the GET /r/{subreddit}/wiki/pages API endpoint. ```kotlin val wikiReference = redditClient.subreddit("someSubreddit").wiki() val pages = wikiReference.pages() ``` -------------------------------- ### Get Multireddit Subreddit Info Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches information about a subreddit within a multireddit using the GET /api/multi/{multipath}/r/{srname} endpoint. The `subredditInfo()` method in `MultiredditReference` handles this. ```Kotlin MultiredditReference.subredditInfo() ``` -------------------------------- ### Get Specific Wiki Page Content - JRAW Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches the content of a specific wiki page for a given subreddit. This method, page(), corresponds to the GET /r/{subreddit}/wiki/{page} API endpoint in the Reddit API. ```kotlin val wikiReference = redditClient.subreddit("someSubreddit").wiki() val pageContent = wikiReference.page("wikiPageName") ``` -------------------------------- ### Traverse Comment Tree Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Demonstrates how to traverse the comment tree of a specific submission using JRAW. This allows for exploring nested comments. ```Java /* Example for traversing a comment tree */ // Assuming 'reddit' is an authenticated JRAW instance and 'submission' is a Submission object for (Comment comment : submission.comments()) { System.out.println(comment.getBody()); // Further traversal logic for replies can be added here } ``` -------------------------------- ### Table of Contents Configuration Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Example of the toc.json file structure used to define the table of contents for the JRAW documentation. It specifies the markdown files and their display titles. ```json [ { "file": "foo" }, { "file": "bar", "title": "Something else" } ] ``` -------------------------------- ### Get Happening Now Live Thread Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/live_threads.md Retrieves information about a live thread that Reddit is currently featuring for a prominent event. ```Java LiveThreads.happeningNow ``` -------------------------------- ### Get Subreddit Wiki Pages Source: https://github.com/mattbdean/jraw/wiki/Fluent-API Shows how to retrieve a list of wiki page titles for a given subreddit using the fluent API. ```Java List wikiPages = fluent.subreddit("pics").wiki().pages(); ``` -------------------------------- ### Concurrently Run Gradle and GitBook for JRAW Docs Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Uses the 'concurrently' tool to run both the Gradle continuous build and the GitBook live-reloading server in a single terminal. This simplifies the development setup by managing multiple processes simultaneously. ```sh concurrently -r -k "./gradlew -t :docs:buildSite" "cd docs/build/docs && gitbook install && gitbook serve --watch" ``` -------------------------------- ### Get Live Thread by ID Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/live_threads.md Shows how to create a reference to an existing live thread using its unique identifier. ```Java LiveThreads.byId ``` -------------------------------- ### Get Live Thread About Information (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves general information about a live thread, such as its description and rules, using JRAW. This is handled by the LiveThreadReference class and maps to the Reddit API's GET /live/{thread}/about endpoint. ```Java LiveThreadReference.about() ``` -------------------------------- ### Mark Messages as Read/Unread Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Demonstrates how to mark messages in the user's inbox as read or unread using JRAW. This requires user authentication. ```Java /* Example for marking messages as read/unread */ // Assuming 'reddit' is an authenticated JRAW instance and 'message' is a Message object // Mark as read message.markRead(); // Mark as unread message.markUnread(); ``` -------------------------------- ### Interactive OAuth2 Authentication Flow in JRAW Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/oauth2.md Illustrates the steps involved in interactive authentication for installed and web applications. This includes generating an authorization URL, redirecting the user, and requesting an access token upon user approval. ```Java String authorizationUrl = OAuth2.getAuthorizationUrl("your_client_id", "your_redirect_uri", "your_scope"); // Direct user to authorizationUrl // Handle redirect and obtain authorization code RedditClient reddit = OAuth2.interactive("your_client_id", "your_client_secret", "your_redirect_uri", "your_authorization_code"); ``` -------------------------------- ### Get Front Page Submissions Source: https://github.com/mattbdean/jraw/wiki/Cookbook This code retrieves submissions from the Reddit front page using JRAW's Paginator. It shows how to initialize a Paginator and iterate through the first page of results. ```Java SubredditPaginator paginator = new SubredditPaginator(redditClient); Listing firstPage = paginator.next(); for (Submission submission : firstPage) { // do something } ``` -------------------------------- ### Build JRAW Documentation Site Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Builds the JRAW documentation site using Gradle and then serves it locally using gitbook serve. This command is used for previewing the documentation. ```shell ./gradlew :docs:buildSite cd docs/build/docs && gitbook serve ``` -------------------------------- ### Send Private Message as Subreddit Moderator Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/cookbook.md Shows how to send a private message to a user acting as a subreddit moderator using JRAW. This requires moderator privileges. ```Java /* Example for sending a private message as a moderator */ // Assuming 'reddit' is an authenticated JRAW instance and 'subreddit' is a Subreddit object subreddit.modMail("recipientUsername", "Subject", "Message body"); ``` -------------------------------- ### Ignore Live By ID Endpoint Source: https://github.com/mattbdean/jraw/blob/master/meta/src/main/resources/not_planned.txt Documents the GET request for the /api/live/by_id/{names} endpoint. This method is excluded due to past issues, and it's uncertain if these problems persist. ```Java GET /api/live/by_id/{names} ``` -------------------------------- ### Ignore User Data Endpoint Source: https://github.com/mattbdean/jraw/blob/master/meta/src/main/resources/not_planned.txt Documents the GET request for the /api/user_data_by_account_ids endpoint. The reason for exclusion is that the functionality of this endpoint is unknown and its use is unclear. ```Java GET /api/user_data_by_account_ids ``` -------------------------------- ### Initialize FluentRedditClient Source: https://github.com/mattbdean/jraw/wiki/Fluent-API Demonstrates how to create an instance of FluentRedditClient, which requires an already authenticated RedditClient instance. ```Java FluentRedditClient fluent = new FluentRedditClient(redditClient); ``` -------------------------------- ### Traverse Comment Tree Source: https://github.com/mattbdean/jraw/wiki/Cookbook This snippet illustrates how to traverse a comment tree using JRAW's CommentNode. It shows how to get the root node and iterate through all comments using walkTree(). ```Java CommentNode rootNode = submission.getComments(); Iterable iterable = rootNode.walkTree(); for (CommentNode node : iterable) { // do something } ``` -------------------------------- ### JSON Response for User Data Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/internals.md A specific JSON response example for a user's profile information, including kind, verified status, gold status, and link karma. This illustrates the 'envelope' structure with 'kind': 't2' for account data. ```JSON { "kind": "t2", "data": { ... "verified": true, "is_gold": true, "link_karma": 357440, ... } } ``` -------------------------------- ### Check Method OAuth2 Scope Source: https://github.com/mattbdean/jraw/wiki/Cookbook This example explains how to determine the required OAuth2 scope for a Reddit API method using JRAW annotations. It shows how to find the scope associated with an endpoint. ```Java // Example: Checking scope for RedditClient.getSubmission() // The annotation value is Endpoints.COMMENTS_ARTICLE // Which corresponds to the 'read' scope. ``` -------------------------------- ### Initialize RedditClient Source: https://github.com/mattbdean/jraw/wiki/Quickstart This Java snippet shows the initialization of a RedditClient object using a previously created UserAgent. This client is the primary interface for interacting with the Reddit API. ```Java RedditClient redditClient = new RedditClient(myUserAgent); ``` -------------------------------- ### Push JRAW Documentation Site Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Command to push the generated JRAW documentation site to GitBook using Gradle. This command requires the authentication properties to be set. ```shell ./gradlew :docs:pushSite ``` -------------------------------- ### Ignore Search Reddit Names Endpoints Source: https://github.com/mattbdean/jraw/blob/master/meta/src/main/resources/not_planned.txt This snippet covers both GET and POST requests for the /api/search_reddit_names endpoint. These are excluded because they perform the same function, differing only in their HTTP verbs, as noted in issue #243. ```Java GET /api/search_reddit_names ``` ```Java POST /api/search_reddit_names ``` -------------------------------- ### Get Flair Selector Options Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves options for flair selection within a subreddit using JRAW. This method corresponds to the POST [/r/{subreddit}]/api/flairselector endpoint. ```Kotlin UserFlairReference.current() ``` -------------------------------- ### Subscribe to a Subreddit Source: https://github.com/mattbdean/jraw/wiki/Fluent-API Illustrates the process of subscribing to a subreddit using the fluent API. ```Java fluent.subreddit("pics").subscribe(); ``` -------------------------------- ### Get Multireddit Information Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches details about a specific multireddit using the GET /api/multi/{multipath} endpoint. The `about()` method in `MultiredditReference` provides this functionality. ```Kotlin MultiredditReference.about() ``` -------------------------------- ### JRAW Pagination with All Options Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/pagination.md Illustrates how to configure a JRAW Paginator with various options, including limit, sorting, and time period, for customized data retrieval. ```Java Listing posts = new DefaultPaginator(reddit, Target.subreddit("java")) .limit(100) .sorting(Sorting.TOP) .timePeriod(TimePeriod.DAY) .build() .next(); ``` -------------------------------- ### Get User Trophies Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves a user's trophies using the GET /api/v1/user/{username}/trophies endpoint. This is implemented by the `trophies()` method in `UserReference`. ```Kotlin UserReference.trophies() ``` -------------------------------- ### Get Submission Comments Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches comments for a specific submission using the GET [/r/{subreddit}]/comments/{article} endpoint. The `comments()` method in `SubmissionReference` handles this. ```Kotlin SubmissionReference.comments() ``` -------------------------------- ### Authenticate RedditClient with Script Credentials Source: https://github.com/mattbdean/jraw/wiki/Quickstart This Java code demonstrates the authentication process for the RedditClient using script application credentials. It involves creating a Credentials object and using OAuthHelper for easy authentication. ```Java Credentials credentials = Credentials.script("", "", "", ""); OAuthData authData = redditClient.getOAuthHelper().easyAuth(credentials); redditClient.authenticate(authData); ``` -------------------------------- ### Get User Flair Options Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves user flair options for a subreddit through the JRAW library. This functionality is linked to the GET [/r/{subreddit}]/api/user_flair endpoint. ```Kotlin SubredditReference.userFlairOptions() ``` -------------------------------- ### Add JRAW Dependency with Gradle Source: https://github.com/mattbdean/jraw/wiki/Quickstart This snippet shows how to add the JRAW library as a dependency in a Gradle project by configuring repositories and dependencies. ```Groovy repositories { jcenter() } dependencies { compile "net.dean.jraw:JRAW:$jrawVersion" } ``` -------------------------------- ### GitBook Authentication Properties Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Configuration for pushing the JRAW documentation site to GitBook. Requires a gitbookUsername and gitbookPassword (access token) to be set in the gradle.properties file. ```properties gitbookUsername= gitbookPassword= ``` -------------------------------- ### Create User-Agent for Reddit API Source: https://github.com/mattbdean/jraw/wiki/Quickstart This Java code illustrates how to create a UserAgent object, which is crucial for making authenticated requests to the Reddit API. It includes platform, package, version, and username. ```Java UserAgent myUserAgent = UserAgent.of("desktop", "net.dean.awesomescript", "v0.1", "thatJavaNerd"); ``` -------------------------------- ### List User's Multireddits Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves a list of multireddits created by a specific user. This can be done via the GET /api/multi/mine or GET /api/multi/user/{username} endpoints. The implementation is in `UserReference.listMultis()`. ```Kotlin UserReference.listMultis() ``` -------------------------------- ### Add JRAW Dependency with Maven Source: https://github.com/mattbdean/jraw/wiki/Quickstart This snippet demonstrates how to add the JRAW library to a Maven project's pom.xml, including repository configuration and dependency declaration. ```XML net.dean.jraw JRAW ${jraw.version} ``` -------------------------------- ### Get Wiki Revisions - JRAW Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches the revision history for all wiki pages within a subreddit. This functionality maps to the GET /r/{subreddit}/wiki/revisions API endpoint and is handled by the revisions() method in JRAW. ```kotlin val wikiReference = redditClient.subreddit("someSubreddit").wiki() val revisions = wikiReference.revisions() ``` -------------------------------- ### Get User Subreddits (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches a list of subreddits a user has subscribed to or interacted with using JRAW. This method is part of the RedditClient class and maps to the Reddit API's GET /users/{where} endpoint. ```Java RedditClient.userSubreddits() ``` -------------------------------- ### Get Random Subreddit (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves a random subreddit using the JRAW library. This method is part of the RedditClient class and utilizes the Reddit API's GET /r/{subreddit}/random endpoint. ```Java RedditClient.randomSubreddit() ``` -------------------------------- ### Run Gradle Tests (Shell) Source: https://github.com/mattbdean/jraw/blob/master/README.md This command executes the tests for the project using Gradle. It's a standard way to run the test suite after setting up the environment and credentials. ```Shell $ ./gradlew test ``` -------------------------------- ### Get Rising Posts from Subreddit (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches the 'rising' posts from a subreddit using JRAW. This method is part of the SubredditReference class and corresponds to the Reddit API's GET /r/{subreddit}/rising endpoint. ```Java SubredditReference.posts() ``` -------------------------------- ### Get Subreddit Rules (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches the rules of a specific subreddit using the JRAW library. This functionality is provided by the SubredditReference class and interacts with the Reddit API's GET /r/{subreddit}/about/rules endpoint. ```Java SubredditReference.rules() ``` -------------------------------- ### Multiple Code Samples and Links in Markdown Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Illustrates the correct way to include multiple code samples and documentation links on separate lines within a Markdown file. Mixing multiple samples on a single line is not allowed. ```markdown {{ @Example.showSomething }} {{ @Example.doSomething }} Lorem ipsum [[@RedditClient]] dolor [[@Paginator]] sit amet. ``` -------------------------------- ### Generated Summary File Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Shows the structure of the SUMMARY.md file generated by GitBook, which is used to create the sidebar navigation for the documentation. ```markdown # Summary * [Foo](foo.md) * [Something else](bar.md) ``` -------------------------------- ### Configure Release Variables (Properties) Source: https://github.com/mattbdean/jraw/blob/master/README.md This properties file snippet shows how to define variables required for releasing the project, including GitBook and Bintray API keys and usernames. ```Properties # Go to gitbook.com -> Account Settings -> Applications/Tokens to get an API key gitbookUsername= gitbookPassword= # Go to bintray.com -> Edit Profile -> API Key to get your account's API key bintrayUser= bintrayKey= # If this property doesn't match the target release, all release-related tasks ``` -------------------------------- ### Get Specific Wiki Page Revisions - JRAW Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves the revision history for a specific wiki page within a subreddit. This is achieved using the revisionsFor() method, which corresponds to the GET /r/{subreddit}/wiki/revisions/{page} API endpoint. ```kotlin val wikiReference = redditClient.subreddit("someSubreddit").wiki() val pageRevisions = wikiReference.revisionsFor("wikiPageName") ``` -------------------------------- ### Get User About Information (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves information about a Reddit user, such as their karma and creation date, using JRAW. This method is part of the UserReference class and corresponds to the Reddit API's GET /user/{username}/about endpoint. ```Java UserReference.query() ``` -------------------------------- ### Get Subreddit About Information (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves information about a subreddit, including its description and subscriber count, using JRAW. This method belongs to the SubredditReference class and corresponds to the Reddit API's GET /r/{subreddit}/about endpoint. ```Java SubredditReference.about() ``` -------------------------------- ### Create Live Thread Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/live_threads.md Demonstrates how to create a new live thread on Reddit. This typically requires specific user karma thresholds. ```Java LiveThreads.create ``` -------------------------------- ### Get New Posts from Subreddit (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches the 'new' posts from a given subreddit via the JRAW library. This method is part of the SubredditReference class and uses the Reddit API's GET /r/{subreddit}/new endpoint. ```Java SubredditReference.posts() ``` -------------------------------- ### Submit a Link to a Subreddit Source: https://github.com/mattbdean/jraw/wiki/Fluent-API Demonstrates how to submit a link to a specific subreddit with a title, using the fluent API. ```Java Submission submission = fluent.subreddit("programming") .submit("https://github.com/thatJavaNerd/JRAW", "A pretty cool reddit API wrapper"); ``` -------------------------------- ### Get Latest Updates for Live Thread (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches the latest updates for a live thread from Reddit using JRAW. This functionality is provided by the LiveThreadReference class and corresponds to the Reddit API's GET /live/{thread} endpoint. ```Java LiveThreadReference.latestUpdates() ``` -------------------------------- ### Include JRAW Code Sample in Markdown Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Shows the syntax for embedding a JRAW code sample within a Markdown file using the {{ @ClassName.methodName }} format. This is compiled into the actual code. ```markdown {{ @Example.showSomething }} ``` -------------------------------- ### Get Hot Posts from Subreddit (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves the 'hot' posts from a specified subreddit using the JRAW library. This method is part of the SubredditReference class and interacts with the Reddit API's GET /r/{subreddit}/hot endpoint. ```Java SubredditReference.posts() ``` -------------------------------- ### Generate Credentials (Shell) Source: https://github.com/mattbdean/jraw/blob/master/README.md This shell command uses Gradle to automatically generate the necessary credentials file for testing. It requires the Gradle wrapper and the `--no-daemon` and `--console plain` flags for execution. ```Shell $ ./gradlew :meta:credentials --no-daemon --console plain ``` -------------------------------- ### Get Posts by Sort Order (Java) Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves posts from a subreddit sorted by various criteria (e.g., controversial, top) using JRAW. This method is part of the SubredditReference class and utilizes the Reddit API's GET /r/{subreddit}/{sort} endpoint. ```Java SubredditReference.posts() ``` -------------------------------- ### Get Flair List Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves the list of flairs for a subreddit. This functionality is available through the SubredditReference class. ```Kotlin SubredditReference.flairList() ``` -------------------------------- ### JRAW Code Sample Annotation Source: https://github.com/mattbdean/jraw/blob/master/docs/README.md Demonstrates how to use the @CodeSample annotation in Java to mark methods that should be extracted as code samples for documentation. Methods without this annotation are ignored. ```java final class Example { @CodeSample void showSomething() { String x = "foo"; System.out.println(x); } @CodeSample void doSomething() { int y = 10; int x = 4; int z = x * y; } void ignored() { // This doesn't have the @CodeSample annotation so it gets ignored } } ``` -------------------------------- ### Get Subreddit Stylesheet - Kotlin Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves the current stylesheet for a subreddit. This function is available within the SubredditReference class. ```Kotlin SubredditReference.stylesheet() ``` -------------------------------- ### Java: Enable HttpLogger Component Source: https://github.com/mattbdean/jraw/wiki/Logging Shows how to enable a specific component for logging within JRAW's HttpLogger. Components define what parts of an HTTP request or response are logged. ```Java httpLogger.enable(HttpLogger.Component.REQUEST_HEADERS); ``` ```Java httpLogger.enable(HttpLogger.Component.RESPONSE_HEADERS); ``` -------------------------------- ### Create a New RateLimiter Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/ratelimiting.md Demonstrates how to create a new RateLimiter instance. This is a core component for managing API request rates. ```Java Ratelimiting.newRateLimiter ``` -------------------------------- ### Live Thread WebSockets Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/live_threads.md Explains the use of WebSockets for live threads, enabling real-time notifications for updates instead of traditional polling methods. ```Java LiveThreads.websocket ``` -------------------------------- ### Get User Trophies Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches the trophies associated with a specific Reddit user. This function requires the username to identify the user. ```Kotlin UserReference.trophies() ``` -------------------------------- ### Initialize JRAW AccountHelper in Android Application Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/android.md This Java code illustrates the onCreate method for an Android Application class. It shows how to initialize the AccountHelper using ManifestAppInfoProvider, a unique device UUID, and a SharedPreferencesTokenStore for managing Reddit API authentication tokens. ```java public final class App extends Application { private static AccountHelper accountHelper; private static SharedPreferencesTokenStore tokenStore; @Override public void onCreate() { super.onCreate(); // Get UserAgent and OAuth2 data from AndroidManifest.xml AppInfoProvider provider = new ManifestAppInfoProvider(getApplicationContext()); // Ideally, this should be unique to every device UUID deviceUuid = UUID.randomUUID(); // Store our access tokens and refresh tokens in shared preferences tokenStore = new SharedPreferencesTokenStore(getApplicationContext()); // Load stored tokens into memory tokenStore.load(); // Automatically save new tokens as they arrive tokenStore.setAutoPersist(true); // An AccountHelper manages switching between accounts and into/out of userless mode. accountHelper = AndroidHelper.accountHelper(provider, deviceUuid, tokenStore); // Every time we use the AccountHelper to switch between accounts (from one account to // another, or into/out of userless mode), call this function accountHelper.onSwitch(redditClient -> { // By default, JRAW logs HTTP activity to System.out. We're going to use Log.i() // instead. LogAdapter logAdapter = new SimpleAndroidLogAdapter(Log.INFO); // We're going to use the LogAdapter to write down the summaries produced by // SimpleHttpLogger redditClient.setLogger( new SimpleHttpLogger(SimpleHttpLogger.DEFAULT_LINE_LENGTH, logAdapter)); // If you want to disable logging, use a NoopHttpLogger instead: // redditClient.setLogger(new NoopHttpLogger()); return null; }); } public static AccountHelper getAccountHelper() { return accountHelper; } public static SharedPreferencesTokenStore getTokenStore() { return tokenStore; } } ``` -------------------------------- ### Ignore Store Visits Endpoint (Requires Gold) Source: https://github.com/mattbdean/jraw/blob/master/meta/src/main/resources/not_planned.txt This documentation covers the POST request for the /api/store_visits endpoint. This method requires Reddit Gold and is not planned for implementation. ```Java POST /api/store_visits ``` -------------------------------- ### Get User Preferences Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Retrieves the preferences of the currently authenticated user. This endpoint is part of the user's settings and requires authentication. ```Kotlin SelfUserReference.prefs() ``` -------------------------------- ### MarkdownGenerator for ENDPOINTS.md Source: https://github.com/mattbdean/jraw/wiki/Endpoints The MarkdownGenerator generates the ENDPOINTS.md file. This file serves as documentation for the available endpoints, likely listing their URIs, parameters, and descriptions in a human-readable Markdown format. ```Markdown ``` -------------------------------- ### Iterate Subreddit Submissions with JRAW Paginator Source: https://github.com/mattbdean/jraw/wiki/Paginators This code demonstrates how to use the SubredditPaginator class to iterate through submissions on the front page or a subreddit using JRAW. It initializes a RedditClient, configures the SubredditPaginator with parameters like limit, time period, and sorting, and then iterates through the submissions, printing basic statistics. ```java RedditClient reddit = new RedditClient(UserAgent.of(...)); SubredditPaginator frontPage = new SubredditPaginator(reddit); // Adjust the request parameters frontPage.setLimit(50); // Default is 25 (Paginator.DEFAULT_LIMIT) frontPage.setTimePeriod(TimePeriod.MONTH); // Default is DAY (Paginator.DEFAULT_TIME_PERIOD) frontPage.setSorting(Sorting.TOP); // Default is HOT (Paginator.DEFAULT_SORTING) // This Paginator is now set up to retrieve the highest-scoring links submitted within the past // month, 50 at a time // Since Paginator implements Iterator, you can use it just how you would expect to, using next() and hasNext() Listing submissions = frontPage.next(); for (Submission s : submissions) { // Print some basic stats about the posts System.out.printf("[/r/%s - %s karma] %s\n", s.getSubredditName(), s.getScore(), s.getTitle()); } ``` -------------------------------- ### Post Update to Live Thread Source: https://github.com/mattbdean/jraw/blob/master/docs/src/main/resources/content/live_threads.md Provides instructions on how to post a new update to an existing live thread. Approved contributors can post updates. ```Java LiveThreads.postUpdate ``` -------------------------------- ### Ignore Captcha Endpoint Source: https://github.com/mattbdean/jraw/blob/master/meta/src/main/resources/not_planned.txt This section documents the GET request for the /api/needs_captcha endpoint, which is not planned for implementation in JRAW. No specific reasons are provided for its exclusion. ```Java GET /api/needs_captcha ``` -------------------------------- ### Login to Reddit API Source: https://github.com/mattbdean/jraw/wiki/Cookbook This snippet demonstrates how to log in to the Reddit API using JRAW. It assumes the client has been authenticated and the necessary scopes have been requested. ```Java LoggedInAccount me = redditClient.me(); ``` -------------------------------- ### Get User Subreddits with JRAW Source: https://github.com/mattbdean/jraw/blob/master/ENDPOINTS.md Fetches a list of the current user's subreddits. This method corresponds to the '/subreddits/mine/{where}' endpoint in the Reddit API. ```Kotlin SelfUserReference.subreddits() ```