https://github.com/avinashbot/redd
Redd is a batteries-included API wrapper for reddit.
https://github.com/avinashbot/redd
api-wrapper bot oauth2 reddit ruby
Last synced: 9 months ago
JSON representation
Redd is a batteries-included API wrapper for reddit.
- Host: GitHub
- URL: https://github.com/avinashbot/redd
- Owner: avinashbot
- License: mit
- Created: 2014-07-30T08:17:44.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-05-12T19:14:53.000Z (over 2 years ago)
- Last Synced: 2024-10-30T03:43:05.414Z (about 1 year ago)
- Topics: api-wrapper, bot, oauth2, reddit, ruby
- Language: Ruby
- Homepage:
- Size: 1.55 MB
- Stars: 186
- Watchers: 12
- Forks: 75
- Open Issues: 35
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
README
---
### 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
```ruby
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
```ruby
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}! Logout"
else
"Sign in with reddit"
end
end
get '/auth/reddit/callback' do
redirect to('/') unless request.env['redd.error']
"Error: #{request.env['redd.error'].message} (Back)"
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**](http://www.rubydoc.info/gems/redd/Redd/Models/Session) / [**GitHub**](http://www.rubydoc.info/github/avinashbot/redd/master/Redd/Models/Session)
#### Where can I ask for help if I'm having issues?
Check out the [**official subreddit**](https://www.reddit.com/r/Redd) or raise a [**GitHub issue**](https://github.com/avinashbot/redd/issues/new).
#### How do I request a feature / contribute?
Take a look at [**CONTRIBUTING.md**](https://github.com/avinashbot/redd/blob/master/CONTRIBUTING.md).
#### How can I contact you?
[Reddit](https://www.reddit.com/message/compose/?to=Mustermind) /
[Email](mailto:avinash@dwarapu.me)
---
This project is available under the MIT License. See LICENSE.txt for more details.
The Redd logo uses the FARRAY font by Coquet Adrien.
