redd 0.7.8 → 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +34 -34
  3. data/.rspec +3 -3
  4. data/.rubocop.yml +5 -5
  5. data/.travis.yml +9 -9
  6. data/LICENSE.md +22 -22
  7. data/README.md +143 -143
  8. data/Rakefile +5 -5
  9. data/RedditKit.LICENSE.md +8 -8
  10. data/lib/redd.rb +50 -50
  11. data/lib/redd/access.rb +76 -76
  12. data/lib/redd/clients/base.rb +181 -181
  13. data/lib/redd/clients/base/account.rb +20 -20
  14. data/lib/redd/clients/base/identity.rb +22 -22
  15. data/lib/redd/clients/base/none.rb +27 -27
  16. data/lib/redd/clients/base/privatemessages.rb +33 -33
  17. data/lib/redd/clients/base/read.rb +113 -113
  18. data/lib/redd/clients/base/stream.rb +81 -81
  19. data/lib/redd/clients/base/submit.rb +19 -19
  20. data/lib/redd/clients/base/utilities.rb +104 -104
  21. data/lib/redd/clients/base/wikiread.rb +33 -33
  22. data/lib/redd/clients/installed.rb +56 -56
  23. data/lib/redd/clients/script.rb +41 -41
  24. data/lib/redd/clients/userless.rb +32 -32
  25. data/lib/redd/clients/web.rb +58 -58
  26. data/lib/redd/error.rb +151 -151
  27. data/lib/redd/objects/base.rb +39 -39
  28. data/lib/redd/objects/comment.rb +22 -22
  29. data/lib/redd/objects/labeled_multi.rb +13 -13
  30. data/lib/redd/objects/listing.rb +29 -29
  31. data/lib/redd/objects/more_comments.rb +11 -10
  32. data/lib/redd/objects/private_message.rb +28 -28
  33. data/lib/redd/objects/submission.rb +139 -139
  34. data/lib/redd/objects/subreddit.rb +330 -319
  35. data/lib/redd/objects/thing.rb +26 -26
  36. data/lib/redd/objects/thing/editable.rb +22 -22
  37. data/lib/redd/objects/thing/hideable.rb +18 -18
  38. data/lib/redd/objects/thing/inboxable.rb +25 -25
  39. data/lib/redd/objects/thing/messageable.rb +34 -34
  40. data/lib/redd/objects/thing/moderatable.rb +43 -43
  41. data/lib/redd/objects/thing/refreshable.rb +14 -14
  42. data/lib/redd/objects/thing/saveable.rb +21 -21
  43. data/lib/redd/objects/thing/votable.rb +33 -33
  44. data/lib/redd/objects/user.rb +52 -52
  45. data/lib/redd/objects/wiki_page.rb +15 -15
  46. data/lib/redd/rate_limit.rb +88 -88
  47. data/lib/redd/response/parse_json.rb +18 -18
  48. data/lib/redd/response/raise_error.rb +16 -16
  49. data/lib/redd/version.rb +4 -4
  50. data/redd.gemspec +31 -31
  51. data/spec/redd/objects/base_spec.rb +1 -1
  52. data/spec/redd/response/raise_error_spec.rb +11 -11
  53. data/spec/redd_spec.rb +5 -5
  54. data/spec/spec_helper.rb +71 -71
  55. metadata +21 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ed185709399c5e0bf0984f8323b710b977b8b24
4
- data.tar.gz: 51d437dfc4f6d2477e33db31e5ef3c340f36e34c
3
+ metadata.gz: 2617c83dedaf3dcd90f02e3b065c879f05898b64
4
+ data.tar.gz: f7634f90934515422bd205efc37e2d393d562f6b
5
5
  SHA512:
6
- metadata.gz: 772c63c331ccfdb175ab743f36a994147d949f2cbc16179eede313b87985f2a0ed450498f6a170d6e69bda234cc610a23c4dd1ffc0b05aaa3908fc1b97e24bce
7
- data.tar.gz: 86330606ecb14b4ec43d834af0f48bc47495761a9d3c5ae30e5411422ec7c10d0ddf66cd1dc8c8f404370d7e9dce5f12789399d53fc31a469fc71e95768a336e
6
+ metadata.gz: 5fab04e72faab63714db2dd149416465d5fbd01c2a6e10179bba746bbeddcea9d0c6ff73e70db8bd2d0e7fca971fa69d84ef252c7f94b00ecea52908b97939f3
7
+ data.tar.gz: 911f0b8f8639efc1439dcd1756b9a0e7acaf9f261b28983755295184bf6e59e4afd558b4bd09d22aa22a9b4e15424f9732947573e2246e1b8644b6cb7df7976c
data/.gitignore CHANGED
@@ -1,34 +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
- ## 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
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,3 +1,3 @@
1
- --require spec_helper
2
- --format documentation
3
- --color
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
@@ -1,9 +1,9 @@
1
- language: ruby
2
- before_install:
3
- - gem install bundler
4
- rvm:
5
- - ruby-2.1.0
6
- - ruby-2.2.0
7
- - ruby-2
8
- - rbx-2
9
- - jruby-9.0.0.0.pre1
1
+ language: ruby
2
+ before_install:
3
+ - gem install bundler -v 1.12
4
+ rvm:
5
+ - ruby-2.1.0
6
+ - ruby-2.2.0
7
+ - ruby-2
8
+ - rbx-2
9
+ - jruby-9.0.0.0.pre1
data/LICENSE.md CHANGED
@@ -1,22 +1,22 @@
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.
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,143 +1,143 @@
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
- <a href="https://gitter.im/avidw/redd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://img.shields.io/badge/GITTER-JOIN%20CHAT%20%E2%86%92-1dce73.svg?style=flat-square" alt="Chat on Gitter"></a>
7
- </p>
8
-
9
- **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).**
10
-
11
- ---
12
-
13
- #### Gemfile
14
- ```ruby
15
- gem "redd", "~> 0.7.0"
16
-
17
- # Optional fast JSON parser.
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
- require "secure_random"
40
- require "sinatra"
41
-
42
- enable :sessions
43
-
44
- get "/auth" do
45
- state = SecureRandom.urlsafe_base64
46
- session[:state] = state
47
- redirect w.auth_url(state, %w(identity), :permanent)
48
- end
49
-
50
- get "/redirect" do
51
- halt 500, "Your state doesn't match!" unless session[:state] == params[:state]
52
- access = w.authorize!(params[:code])
53
- session[:access] = access.to_json
54
- redirect to("/name")
55
- end
56
-
57
- get "/name" do
58
- if session[:access]
59
- session_access = Redd::Access.from_json(session[:access])
60
- w.with(session_access) do |client|
61
- client.refresh_access! if session_access.expired?
62
- "Your username is #{client.me.name}"
63
- end
64
- else
65
- redirect to("/auth")
66
- end
67
- end
68
-
69
- ```
70
-
71
- ```ruby
72
- # Getting a model
73
- vargas = r.user_from_name("_vargas_")
74
- puts vargas.keys
75
- puts vargas.over_18?
76
-
77
- picturegame = r.subreddit_from_name("picturegame")
78
- puts picturegame.display_name
79
- puts picturegame.public_description
80
- ```
81
-
82
- ```ruby
83
- # Listings
84
- hot = r.get_hot("all")
85
- hot.each { |link| puts "#{link.title} by /u/#{link.author}" }
86
- ```
87
-
88
- ```ruby
89
- # Streaming
90
- def stream_all!
91
- r.stream :get_comments, "all" do |comment|
92
- reddit.refresh_access! if reddit.access.expired? # for :web
93
- comment.reply("World!") if comment.body == "Hello?"
94
- end
95
- end
96
- ```
97
-
98
- ```ruby
99
- # Escaping Errors
100
- begin
101
- stream_all!
102
- rescue Redd::Error::RateLimited => error
103
- sleep(error.time)
104
- retry
105
- rescue Redd::Error => error
106
- # 5-something errors are usually errors on reddit's end.
107
- raise error unless (500...600).include?(error.code)
108
- retry
109
- end
110
- ```
111
-
112
- #### Extras
113
- ```ruby
114
- # Extending Redd.rb
115
-
116
- module MyGildingExtension
117
- def gild!
118
- # We're using post instead of request_object, because we don't
119
- # expect any object from the response.
120
- post("/api/v1/gold/gild/#{fullname}")
121
- end
122
- end
123
-
124
- Redd::Objects::Comment.include(MyGildingExtension)
125
- Redd::Objects::Submission.include(MyGildingExtension)
126
- ```
127
-
128
- ```markdown
129
- # Contributing
130
- 1. [Fork](https://github.com/avidw/redd/issues/new)
131
- 2. [Pull](https://github.com/avidw/redd/compare)
132
- 3. [Profit](https://www.reddit.com/r/requestabot)
133
-
134
- # Request a Feature
135
- 1. [Help](https://github.com/avidw/redd/issues/new)
136
- ```
137
-
138
- ```ruby
139
- # Copyright.rb
140
- #
141
- # Copyright (c) Avinash Dwarapu under the MIT License. See LICENSE.md for more details.
142
- # Redd::Error has been modified from RedditKit.rb. See RedditKit.LICENSE.md for its license.
143
- ```
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
+ <a href="https://gitter.im/avidw/redd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://img.shields.io/badge/GITTER-JOIN%20CHAT%20%E2%86%92-1dce73.svg?style=flat-square" alt="Chat on Gitter"></a>
7
+ </p>
8
+
9
+ **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).**
10
+
11
+ ---
12
+
13
+ #### Gemfile
14
+ ```ruby
15
+ gem "redd", "~> 0.7.0"
16
+
17
+ # Optional fast JSON parser.
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
+ require "secure_random"
40
+ require "sinatra"
41
+
42
+ enable :sessions
43
+
44
+ get "/auth" do
45
+ state = SecureRandom.urlsafe_base64
46
+ session[:state] = state
47
+ redirect w.auth_url(state, %w(identity), :permanent)
48
+ end
49
+
50
+ get "/redirect" do
51
+ halt 500, "Your state doesn't match!" unless session[:state] == params[:state]
52
+ access = w.authorize!(params[:code])
53
+ session[:access] = access.to_json
54
+ redirect to("/name")
55
+ end
56
+
57
+ get "/name" do
58
+ if session[:access]
59
+ session_access = Redd::Access.from_json(session[:access])
60
+ w.with(session_access) do |client|
61
+ client.refresh_access! if session_access.expired?
62
+ "Your username is #{client.me.name}"
63
+ end
64
+ else
65
+ redirect to("/auth")
66
+ end
67
+ end
68
+
69
+ ```
70
+
71
+ ```ruby
72
+ # Getting a model
73
+ vargas = r.user_from_name("_vargas_")
74
+ puts vargas.keys
75
+ puts vargas.over_18?
76
+
77
+ picturegame = r.subreddit_from_name("picturegame")
78
+ puts picturegame.display_name
79
+ puts picturegame.public_description
80
+ ```
81
+
82
+ ```ruby
83
+ # Listings
84
+ hot = r.get_hot("all")
85
+ hot.each { |link| puts "#{link.title} by /u/#{link.author}" }
86
+ ```
87
+
88
+ ```ruby
89
+ # Streaming
90
+ def stream_all!
91
+ r.stream :get_comments, "all" do |comment|
92
+ reddit.refresh_access! if reddit.access.expired? # for :web
93
+ comment.reply("World!") if comment.body == "Hello?"
94
+ end
95
+ end
96
+ ```
97
+
98
+ ```ruby
99
+ # Escaping Errors
100
+ begin
101
+ stream_all!
102
+ rescue Redd::Error::RateLimited => error
103
+ sleep(error.time)
104
+ retry
105
+ rescue Redd::Error => error
106
+ # 5-something errors are usually errors on reddit's end.
107
+ raise error unless (500...600).include?(error.code)
108
+ retry
109
+ end
110
+ ```
111
+
112
+ #### Extras
113
+ ```ruby
114
+ # Extending Redd.rb
115
+
116
+ module MyGildingExtension
117
+ def gild!
118
+ # We're using post instead of request_object, because we don't
119
+ # expect any object from the response.
120
+ post("/api/v1/gold/gild/#{fullname}")
121
+ end
122
+ end
123
+
124
+ Redd::Objects::Comment.include(MyGildingExtension)
125
+ Redd::Objects::Submission.include(MyGildingExtension)
126
+ ```
127
+
128
+ ```markdown
129
+ # Contributing
130
+ 1. [Fork](https://github.com/avidw/redd/issues/new)
131
+ 2. [Pull](https://github.com/avidw/redd/compare)
132
+ 3. [Profit](https://www.reddit.com/r/requestabot)
133
+
134
+ # Request a Feature
135
+ 1. [Help](https://github.com/avidw/redd/issues/new)
136
+ ```
137
+
138
+ ```ruby
139
+ # Copyright.rb
140
+ #
141
+ # Copyright (c) Avinash Dwarapu under the MIT License. See LICENSE.md for more details.
142
+ # Redd::Error has been modified from RedditKit.rb. See RedditKit.LICENSE.md for its license.
143
+ ```