Skip to content
Redd is a batteries-included API wrapper for reddit.
Branch: master
Clone or download
scragz and avinashbot if access is a string then use it directly
fixes "undefined local variable or method `refresh_token'"
pretty sure this was a typo?
Latest commit 3b1519a Nov 2, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Have console script store the key permanently in /home/avinash/.redd.key Oct 4, 2017
docs Add a test documentation page (in progress). Oct 6, 2017
lib if access is a string then use it directly Nov 2, 2017
spec Remove non-lazy_lazer tests. Should close #67. Oct 4, 2017
www Add a test documentation page (in progress). Oct 6, 2017
.gitignore Improve and update tests. Mar 12, 2017
.hound.yml Make Hound CI use project's .rubocop.yml. Mar 11, 2017
.rspec Improve and update tests. Mar 12, 2017
.rubocop.yml Get user fully working. Oct 4, 2017
.travis.yml Improve and update tests. Mar 12, 2017
CONTRIBUTING.md Fix link [skip ci] Aug 20, 2017
Gemfile First Commit 🎉 Feb 23, 2017
Guardfile Assimilate changes made over the past few months. Oct 4, 2017
LICENSE.txt First Commit 🎉 Feb 23, 2017
README.md Wipe old stream method. Oct 4, 2017
Rakefile Get user fully working. Oct 4, 2017
TODO.md Add additional calls. Oct 4, 2017
logo.png
redd.gemspec Change DeleteNegative to DeleteBadlyScoring. Oct 4, 2017

README.md


Gem Version Build Status Gem Downloads

Redd is a batteries-included API wrapper for reddit.


Features

  • Supports most of the reddit API, including live threads and the beta mod-mail.
  • Includes support for streaming new posts and comments.
  • Built-in rate limiting and error handling.
  • Automatic retrying of failed requests.

Demo

Reddit Bot

require 'redd'

session = Redd.it(
  user_agent: 'Redd:RandomBot:v1.0.0 (by /u/Mustermind)',
  client_id:  'PQgS0UaX9l70oQ',
  secret:     'PsF_kVZrW8nSVCG5kNsIgl-AaXE',
  username:   'RandomBot',
  password:   'hunter2'
)

session.subreddit('all').comments.stream do |comment|
  if comment.body.include?('roll a dice')
    comment.reply("It's a #{rand(1..6)}!")
  elsif comment.body.include?('flip a coin')
    comment.reply("It's a #{%w(heads tails).sample}!")
  end
end

Web Application

require 'sinatra'
require 'redd/middleware'

use Rack::Session::Cookie
use Redd::Middleware,
    user_agent:   'Redd:Username App:v1.0.0 (by /u/Mustermind)',
    client_id:    'PQgS0UaX9l70oQ',
    secret:       'PsF_kVZrW8nSVCG5kNsIgl-AaXE',
    redirect_uri: 'http://localhost:4567/auth/reddit/callback',
    scope:        %w(identity),
    via:          '/auth/reddit'

get '/' do
  reddit = request.env['redd.session']

  if reddit
    "Hello /u/#{reddit.me.name}! <a href='/logout'>Logout</a>"
  else
    "<a href='/auth/reddit'>Sign in with reddit</a>"
  end
end

get '/auth/reddit/callback' do
  redirect to('/') unless request.env['redd.error']
  "Error: #{request.env['redd.error'].message} (<a href='/'>Back</a>)"
end

get '/logout' do
  request.env['redd.session'] = nil
  redirect to('/')
end

FAQ

Are those examples fully functional?

Yes, that's all there is to it! You don't need to handle rate-limiting, refresh access tokens or protect against issues on reddit's end (like 5xx errors).

Where can I find the documentation?

Gem / GitHub

Where can I ask for help if I'm having issues?

Check out the official subreddit or raise a GitHub issue.

How do I request a feature / contribute?

Take a look at CONTRIBUTING.md.

How can I contact you?

Reddit / Email


This project is available under the MIT License. See LICENSE.txt for more details.
The Redd logo uses the FARRAY font by Coquet Adrien.
You can’t perform that action at this time.