Git Product home page Git Product logo

wreddit's Introduction

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 [email protected]

wreddit's People

Contributors

seanjhulse avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.