Reddit Base

A minimal reddit API client for Ruby.

Motivation

Managing major versions of an API client can be tricky, especially when the API us unversioned, inconsistent and outside of your control.

This client library aims to provide minimal support for the reddit API, reducing the need for frequent breaking changes and to act as the backbone for more other higher-level API clients.

Installation

Via Rubygems:

gem install reddit-base

Or in your Gemfile with Bundler:

gem reddit-base

Basic Usage

Retrieve the JSON for a particular endpoint:

require 'reddit/base'

client = Reddit::Base::Client.new(user: USERNAME, password: PASSWORD)
client.get('/r/AskReddit')

Making a new self post:

require 'reddit/base'

client = Reddit::Base::Client.new(user: USERNAME, password: PASSWORD)
client.get('/r/AskReddit') # Need to make at least one GET request to retrieve a modhash.
client.post('/api/submit', kind: 'self', sr: SUBREDDIT, title: 'Hello,', text: 'World!')

Client#get and Client#post accept a simplify option to flatten data and kind attributes for easier traversal:

client.get('/r/AskReddit', simplify: true)

What it Does

  • Authentication.
  • Rate limiting.
  • Modhash handling (reddit's CSRF protection).
  • JSON coersion.
  • Forwarding..
  • Multipart POST.
  • Reddit error wrapping.

What it Doesn't

  • Parsing of Reddit "Things" and "Kinds."
  • Parsing of common attributes like dates and times.
  • HTML entity decoding (beware of "body" and "selftext").

Contributors

This project is copyright 2014 by its contributors, refer to LICENSE file for licensing information.