redd 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,74 +0,0 @@
|
|
1
|
-
require "redd/thing"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
module Object
|
5
|
-
# A comment made on links.
|
6
|
-
# @note This model can sure benefit from some lazy-loading...
|
7
|
-
class Subreddit < Redd::Thing
|
8
|
-
require "redd/thing/messageable"
|
9
|
-
|
10
|
-
include Redd::Thing::Messageable
|
11
|
-
|
12
|
-
attr_reader :display_name
|
13
|
-
attr_reader :title
|
14
|
-
|
15
|
-
attr_reader :description
|
16
|
-
attr_reader :description_html
|
17
|
-
|
18
|
-
attr_reader :header_img
|
19
|
-
attr_reader :header_title
|
20
|
-
attr_reader :header_size
|
21
|
-
|
22
|
-
attr_reader :user_is_banned
|
23
|
-
attr_reader :user_is_contributor
|
24
|
-
attr_reader :user_is_moderator
|
25
|
-
attr_reader :user_is_subscriber
|
26
|
-
|
27
|
-
attr_reader :submit_text
|
28
|
-
attr_reader :submit_text_html
|
29
|
-
attr_reader :submit_link_label
|
30
|
-
attr_reader :submit_text_label
|
31
|
-
|
32
|
-
attr_reader :over18
|
33
|
-
attr_reader :accounts_active
|
34
|
-
attr_reader :public_traffic
|
35
|
-
attr_reader :subscribers
|
36
|
-
attr_reader :comment_score_hide_mins
|
37
|
-
attr_reader :subreddit_type
|
38
|
-
attr_reader :submission_type
|
39
|
-
|
40
|
-
alias_method :header_image, :header_img
|
41
|
-
alias_method :nsfw?, :over18
|
42
|
-
alias_method :users_online, :accounts_active
|
43
|
-
alias_method :type, :subreddit_type
|
44
|
-
|
45
|
-
def created
|
46
|
-
@created ||= Time.at(@attributes[:created_utc])
|
47
|
-
end
|
48
|
-
|
49
|
-
def url
|
50
|
-
"http://reddit.com" + @attributes[:url]
|
51
|
-
end
|
52
|
-
|
53
|
-
def get_hot(*args)
|
54
|
-
client.get_hot(display_name, *args)
|
55
|
-
end
|
56
|
-
|
57
|
-
def get_new(*args)
|
58
|
-
client.get_new(display_name, *args)
|
59
|
-
end
|
60
|
-
|
61
|
-
def get_random(*args)
|
62
|
-
client.get_random(display_name, *args)
|
63
|
-
end
|
64
|
-
|
65
|
-
def get_top(*args)
|
66
|
-
client.get_top(display_name, *args)
|
67
|
-
end
|
68
|
-
|
69
|
-
def get_controversial(*args)
|
70
|
-
client.get_controversial(display_name, *args)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/lib/redd/object/user.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require "redd/thing"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
module Object
|
5
|
-
# The model for a reddit user
|
6
|
-
class User < Redd::Thing
|
7
|
-
require "redd/thing/messageable"
|
8
|
-
|
9
|
-
include Redd::Thing::Messageable
|
10
|
-
|
11
|
-
attr_reader :name
|
12
|
-
attr_reader :is_friend
|
13
|
-
attr_reader :link_karma
|
14
|
-
attr_reader :comment_karma
|
15
|
-
attr_reader :gold_creddits
|
16
|
-
attr_reader :gold_expiration
|
17
|
-
attr_reader :is_gold
|
18
|
-
attr_reader :is_mod
|
19
|
-
attr_reader :has_verified_email
|
20
|
-
attr_reader :has_mod_mail
|
21
|
-
attr_reader :has_mail
|
22
|
-
|
23
|
-
alias_method :has_gold, :is_gold
|
24
|
-
|
25
|
-
def created
|
26
|
-
@created ||= Time.at(@attributes[:created_utc])
|
27
|
-
end
|
28
|
-
|
29
|
-
def fullname
|
30
|
-
@fullname ||= "#{kind}_#{id}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require "redd/base"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
module Object
|
5
|
-
# A submission made in a subreddit.
|
6
|
-
class WikiPage < Redd::Base
|
7
|
-
attr_reader :kind
|
8
|
-
attr_reader :may_revise
|
9
|
-
attr_reader :content_md
|
10
|
-
attr_reader :content_html
|
11
|
-
|
12
|
-
alias_method :content, :content_md
|
13
|
-
alias_method :body, :content_md
|
14
|
-
|
15
|
-
# HACK
|
16
|
-
def revision_by
|
17
|
-
@revision_by ||= client.send(
|
18
|
-
:object_from_body, @attributes[:revision_by]
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
def revision_date
|
23
|
-
@created ||= Time.at(@attributes[:revision_date])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/redd/thing.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require "redd/base"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
# A reddit thing.
|
5
|
-
# @see http://www.reddit.com/dev/api#fullnames
|
6
|
-
class Thing < Redd::Base
|
7
|
-
# @!attribute [r] id
|
8
|
-
# @return [String] The id value for the thing.
|
9
|
-
attr_reader :id
|
10
|
-
|
11
|
-
# @!attribute [r] kind
|
12
|
-
# @return [String] The kind of the thing.
|
13
|
-
attr_reader :kind
|
14
|
-
|
15
|
-
# Check for equality.
|
16
|
-
# @param other The other object.
|
17
|
-
# @return [Boolean]
|
18
|
-
def ==(other)
|
19
|
-
other.is_a?(Redd::Thing) && full_name == other.full_name
|
20
|
-
end
|
21
|
-
|
22
|
-
# @return [String] The fullname of the thing.
|
23
|
-
def fullname
|
24
|
-
@fullname ||= "#{kind}_#{id}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require "redd/thing"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
class Thing
|
5
|
-
# A Redd::Object that can be commented on.
|
6
|
-
# This means that the comments could contain a MoreComments object.
|
7
|
-
module Commentable
|
8
|
-
def expand_morecomments
|
9
|
-
comments.things.map! do |comment|
|
10
|
-
if comment.is_a?(Redd::Object::MoreComments)
|
11
|
-
comment.expand.things
|
12
|
-
else
|
13
|
-
comment
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
comments.things.flatten!
|
18
|
-
end
|
19
|
-
|
20
|
-
def remove_morecomments
|
21
|
-
while comments.map { |c| c.class }.include? Redd::Object::MoreComments
|
22
|
-
expand_morecomments
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/redd/thing/editable.rb
DELETED
data/lib/redd/thing/hideable.rb
DELETED
data/lib/redd/thing/inboxable.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require "redd/thing"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
class Thing
|
5
|
-
# A Redd::Object that can be added to one's inbox
|
6
|
-
module Inboxable
|
7
|
-
def mark_as_read
|
8
|
-
client.mark_as_read(self)
|
9
|
-
end
|
10
|
-
|
11
|
-
def mark_as_unread
|
12
|
-
client.mark_as_unread(self)
|
13
|
-
end
|
14
|
-
|
15
|
-
def reply(text)
|
16
|
-
client.add_comment(self, text)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require "redd/thing"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
class Thing
|
5
|
-
# A Redd::Object that can be sent a message
|
6
|
-
module Messageable
|
7
|
-
def send_message(subject, text, captcha = nil, identifier = nil)
|
8
|
-
client.send_message(self, subject, text, captcha, identifier)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require "redd/thing"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
class Thing
|
5
|
-
# A Redd::Object that can be moderated
|
6
|
-
module Moderatable
|
7
|
-
def approve
|
8
|
-
client.approve(self)
|
9
|
-
end
|
10
|
-
|
11
|
-
def remove
|
12
|
-
client.remove(self)
|
13
|
-
end
|
14
|
-
|
15
|
-
def distinguish(how = :yes)
|
16
|
-
client.distinguish(self, how)
|
17
|
-
end
|
18
|
-
|
19
|
-
def undistinguish
|
20
|
-
client.undistinguish(self)
|
21
|
-
end
|
22
|
-
|
23
|
-
def ignore_reports
|
24
|
-
client.ignore_reports(self)
|
25
|
-
end
|
26
|
-
|
27
|
-
def unignore_reports
|
28
|
-
client.unignore_reports(self)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/redd/thing/saveable.rb
DELETED
data/lib/redd/thing/voteable.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "redd/thing"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
class Thing
|
5
|
-
# A Redd::Object that can be voted on
|
6
|
-
module Voteable
|
7
|
-
def upvote
|
8
|
-
client.upvote(self)
|
9
|
-
end
|
10
|
-
|
11
|
-
def downvote
|
12
|
-
client.upvote(self)
|
13
|
-
end
|
14
|
-
|
15
|
-
def unvote
|
16
|
-
client.upvote(self)
|
17
|
-
end
|
18
|
-
|
19
|
-
alias_method :clear_vote, :unvote
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/spec/README.md
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
## Setting up the testing environment on reddit
|
2
|
-
|
3
|
-
# Create a subreddit for testing.
|
4
|
-
$ export REDDIT_SUBREDDIT=redd_testing
|
5
|
-
|
6
|
-
# Create an account for testing. You can use your reddit account.
|
7
|
-
$ export REDDIT_USERNAME=redd-testing
|
8
|
-
$ export REDDIT_PASSWORD=????????
|
9
|
-
|
10
|
-
# Create an example post on the subreddit
|
11
|
-
$ export REDDIT_LINKID=t3_2gngbm
|
12
|
-
|
13
|
-
# Create a page on the wiki with the following name
|
14
|
-
# Remember to make the wiki set to "mod editing"
|
15
|
-
$ export REDDIT_WIKIPAGE=redd_wiki_test
|
16
|
-
|
17
|
-
# Grab a sandwich or something. The tests are rate-limited.
|
18
|
-
$ rspec
|
data/spec/redd/base_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
describe Redd::Base do
|
2
|
-
before do
|
3
|
-
stub_const "ReddObject", Class.new(Redd::Base)
|
4
|
-
ReddObject.attr_reader :string
|
5
|
-
ReddObject.attr_reader :condition
|
6
|
-
ReddObject.attr_reader :nonexistent
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:base) do
|
10
|
-
client = Redd::Client::Unauthenticated.new
|
11
|
-
object = {
|
12
|
-
kind: "test_object",
|
13
|
-
data: {
|
14
|
-
string: "test", condition: true,
|
15
|
-
nonexistent: nil, undocumented: :accessible
|
16
|
-
}
|
17
|
-
}
|
18
|
-
ReddObject.new(client, object)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "defines an attribute method" do
|
22
|
-
expect(base.string).to eq("test")
|
23
|
-
expect(base.condition).to eq(true)
|
24
|
-
expect(base.nonexistent).to eq(nil)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "defines a predicate method" do
|
28
|
-
expect(base.string?).to eq(true)
|
29
|
-
expect(base.condition?).to eq(true)
|
30
|
-
expect(base.nonexistent?).to eq(false)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "returns undocumented attributes via #attributes" do
|
34
|
-
expect(base.attributes[:undocumented]).to eq(:accessible)
|
35
|
-
end
|
36
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
describe Redd::Client::Authenticated::Flair do
|
2
|
-
describe "#get_flair_list" do
|
3
|
-
it "returns an array"
|
4
|
-
|
5
|
-
context "when the limit is set to 5" do
|
6
|
-
it "only returns 5 results"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "#get_flair" do
|
11
|
-
before do
|
12
|
-
# set a random flair
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns the correct flair of the user"
|
16
|
-
|
17
|
-
after do
|
18
|
-
# unset the flair? "if it's random each time, there's no point
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#set_flair" do
|
23
|
-
it "sets the flair of a user correctly"
|
24
|
-
it "sets the flair of a link correctly"
|
25
|
-
end
|
26
|
-
end
|