Project

wreddit

0.0
No commit activity in last 3 years
No release in over 3 years
Reddit has a built-in API with JSON requests. The WReddit class allows users to access the JSON data for quick applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 10.0
~> 3.0

Runtime

 Project Readme

WReddit: Reddit API wrapper for Ruby

wreddit

A Reddit API Wrapper built in Ruby to play with my own Gem. It really only helps you grab subreddit information and user information.

What makes this special?

It's utilizing Reddit's free API resources. That means you don't need any authorization to make requests. You can't make a lot of requests, but if you cache them using Redis, you could probably use this on a small toy app for yourself. It's a good way to quickly grab Reddit subreddits, comments, articles, and user profiles for your application.

Install

add this to your Gemfile:

gem 'wreddit'

run bundle install in your app

How to use

REDIS

This gem takes advantage of Redis caching which should help reduce the amount of error requests received by Reddit's Native API. You can't really make adjustments to the caching because caching is going to happen automatically. In order to use Redis, you MUST be running a redis-server to handle the hash maps of URLs and response objects.

As of v.1.0.2 we are using the Wreddit class.

Example of basic usage
    wreddit = Wreddit.new #wreddit will be a standard variable for future examples
    @reddit_user = wreddit.user('username').parse

user -> checks for a username on Reddit.com. If the user doesn't exist, their API handles that.
subreddit -> checks for subreddit. If left empty, it'll default to /r/all.
parse -> will parse the response in JSON format by default. If you'd like to parse XML or HTTP, you can do that like this:

...parse('xml') or parse('html') or parse('json')
Example of advanced usage

In this example, we'd be grabbing the subreddit and its comments in a specific thread

    @reddit_comments = wreddit.subreddit('learnprogramming').comments('specific_article_id').parse

If you just quickly want to get the links, titles, or descriptions for articles/comments, I made some snappy methods. You don't have to parse them. For now, it assumes that you want an array from the JSON object. Getting top links to articles in subreddit

    @reddit_links = wreddit.subreddit('learnprogramming').links

Getting top titles of articles in subreddit

    @reddit_titles  = wreddit.subreddit('learnprogramming').titles

Getting top descriptions of articles in subreddit

    @reddit_descriptions = wreddit.subreddit('learnprogramming').descriptions
Hazards

You cannot assume that any of these methods together will provide some response. Logically, some of these will render nil arrays. However, you'd be surprised by some things you can do. Like: In this example, we'd be grabbing the subreddit, its comments in a specific thread

    @stuff = wreddit.user('myusername').links #provides valid links to user submitted threads

    @stuff = wreddit.user('myusername').descriptions #provides valid descriptions to commments

But you would NOT be able to write something like:

    @invalid_response = wreddit.user('myusername').subreddit('learnprogramming').parse

The API will response with 404.

Email me with any questions at seanjhulse@gmail.com