redd 0.6.5 → 0.7.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 +4 -4
- data/.gitignore +34 -33
- data/.rspec +3 -4
- data/.rubocop.yml +5 -5
- data/.travis.yml +9 -7
- data/{LICENSE.md → LICENSE.txt} +22 -22
- data/README.md +126 -241
- data/Rakefile +5 -6
- data/{RedditKit.LICENSE.md → RedditKit.LICENSE.txt} +13 -13
- data/lib/redd.rb +50 -4
- data/lib/redd/access.rb +76 -0
- data/lib/redd/clients/base.rb +178 -0
- data/lib/redd/clients/base/account.rb +20 -0
- data/lib/redd/clients/base/identity.rb +22 -0
- data/lib/redd/clients/base/none.rb +27 -0
- data/lib/redd/clients/base/privatemessages.rb +28 -0
- data/lib/redd/clients/base/read.rb +66 -0
- data/lib/redd/clients/base/stream.rb +74 -0
- data/lib/redd/clients/base/submit.rb +54 -0
- data/lib/redd/clients/base/utilities.rb +80 -0
- data/lib/redd/clients/base/wikiread.rb +33 -0
- data/lib/redd/clients/installed.rb +55 -0
- data/lib/redd/clients/script.rb +37 -0
- data/lib/redd/clients/userless.rb +31 -0
- data/lib/redd/clients/web.rb +57 -0
- data/lib/redd/error.rb +138 -153
- data/lib/redd/objects/base.rb +36 -0
- data/lib/redd/objects/comment.rb +22 -0
- data/lib/redd/objects/listing.rb +29 -0
- data/lib/redd/objects/more_comments.rb +10 -0
- data/lib/redd/objects/private_message.rb +18 -0
- data/lib/redd/objects/submission.rb +72 -0
- data/lib/redd/objects/subreddit.rb +152 -0
- data/lib/redd/objects/thing.rb +33 -0
- data/lib/redd/objects/thing/editable.rb +22 -0
- data/lib/redd/objects/thing/hideable.rb +18 -0
- data/lib/redd/objects/thing/inboxable.rb +25 -0
- data/lib/redd/objects/thing/messageable.rb +34 -0
- data/lib/redd/objects/thing/moderatable.rb +43 -0
- data/lib/redd/objects/thing/refreshable.rb +14 -0
- data/lib/redd/objects/thing/saveable.rb +21 -0
- data/lib/redd/objects/thing/votable.rb +33 -0
- data/lib/redd/objects/user.rb +52 -0
- data/lib/redd/objects/wiki_page.rb +15 -0
- data/lib/redd/rate_limit.rb +50 -49
- data/lib/redd/response/parse_json.rb +17 -33
- data/lib/redd/response/raise_error.rb +16 -25
- data/lib/redd/version.rb +4 -5
- data/redd.gemspec +30 -31
- data/spec/redd/objects/base_spec.rb +1 -0
- data/spec/redd/rate_limit_spec.rb +29 -29
- data/spec/redd/response/parse_json_spec.rb +12 -0
- data/spec/redd/response/raise_error_spec.rb +11 -0
- data/spec/redd_spec.rb +7 -5
- data/spec/spec_helper.rb +69 -50
- metadata +73 -136
- data/.yardopts +0 -1
- data/lib/redd/base.rb +0 -56
- data/lib/redd/client/authenticated.rb +0 -83
- data/lib/redd/client/authenticated/account.rb +0 -13
- data/lib/redd/client/authenticated/apps.rb +0 -13
- data/lib/redd/client/authenticated/flair.rb +0 -71
- data/lib/redd/client/authenticated/gold.rb +0 -13
- data/lib/redd/client/authenticated/links_comments.rb +0 -189
- data/lib/redd/client/authenticated/live.rb +0 -13
- data/lib/redd/client/authenticated/moderation.rb +0 -126
- data/lib/redd/client/authenticated/multis.rb +0 -9
- data/lib/redd/client/authenticated/private_messages.rb +0 -73
- data/lib/redd/client/authenticated/subreddits.rb +0 -172
- data/lib/redd/client/authenticated/users.rb +0 -9
- data/lib/redd/client/authenticated/wiki.rb +0 -9
- data/lib/redd/client/oauth2.rb +0 -71
- data/lib/redd/client/oauth2/authorization.rb +0 -108
- data/lib/redd/client/oauth2/identity.rb +0 -16
- data/lib/redd/client/oauth2_script.rb +0 -24
- data/lib/redd/client/oauth2_script/authorization.rb +0 -21
- data/lib/redd/client/unauthenticated.rb +0 -118
- data/lib/redd/client/unauthenticated/account.rb +0 -30
- data/lib/redd/client/unauthenticated/captcha.rb +0 -27
- data/lib/redd/client/unauthenticated/links_comments.rb +0 -60
- data/lib/redd/client/unauthenticated/listing.rb +0 -65
- data/lib/redd/client/unauthenticated/live.rb +0 -9
- data/lib/redd/client/unauthenticated/moderation.rb +0 -26
- data/lib/redd/client/unauthenticated/subreddits.rb +0 -49
- data/lib/redd/client/unauthenticated/users.rb +0 -67
- data/lib/redd/client/unauthenticated/utilities.rb +0 -109
- data/lib/redd/client/unauthenticated/wiki.rb +0 -33
- data/lib/redd/oauth2_access.rb +0 -70
- data/lib/redd/object/comment.rb +0 -74
- data/lib/redd/object/listing.rb +0 -29
- data/lib/redd/object/more_comments.rb +0 -14
- data/lib/redd/object/private_message.rb +0 -35
- data/lib/redd/object/submission.rb +0 -94
- data/lib/redd/object/subreddit.rb +0 -74
- data/lib/redd/object/user.rb +0 -34
- data/lib/redd/object/wiki_page.rb +0 -27
- data/lib/redd/thing.rb +0 -27
- data/lib/redd/thing/commentable.rb +0 -27
- data/lib/redd/thing/editable.rb +0 -16
- data/lib/redd/thing/hideable.rb +0 -16
- data/lib/redd/thing/inboxable.rb +0 -20
- data/lib/redd/thing/messageable.rb +0 -12
- data/lib/redd/thing/moderatable.rb +0 -32
- data/lib/redd/thing/reportable.rb +0 -12
- data/lib/redd/thing/saveable.rb +0 -16
- data/lib/redd/thing/voteable.rb +0 -22
- data/spec/README.md +0 -18
- data/spec/redd/base_spec.rb +0 -36
- data/spec/redd/client/authenticated/account_spec.rb +0 -5
- data/spec/redd/client/authenticated/apps_spec.rb +0 -2
- data/spec/redd/client/authenticated/flair_spec.rb +0 -26
- data/spec/redd/client/authenticated/gold_spec.rb +0 -2
- data/spec/redd/client/authenticated/links_comments_spec.rb +0 -231
- data/spec/redd/client/authenticated/live_spec.rb +0 -2
- data/spec/redd/client/unauthenticated/account_spec.rb +0 -15
- data/spec/redd/client/unauthenticated/captcha_spec.rb +0 -23
- data/spec/redd/client/unauthenticated/links_comments_spec.rb +0 -28
- data/spec/redd/client/unauthenticated/listing_spec.rb +0 -23
- data/spec/redd/client/unauthenticated/live_spec.rb +0 -2
- data/spec/redd/client/unauthenticated/moderation_spec.rb +0 -14
- data/spec/redd/client/unauthenticated/subreddits_spec.rb +0 -35
- data/spec/redd/client/unauthenticated/users_spec.rb +0 -34
- data/spec/redd/client/unauthenticated/wiki_spec.rb +0 -18
- data/spec/redd/oauth2_access_spec.rb +0 -83
- data/spec/redd/thing_spec.rb +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dc908201324aea927202ad7e528f0fbf32ae56be
|
|
4
|
+
data.tar.gz: 92b74d29e18b82bd9f378b5eb44f84bfac519c6f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c4c793e73a7d8a65722678da3069cc3affe66d14b19195283dfc9b6fdcc29b183e1e67ea673f0ed5f68b069515a41f7d2fd6e46bb8cb80c36c70a6db225bb9c0
|
|
7
|
+
data.tar.gz: 69ba345a72d015d9e44a44c46de2ae26b57b4ff8474c48d270d4976caf1131f7d458ef184538f1108dd92f6e40547077d6a59bc1c0aec9ca3ef987cd99257639
|
data/.gitignore
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
*.gem
|
|
2
|
-
*.rbc
|
|
3
|
-
/.config
|
|
4
|
-
/coverage/
|
|
5
|
-
/InstalledFiles
|
|
6
|
-
/pkg/
|
|
7
|
-
/spec/reports/
|
|
8
|
-
/test/tmp/
|
|
9
|
-
/test/version_tmp/
|
|
10
|
-
/tmp/
|
|
11
|
-
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
#
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/test/tmp/
|
|
9
|
+
/test/version_tmp/
|
|
10
|
+
/tmp/
|
|
11
|
+
|
|
12
|
+
## Specific to RubyMotion:
|
|
13
|
+
.dat*
|
|
14
|
+
.repl_history
|
|
15
|
+
build/
|
|
16
|
+
|
|
17
|
+
## Documentation cache and generated files:
|
|
18
|
+
/.yardoc/
|
|
19
|
+
/_yardoc/
|
|
20
|
+
/doc/
|
|
21
|
+
/rdoc/
|
|
22
|
+
|
|
23
|
+
## Environment normalisation:
|
|
24
|
+
/.bundle/
|
|
25
|
+
/lib/bundler/man/
|
|
26
|
+
|
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
29
|
+
Gemfile.lock
|
|
30
|
+
.ruby-version
|
|
31
|
+
.ruby-gemset
|
|
32
|
+
|
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
34
|
+
.rvmrc
|
data/.rspec
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
--
|
|
2
|
-
--format documentation
|
|
3
|
-
--
|
|
4
|
-
--require spec_helper
|
|
1
|
+
--require spec_helper
|
|
2
|
+
--format documentation
|
|
3
|
+
--color
|
data/.rubocop.yml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
StringLiterals:
|
|
2
|
-
EnforcedStyle: double_quotes
|
|
3
|
-
|
|
4
|
-
Style/SpaceInsideHashLiteralBraces:
|
|
5
|
-
Enabled: false
|
|
1
|
+
StringLiterals:
|
|
2
|
+
EnforcedStyle: double_quotes
|
|
3
|
+
|
|
4
|
+
Style/SpaceInsideHashLiteralBraces:
|
|
5
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/{LICENSE.md → LICENSE.txt}
RENAMED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
Copyright (c)
|
|
2
|
-
|
|
3
|
-
MIT License
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
a copy of this software and associated documentation files (the
|
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
-
the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
included in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
Copyright (c) 2015 Avinash Dwarapu
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,241 +1,126 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img src="https://i.imgur.com/2JfE4M1.png" alt="redd"><br>
|
|
3
|
-
<a href="https://rubygems.org/gems/redd"><img src="http://img.shields.io/gem/v/redd.svg?style=flat-square" alt="Gem Version"></a>
|
|
4
|
-
<a href="https://travis-ci.org/avidw/redd"><img src="http://img.shields.io/travis/avidw/redd.svg?style=flat-square" alt="Build Status"></a>
|
|
5
|
-
<a href="https://rubygems.org/gems/redd"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT License"></a>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
Now let's run the application:
|
|
130
|
-
|
|
131
|
-
```shell
|
|
132
|
-
$ rackup -p 8080
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
#### Remember Me
|
|
136
|
-
If you want longer control of users' accounts for background tasks like auto-saving to a users' account behind the scenes or not have to ask your user to go through reddit every time, you can choose to have a permanent access by changing the second parameter of `auth_url`.
|
|
137
|
-
|
|
138
|
-
```ruby
|
|
139
|
-
client = Redd::Client::OAuth2.new("sa_xTDcJ3dWz0w", "very-sensitive-secret", "http://localhost:8080/auth/reddit/redirect")
|
|
140
|
-
state = SecureRandom.urlsafe_base64
|
|
141
|
-
auth_url = client.auth_url(["identity"], :permanent, state)
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
The access will still only last one hour, but you can refresh the access whenever you want.
|
|
145
|
-
|
|
146
|
-
```ruby
|
|
147
|
-
access = client.request_access(params[:code])
|
|
148
|
-
|
|
149
|
-
# 1 hour or more later
|
|
150
|
-
client.refresh_access(access) if access.expired?
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
Now if you are running a web application, you can't just store access tokens in memory. `Redd::OAuth2Access` offers a couple of methods for serializing the access to JSON and retrieving it.
|
|
154
|
-
|
|
155
|
-
```ruby
|
|
156
|
-
json = access.to_json
|
|
157
|
-
current_user.update!(access: json) # Rails
|
|
158
|
-
redis.set("some-token", json) # Redis
|
|
159
|
-
|
|
160
|
-
# After some time
|
|
161
|
-
access = Redd::OAuth2Access.from_json(current_user.access)
|
|
162
|
-
client.with_access(access) do |authenticated_client|
|
|
163
|
-
authenticated_client.do_whatever_redd_client_can_do
|
|
164
|
-
end
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
#### Who, me?
|
|
168
|
-
You can also revoke access tokens after the user has logged out to make sure the tokens can't be used for malicious purposes.
|
|
169
|
-
|
|
170
|
-
```ruby
|
|
171
|
-
also_revoke_refresh_token = true
|
|
172
|
-
client.revoke_access(access, also_revoke_refresh_token)
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
## Extending Redd
|
|
176
|
-
Extending any ruby library, including redd is incredibly easy. Let's try this out by adding a gilding extension. Reddit provides an api to be able to gild posts and comments, given that you have "creddits".
|
|
177
|
-
|
|
178
|
-
1. Let's start by creating a module for the methods to live in.
|
|
179
|
-
|
|
180
|
-
```ruby
|
|
181
|
-
module MyGildingExtension
|
|
182
|
-
end
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
2. Let's add a method to gild a thing, using the [reddit api](http://www.reddit.com/dev/api#section_gold) and following the conventions.
|
|
186
|
-
|
|
187
|
-
```ruby
|
|
188
|
-
module MyGildingExtension
|
|
189
|
-
def gild(thing)
|
|
190
|
-
# Redd::Client::Unauthenticated::Utilities has some pretty helpful
|
|
191
|
-
# methods.
|
|
192
|
-
fullname = extract_fullname(thing)
|
|
193
|
-
|
|
194
|
-
# We're using post instead of object_from_response, because we don't
|
|
195
|
-
# expect any object from the response.
|
|
196
|
-
post "/api/v1/gold/gild/#{fullname}"
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
3. Let's add the method to the Authenticated client. You can also add it to the Unauthenticated client, but since unauthenticated users can't gild, there's no point.
|
|
202
|
-
|
|
203
|
-
```ruby
|
|
204
|
-
Redd::Client::Authenticated.include(MyGildingExtension)
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
4. You might also want to add the method to objects to make it easier to access.
|
|
208
|
-
|
|
209
|
-
```ruby
|
|
210
|
-
module Gildable
|
|
211
|
-
def gild
|
|
212
|
-
# Every Redd::Object is instantiated with the client that created
|
|
213
|
-
# it, so the method can be called on the client easily, similar to
|
|
214
|
-
# praw in python.
|
|
215
|
-
client.gild(self)
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
Redd::Object::Submission.include(Gildable)
|
|
220
|
-
Redd::Object::Comment.include(Gildable)
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
## Contributing
|
|
224
|
-
[Fork the repository](https://github.com/avidw/redd/fork), [create a pull request](https://github.com/avidw/redd/compare) and [go nuts](https://i.imgur.com/lz7hOlC.jpg).
|
|
225
|
-
|
|
226
|
-
*You don't have to run the tests, Travis CI will automatically do that with my testing subreddit and account when you submit a pull request.*
|
|
227
|
-
|
|
228
|
-
## Supported Rubies
|
|
229
|
-
This gem aims to work on the following rubies:
|
|
230
|
-
|
|
231
|
-
MRI: **1.9.3** - **2.1.2**
|
|
232
|
-
JRuby: **1.7.x**
|
|
233
|
-
Rubinius: **2.x.x**
|
|
234
|
-
|
|
235
|
-
## Copyright
|
|
236
|
-
Copyright (c) [Avinash Dwarapu](http://github.com/avidw) under the MIT License. See LICENSE.md for more details.
|
|
237
|
-
Some code has been used from [RedditKit.rb](http://github.com/samsymons/RedditKit.rb). See RedditKit.LICENSE.md for more details.
|
|
238
|
-
|
|
239
|
-
---
|
|
240
|
-
|
|
241
|
-
Redd not your cup of tea? Check out [RedditKit.rb](http://github.com/samsymons/RedditKit.rb)!
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://i.imgur.com/2JfE4M1.png" alt="redd"><br>
|
|
3
|
+
<a href="https://rubygems.org/gems/redd"><img src="http://img.shields.io/gem/v/redd.svg?style=flat-square" alt="Gem Version"></a>
|
|
4
|
+
<a href="https://travis-ci.org/avidw/redd"><img src="http://img.shields.io/travis/avidw/redd.svg?style=flat-square" alt="Build Status"></a>
|
|
5
|
+
<a href="https://rubygems.org/gems/redd"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT License"></a>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
**redd** is an API wrapper for [reddit](http://www.reddit.com/dev/api) written in ruby that focuses on being consistent and extensible. **Check out the latest documentation on [RubyDoc](http://www.rubydoc.info/github/avidw/redd/master/frames/Redd.it).**
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
#### Gemfile
|
|
13
|
+
```ruby
|
|
14
|
+
gem "ruby", "~> 0.7.0"
|
|
15
|
+
# if you're feeling adventurous
|
|
16
|
+
# gem "redd", github: "avidw/redd", branch: "oauth2"
|
|
17
|
+
|
|
18
|
+
gem "oj", platforms: :ruby
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
#### Getting Started
|
|
22
|
+
```ruby
|
|
23
|
+
# Authorization (Web)
|
|
24
|
+
w = Redd.it(:web, "CLIENT_ID", "SECRET", "REDIRECT_URI", user_agent: "TestSite v1.0.0")
|
|
25
|
+
url = w.auth_url("random_state", ["identity", "read"], :temporary)
|
|
26
|
+
puts "Please go to #{url} and enter the code below:"
|
|
27
|
+
code = gets.chomp
|
|
28
|
+
w.authorize!(code)
|
|
29
|
+
|
|
30
|
+
# Authorization
|
|
31
|
+
r = Redd.it(:script, "CLIENT_ID", "SECRET", "Unidan", "hunter2", user_agent: "TestBot v1.0.0")
|
|
32
|
+
r.authorize!
|
|
33
|
+
|
|
34
|
+
# See documentation for more grants.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
# Access
|
|
39
|
+
get "/redirect" do
|
|
40
|
+
access = w.authorize!(params[:code])
|
|
41
|
+
session[:access] = access.to_json
|
|
42
|
+
redirect to("/name")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
get "/name" do
|
|
46
|
+
session_access = Access.from_json(session[:access])
|
|
47
|
+
w.with(session_access) do |client|
|
|
48
|
+
client.refresh_access! if session_access.expired?
|
|
49
|
+
"Your username is #{client.me.name}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
# Getting a model
|
|
57
|
+
vargas = r.user_from_name("_vargas_")
|
|
58
|
+
puts vargas.keys
|
|
59
|
+
puts vargas.over_18?
|
|
60
|
+
|
|
61
|
+
picturegame = r.subreddit_from_name("picturegame")
|
|
62
|
+
puts picturegame.display_name
|
|
63
|
+
puts picturegame.public_description
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
# Listings
|
|
68
|
+
hot = r.get_hot("all")
|
|
69
|
+
hot.each { |link| puts "#{link.title} by /u/#{link.author}" }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
# Streaming
|
|
74
|
+
def stream_all!
|
|
75
|
+
r.stream :get_comments, "all" do |comment|
|
|
76
|
+
comment.reply("World!") if comment.body == "Hello?"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
# Escaping Errors
|
|
83
|
+
begin
|
|
84
|
+
stream_all!
|
|
85
|
+
rescue Redd::Error::RateLimited => error
|
|
86
|
+
sleep(error.time)
|
|
87
|
+
retry
|
|
88
|
+
rescue Redd::Error => error
|
|
89
|
+
# 5-something errors are usually errors on reddit's end.
|
|
90
|
+
raise error unless (500...600).include?(error.code)
|
|
91
|
+
retry
|
|
92
|
+
end
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Extras
|
|
96
|
+
```ruby
|
|
97
|
+
# Extending Redd.rb
|
|
98
|
+
|
|
99
|
+
module MyGildingExtension
|
|
100
|
+
def gild!
|
|
101
|
+
# We're using post instead of request_object, because we don't
|
|
102
|
+
# expect any object from the response.
|
|
103
|
+
post("/api/v1/gold/gild/#{fullname}")
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
Redd::Objects::Comment.include(MyGildingExtension)
|
|
108
|
+
Redd::Objects::Submission.include(MyGildingExtension)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```markdown
|
|
112
|
+
# Contributing
|
|
113
|
+
1. [Fork](https://github.com/avidw/redd/issues/new)
|
|
114
|
+
2. [Pull](https://github.com/avidw/redd/compare)
|
|
115
|
+
3. [Profit](https://www.reddit.com/r/requestabot)
|
|
116
|
+
|
|
117
|
+
# Request a Feature
|
|
118
|
+
1. [Help](https://github.com/avidw/redd/issues/new)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
# Copyright.rb
|
|
123
|
+
#
|
|
124
|
+
# Copyright (c) Avinash Dwarapu under the MIT License. See LICENSE.txt for more details.
|
|
125
|
+
# Redd::Error has been modified from RedditKit.rb. See RedditKit.LICENSE.txt for its license.
|
|
126
|
+
```
|