spinels-redd 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/ci.yml +52 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.rubocop.yml +29 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +6 -0
- data/Guardfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +119 -0
- data/Rakefile +12 -0
- data/TODO.md +423 -0
- data/bin/console +127 -0
- data/bin/guard +2 -0
- data/bin/setup +8 -0
- data/docs/guides/.keep +0 -0
- data/docs/tutorials/creating-bots-with-redd.md +101 -0
- data/docs/tutorials/creating-webapps-with-redd.md +124 -0
- data/docs/tutorials/make-a-grammar-bot.md +5 -0
- data/docs/tutorials.md +7 -0
- data/lib/redd/api_client.rb +116 -0
- data/lib/redd/assist/delete_badly_scoring.rb +64 -0
- data/lib/redd/auth_strategies/auth_strategy.rb +68 -0
- data/lib/redd/auth_strategies/script.rb +35 -0
- data/lib/redd/auth_strategies/userless.rb +29 -0
- data/lib/redd/auth_strategies/web.rb +36 -0
- data/lib/redd/client.rb +91 -0
- data/lib/redd/errors.rb +65 -0
- data/lib/redd/middleware.rb +125 -0
- data/lib/redd/models/access.rb +54 -0
- data/lib/redd/models/comment.rb +229 -0
- data/lib/redd/models/front_page.rb +55 -0
- data/lib/redd/models/gildable.rb +13 -0
- data/lib/redd/models/inboxable.rb +33 -0
- data/lib/redd/models/listing.rb +52 -0
- data/lib/redd/models/live_thread.rb +133 -0
- data/lib/redd/models/live_update.rb +46 -0
- data/lib/redd/models/messageable.rb +20 -0
- data/lib/redd/models/mod_action.rb +59 -0
- data/lib/redd/models/model.rb +23 -0
- data/lib/redd/models/moderatable.rb +46 -0
- data/lib/redd/models/modmail.rb +61 -0
- data/lib/redd/models/modmail_conversation.rb +154 -0
- data/lib/redd/models/modmail_message.rb +35 -0
- data/lib/redd/models/more_comments.rb +96 -0
- data/lib/redd/models/multireddit.rb +104 -0
- data/lib/redd/models/paginated_listing.rb +124 -0
- data/lib/redd/models/postable.rb +83 -0
- data/lib/redd/models/private_message.rb +105 -0
- data/lib/redd/models/replyable.rb +16 -0
- data/lib/redd/models/reportable.rb +14 -0
- data/lib/redd/models/searchable.rb +35 -0
- data/lib/redd/models/self.rb +17 -0
- data/lib/redd/models/session.rb +198 -0
- data/lib/redd/models/submission.rb +405 -0
- data/lib/redd/models/subreddit.rb +670 -0
- data/lib/redd/models/trophy.rb +34 -0
- data/lib/redd/models/user.rb +239 -0
- data/lib/redd/models/wiki_page.rb +56 -0
- data/lib/redd/utilities/error_handler.rb +73 -0
- data/lib/redd/utilities/rate_limiter.rb +21 -0
- data/lib/redd/utilities/unmarshaller.rb +70 -0
- data/lib/redd/version.rb +5 -0
- data/lib/redd.rb +129 -0
- data/lib/spinels-redd.rb +3 -0
- data/logo.png +0 -0
- data/spinels-redd.gemspec +39 -0
- metadata +298 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '097e7d4ed4b2fb64354aaa5383205904e31f486335ad058dced128d5e90ebaf0'
|
4
|
+
data.tar.gz: 5e7232d3ab19e0f9d0513d92b8266d34110ea0b8c315b14c52b05e98968d1f5c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b4e42e6020f621a2d6190bc20ada4ac4974e4e3e6959b604bad9f59a65df1a6e0c86701c040daf664c8720c2989a83222edb65b65e5baa6cc12a525172a36d0
|
7
|
+
data.tar.gz: d5572740470f872ba55d66442a25f60be50bcc55a83357d99207589a38437a04954fd9b615021387898687b2810224cfc78fd2d8844ba3d226c6c0d4d6912fcf
|
@@ -0,0 +1,52 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
include:
|
15
|
+
- { ruby: 2.6.7 }
|
16
|
+
- { ruby: 2.7.3 }
|
17
|
+
- { ruby: 3.0.1 }
|
18
|
+
- { ruby: head, allow-failure: true }
|
19
|
+
- { ruby: jruby-9.3.4.0 }
|
20
|
+
- { ruby: jruby-head, allow-failure: true }
|
21
|
+
|
22
|
+
steps:
|
23
|
+
- name: Checkout code
|
24
|
+
uses: actions/checkout@v2
|
25
|
+
|
26
|
+
- name: Setup Ruby ${{ matrix.ruby }}
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby }}
|
30
|
+
bundler-cache: true
|
31
|
+
|
32
|
+
- name: Run tests
|
33
|
+
run: bundle exec rake
|
34
|
+
continue-on-error: ${{ matrix.allow-failure || false }}
|
35
|
+
|
36
|
+
install:
|
37
|
+
runs-on: ubuntu-latest
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout code
|
41
|
+
uses: actions/checkout@v2
|
42
|
+
|
43
|
+
- name: Setup Ruby
|
44
|
+
uses: ruby/setup-ruby@v1
|
45
|
+
with:
|
46
|
+
ruby-version: '3.0.1'
|
47
|
+
|
48
|
+
- name: Build gem
|
49
|
+
run: gem build spinels-redd
|
50
|
+
|
51
|
+
- name: Install gem
|
52
|
+
run: gem install *.gem
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Metrics/LineLength:
|
6
|
+
Max: 100
|
7
|
+
|
8
|
+
Style/MutableConstant:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
# Dumb, but also brand new.
|
12
|
+
Style/NumericPredicate:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
# Allows for raising Redd::ResponseErrors with a Response object.
|
16
|
+
Style/RaiseArgs:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
# Many reddit calls demand a lot of parameters.
|
20
|
+
Metrics/ParameterLists:
|
21
|
+
CountKeywordArgs: false
|
22
|
+
|
23
|
+
# Stop rubocop from complaining about large `describe` blocks.
|
24
|
+
Metrics/BlockLength:
|
25
|
+
Exclude:
|
26
|
+
- spec/**/*_spec.rb
|
27
|
+
|
28
|
+
Naming/FileName:
|
29
|
+
Enabled: false
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
This is the documentation that contains information on contributing to Redd.
|
4
|
+
Note that I would appreciate contributions to this document itself.
|
5
|
+
|
6
|
+
There isn't an official code of conduct, just
|
7
|
+
[don't be a dick](https://twitter.com/wilw/status/5966220832).
|
8
|
+
|
9
|
+
### Filing an Issue / Making a Pull Request
|
10
|
+
|
11
|
+
**The quickest way to get a feature into Redd is by raising an issue.**
|
12
|
+
|
13
|
+
Please try to provide as much information as possible when submitting an
|
14
|
+
issue. I'm not going to get mad if the issue is inconsequential, so don't
|
15
|
+
hesitate to ask even simple questions about the gem.
|
16
|
+
|
17
|
+
When making a pull request, you don't really have to write tests for the
|
18
|
+
time being (what a relief for you!). Just make sure you have manually tested
|
19
|
+
the call yourself and rubocop doesn't whine about it too much.
|
20
|
+
|
21
|
+
### Architecture
|
22
|
+
The central part of the gem is the `Client`. It knows how to make HTTP
|
23
|
+
requests. For specific reddit behaviour, there is a subclass named
|
24
|
+
`APIClient`. Keep in mind that neither of these are actually aware of the API
|
25
|
+
methods, just how to interact with the API.
|
26
|
+
|
27
|
+
To simplify the architecture as much as humanly possible, everything is
|
28
|
+
represented as a model. A model holds a client and some attributes. It has
|
29
|
+
some methods that make API requests using the client and maybe some of its
|
30
|
+
attributes.
|
31
|
+
|
32
|
+
Each authentication method has an `AuthStrategy` associated with it. This only
|
33
|
+
provides API keys and is aware of the OAuth2 protocol.
|
34
|
+
|
35
|
+
The `Redd.it` method combines all of these:
|
36
|
+
|
37
|
+
1. It creates an `AuthStrategy`.
|
38
|
+
2. It creates an `APIClient` using the `AuthStrategy`.
|
39
|
+
3. It creates a `Session` model using the `APIClient`.
|
40
|
+
4. It returns the created `Session`.
|
41
|
+
|
42
|
+
This seems complicated but trust me on this, this gem has gone through three
|
43
|
+
rewrites.
|
44
|
+
|
45
|
+
### Reddit API
|
46
|
+
|
47
|
+
Here are some links where you can find helpful information about the reddit
|
48
|
+
API:
|
49
|
+
|
50
|
+
1. [API reference](https://www.reddit.com/dev/api)
|
51
|
+
2. [GitHub Wiki](https://github.com/reddit/reddit/wiki/API)
|
52
|
+
3. [API Subreddit](https://www.reddit.com/r/redditdev)
|
53
|
+
|
54
|
+
### Testing
|
55
|
+
|
56
|
+
Unit testing has turned out to be ultimately pointless; the API is a total
|
57
|
+
mess and requires a deep knowledge of how reddit works. Testing the multitude
|
58
|
+
of parameters that each call takes, it's safe to assume individual unit tests
|
59
|
+
will span a few thousand lines and be incredibly brittle. So when you submit a
|
60
|
+
pull-request, I expect you to have *manually tested the calls yourself*.
|
61
|
+
|
62
|
+
To help you, there is a console that can be found at `./bin/console`. Give it
|
63
|
+
a shot — I think you'll love it!
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Avinash Dwarapu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
<div align="center">
|
2
|
+
<p>
|
3
|
+
<!-- Redd -->
|
4
|
+
<img src="https://raw.githubusercontent.com/avinashbot/redd/master/logo.png" width="500"><br>
|
5
|
+
<!-- Badges -->
|
6
|
+
<a href="https://rubygems.org/gems/redd">
|
7
|
+
<img src="http://img.shields.io/gem/v/redd.svg?style=flat-square" alt="Gem Version">
|
8
|
+
</a>
|
9
|
+
<a href="https://github.com/spinels/redd/actions?query=workflow%3ACI">
|
10
|
+
<img src="https://github.com/spinels/redd/workflows/CI/badge.svg?branch=master" alt="Build Status">
|
11
|
+
</a>
|
12
|
+
<a href="https://rubygems.org/gems/redd">
|
13
|
+
<img src="http://img.shields.io/gem/dt/redd.svg?style=flat-square" alt="Gem Downloads">
|
14
|
+
</a>
|
15
|
+
</p>
|
16
|
+
<!-- Intro Text -->
|
17
|
+
<p>
|
18
|
+
<strong>Redd</strong> is a <strong>batteries-included</strong>
|
19
|
+
API wrapper for <a href="https://www.reddit.com/dev/api">reddit</a>.
|
20
|
+
</p>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
---
|
24
|
+
|
25
|
+
### Features
|
26
|
+
|
27
|
+
- Supports most of the reddit API, including live threads and the beta mod-mail.
|
28
|
+
- Includes support for streaming new posts and comments.
|
29
|
+
- Built-in rate limiting and error handling.
|
30
|
+
- Automatic retrying of failed requests.
|
31
|
+
|
32
|
+
### Demo
|
33
|
+
|
34
|
+
#### Reddit Bot
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'redd'
|
38
|
+
|
39
|
+
session = Redd.it(
|
40
|
+
user_agent: 'Redd:RandomBot:v1.0.0 (by /u/Mustermind)',
|
41
|
+
client_id: 'PQgS0UaX9l70oQ',
|
42
|
+
secret: 'PsF_kVZrW8nSVCG5kNsIgl-AaXE',
|
43
|
+
username: 'RandomBot',
|
44
|
+
password: 'hunter2'
|
45
|
+
)
|
46
|
+
|
47
|
+
session.subreddit('all').comments.stream do |comment|
|
48
|
+
if comment.body.include?('roll a dice')
|
49
|
+
comment.reply("It's a #{rand(1..6)}!")
|
50
|
+
elsif comment.body.include?('flip a coin')
|
51
|
+
comment.reply("It's a #{%w(heads tails).sample}!")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
#### Web Application
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'sinatra'
|
60
|
+
require 'redd/middleware'
|
61
|
+
|
62
|
+
use Rack::Session::Cookie
|
63
|
+
use Redd::Middleware,
|
64
|
+
user_agent: 'Redd:Username App:v1.0.0 (by /u/Mustermind)',
|
65
|
+
client_id: 'PQgS0UaX9l70oQ',
|
66
|
+
secret: 'PsF_kVZrW8nSVCG5kNsIgl-AaXE',
|
67
|
+
redirect_uri: 'http://localhost:4567/auth/reddit/callback',
|
68
|
+
scope: %w(identity),
|
69
|
+
via: '/auth/reddit'
|
70
|
+
|
71
|
+
get '/' do
|
72
|
+
reddit = request.env['redd.session']
|
73
|
+
|
74
|
+
if reddit
|
75
|
+
"Hello /u/#{reddit.me.name}! <a href='/logout'>Logout</a>"
|
76
|
+
else
|
77
|
+
"<a href='/auth/reddit'>Sign in with reddit</a>"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
get '/auth/reddit/callback' do
|
82
|
+
redirect to('/') unless request.env['redd.error']
|
83
|
+
"Error: #{request.env['redd.error'].message} (<a href='/'>Back</a>)"
|
84
|
+
end
|
85
|
+
|
86
|
+
get '/logout' do
|
87
|
+
request.env['redd.session'] = nil
|
88
|
+
redirect to('/')
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
### FAQ
|
93
|
+
|
94
|
+
#### Are those examples fully functional?
|
95
|
+
**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).
|
96
|
+
|
97
|
+
#### Where can I find the documentation?
|
98
|
+
|
99
|
+
[**Gem**](http://www.rubydoc.info/gems/redd/Redd/Models/Session) / [**GitHub**](http://www.rubydoc.info/github/avinashbot/redd/master/Redd/Models/Session)
|
100
|
+
|
101
|
+
#### Where can I ask for help if I'm having issues?
|
102
|
+
Check out the [**official subreddit**](https://www.reddit.com/r/Redd) or raise a [**GitHub issue**](https://github.com/avinashbot/redd/issues/new).
|
103
|
+
|
104
|
+
#### How do I request a feature / contribute?
|
105
|
+
Take a look at [**CONTRIBUTING.md**](https://github.com/avinashbot/redd/blob/master/CONTRIBUTING.md).
|
106
|
+
|
107
|
+
#### How can I contact you?
|
108
|
+
[Reddit](https://www.reddit.com/message/compose/?to=Mustermind) /
|
109
|
+
[Email](mailto:avinash@dwarapu.me)
|
110
|
+
|
111
|
+
---
|
112
|
+
|
113
|
+
<div align="center">
|
114
|
+
<!-- Copyright Notice -->
|
115
|
+
<em>
|
116
|
+
This project is available under the MIT License. See LICENSE.txt for more details.<br>
|
117
|
+
The Redd logo uses the FARRAY font by Coquet Adrien.
|
118
|
+
</em>
|
119
|
+
</div>
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rubocop/rake_task'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
|
7
|
+
RuboCop::RakeTask.new do |t|
|
8
|
+
t.fail_on_error = false
|
9
|
+
end
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
|
12
|
+
task default: %i[rubocop spec]
|