redd 0.7.8 → 0.7.9
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 -34
- data/.rspec +3 -3
- data/.rubocop.yml +5 -5
- data/.travis.yml +9 -9
- data/LICENSE.md +22 -22
- data/README.md +143 -143
- data/Rakefile +5 -5
- data/RedditKit.LICENSE.md +8 -8
- data/lib/redd.rb +50 -50
- data/lib/redd/access.rb +76 -76
- data/lib/redd/clients/base.rb +181 -181
- data/lib/redd/clients/base/account.rb +20 -20
- data/lib/redd/clients/base/identity.rb +22 -22
- data/lib/redd/clients/base/none.rb +27 -27
- data/lib/redd/clients/base/privatemessages.rb +33 -33
- data/lib/redd/clients/base/read.rb +113 -113
- data/lib/redd/clients/base/stream.rb +81 -81
- data/lib/redd/clients/base/submit.rb +19 -19
- data/lib/redd/clients/base/utilities.rb +104 -104
- data/lib/redd/clients/base/wikiread.rb +33 -33
- data/lib/redd/clients/installed.rb +56 -56
- data/lib/redd/clients/script.rb +41 -41
- data/lib/redd/clients/userless.rb +32 -32
- data/lib/redd/clients/web.rb +58 -58
- data/lib/redd/error.rb +151 -151
- data/lib/redd/objects/base.rb +39 -39
- data/lib/redd/objects/comment.rb +22 -22
- data/lib/redd/objects/labeled_multi.rb +13 -13
- data/lib/redd/objects/listing.rb +29 -29
- data/lib/redd/objects/more_comments.rb +11 -10
- data/lib/redd/objects/private_message.rb +28 -28
- data/lib/redd/objects/submission.rb +139 -139
- data/lib/redd/objects/subreddit.rb +330 -319
- data/lib/redd/objects/thing.rb +26 -26
- data/lib/redd/objects/thing/editable.rb +22 -22
- data/lib/redd/objects/thing/hideable.rb +18 -18
- data/lib/redd/objects/thing/inboxable.rb +25 -25
- data/lib/redd/objects/thing/messageable.rb +34 -34
- data/lib/redd/objects/thing/moderatable.rb +43 -43
- data/lib/redd/objects/thing/refreshable.rb +14 -14
- data/lib/redd/objects/thing/saveable.rb +21 -21
- data/lib/redd/objects/thing/votable.rb +33 -33
- data/lib/redd/objects/user.rb +52 -52
- data/lib/redd/objects/wiki_page.rb +15 -15
- data/lib/redd/rate_limit.rb +88 -88
- data/lib/redd/response/parse_json.rb +18 -18
- data/lib/redd/response/raise_error.rb +16 -16
- data/lib/redd/version.rb +4 -4
- data/redd.gemspec +31 -31
- data/spec/redd/objects/base_spec.rb +1 -1
- data/spec/redd/response/raise_error_spec.rb +11 -11
- data/spec/redd_spec.rb +5 -5
- data/spec/spec_helper.rb +71 -71
- metadata +21 -21
data/lib/redd/objects/base.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
require "hashie"
|
2
|
-
require "forwardable"
|
3
|
-
|
4
|
-
module Redd
|
5
|
-
# A bunch of objects that can hold properties.
|
6
|
-
module Objects
|
7
|
-
# A base for all objects to inherit from.
|
8
|
-
class Base < Hashie::Hash
|
9
|
-
include Hashie::Extensions::MergeInitializer
|
10
|
-
include Hashie::Extensions::MethodReader
|
11
|
-
include Hashie::Extensions::MethodQuery
|
12
|
-
include Hashie::Extensions::DeepMerge
|
13
|
-
|
14
|
-
# The `delete` method is called `delete_path` because it conflicts with
|
15
|
-
# Hash#delete.
|
16
|
-
extend Forwardable
|
17
|
-
def_delegators :@client, :get, :post, :put, :delete_path
|
18
|
-
|
19
|
-
# @!attribute [r] client
|
20
|
-
# @return [Clients::Base] The client that used to make requests.
|
21
|
-
attr_reader :client
|
22
|
-
|
23
|
-
# @param [Clients::Base] client The client instance.
|
24
|
-
# @param [Hash] attributes A hash of attributes.
|
25
|
-
def initialize(client, attributes = {})
|
26
|
-
@client = client
|
27
|
-
super(attributes)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Define an alias for a property.
|
31
|
-
# @param [Symbol] new_name The alias.
|
32
|
-
# @param [Symbol] old_name The existing property.
|
33
|
-
def self.alias_property(new_name, old_name)
|
34
|
-
define_method(new_name) { send(old_name) }
|
35
|
-
define_method(:"#{new_name}?") { send(old_name) }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
require "hashie"
|
2
|
+
require "forwardable"
|
3
|
+
|
4
|
+
module Redd
|
5
|
+
# A bunch of objects that can hold properties.
|
6
|
+
module Objects
|
7
|
+
# A base for all objects to inherit from.
|
8
|
+
class Base < Hashie::Hash
|
9
|
+
include Hashie::Extensions::MergeInitializer
|
10
|
+
include Hashie::Extensions::MethodReader
|
11
|
+
include Hashie::Extensions::MethodQuery
|
12
|
+
include Hashie::Extensions::DeepMerge
|
13
|
+
|
14
|
+
# The `delete` method is called `delete_path` because it conflicts with
|
15
|
+
# Hash#delete.
|
16
|
+
extend Forwardable
|
17
|
+
def_delegators :@client, :get, :post, :put, :delete_path
|
18
|
+
|
19
|
+
# @!attribute [r] client
|
20
|
+
# @return [Clients::Base] The client that used to make requests.
|
21
|
+
attr_reader :client
|
22
|
+
|
23
|
+
# @param [Clients::Base] client The client instance.
|
24
|
+
# @param [Hash] attributes A hash of attributes.
|
25
|
+
def initialize(client, attributes = {})
|
26
|
+
@client = client
|
27
|
+
super(attributes)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Define an alias for a property.
|
31
|
+
# @param [Symbol] new_name The alias.
|
32
|
+
# @param [Symbol] old_name The existing property.
|
33
|
+
def self.alias_property(new_name, old_name)
|
34
|
+
define_method(new_name) { send(old_name) }
|
35
|
+
define_method(:"#{new_name}?") { send(old_name) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/redd/objects/comment.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require_relative "thing"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
module Objects
|
5
|
-
# A comment that can be made on a link.
|
6
|
-
class Comment < Thing
|
7
|
-
include Thing::Editable
|
8
|
-
include Thing::Inboxable
|
9
|
-
include Thing::Moderatable
|
10
|
-
include Thing::Refreshable
|
11
|
-
include Thing::Saveable
|
12
|
-
include Thing::Votable
|
13
|
-
|
14
|
-
alias_property :reports_count, :num_reports
|
15
|
-
|
16
|
-
# @return [Listing] The comment's replies.
|
17
|
-
def replies
|
18
|
-
@replies ||= (client.object_from_body(self[:replies]) || [])
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
1
|
+
require_relative "thing"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
module Objects
|
5
|
+
# A comment that can be made on a link.
|
6
|
+
class Comment < Thing
|
7
|
+
include Thing::Editable
|
8
|
+
include Thing::Inboxable
|
9
|
+
include Thing::Moderatable
|
10
|
+
include Thing::Refreshable
|
11
|
+
include Thing::Saveable
|
12
|
+
include Thing::Votable
|
13
|
+
|
14
|
+
alias_property :reports_count, :num_reports
|
15
|
+
|
16
|
+
# @return [Listing] The comment's replies.
|
17
|
+
def replies
|
18
|
+
@replies ||= (client.object_from_body(self[:replies]) || [])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
# A comment that can be made on a link.
|
4
|
-
class LabeledMulti < Base
|
5
|
-
# @see Objects::Base
|
6
|
-
def initialize(client, attributes = {})
|
7
|
-
attr_dup = attributes.dup
|
8
|
-
attr_dup[:subreddits].map! { |sub| sub[:name] }
|
9
|
-
super(client, attr_dup)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
# A comment that can be made on a link.
|
4
|
+
class LabeledMulti < Base
|
5
|
+
# @see Objects::Base
|
6
|
+
def initialize(client, attributes = {})
|
7
|
+
attr_dup = attributes.dup
|
8
|
+
attr_dup[:subreddits].map! { |sub| sub[:name] }
|
9
|
+
super(client, attr_dup)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/redd/objects/listing.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
# A collection of reddit things.
|
4
|
-
# @see https://www.reddit.com/dev/api#listings
|
5
|
-
class Listing < Array
|
6
|
-
# @!attribute [r] before
|
7
|
-
# @return [String] The id of the object before the listing.
|
8
|
-
attr_reader :before
|
9
|
-
|
10
|
-
# @!attribute [r] after
|
11
|
-
# @return [String] The id of the object after the listing.
|
12
|
-
attr_reader :after
|
13
|
-
|
14
|
-
# @param [Clients::Base] client The client to expand the comments with.
|
15
|
-
# @param [{:before => String, :after => String,
|
16
|
-
# :children => Array<Hash>}] attributes The data to initialize the
|
17
|
-
# class with.
|
18
|
-
# @todo Only call Clients::Base#object_from_body when item is being
|
19
|
-
# accessed.
|
20
|
-
def initialize(client, attributes)
|
21
|
-
@before = attributes[:before]
|
22
|
-
@after = attributes[:after]
|
23
|
-
attributes[:children].each do |child|
|
24
|
-
self << (client.object_from_body(child) || child)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
# A collection of reddit things.
|
4
|
+
# @see https://www.reddit.com/dev/api#listings
|
5
|
+
class Listing < Array
|
6
|
+
# @!attribute [r] before
|
7
|
+
# @return [String] The id of the object before the listing.
|
8
|
+
attr_reader :before
|
9
|
+
|
10
|
+
# @!attribute [r] after
|
11
|
+
# @return [String] The id of the object after the listing.
|
12
|
+
attr_reader :after
|
13
|
+
|
14
|
+
# @param [Clients::Base] client The client to expand the comments with.
|
15
|
+
# @param [{:before => String, :after => String,
|
16
|
+
# :children => Array<Hash>}] attributes The data to initialize the
|
17
|
+
# class with.
|
18
|
+
# @todo Only call Clients::Base#object_from_body when item is being
|
19
|
+
# accessed.
|
20
|
+
def initialize(client, attributes)
|
21
|
+
@before = attributes[:before]
|
22
|
+
@after = attributes[:after]
|
23
|
+
attributes[:children].each do |child|
|
24
|
+
self << (client.object_from_body(child) || child)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
# The model for a morecomments object
|
4
|
-
class MoreComments < Array
|
5
|
-
def initialize(_, attributes)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
# The model for a morecomments object
|
4
|
+
class MoreComments < Array
|
5
|
+
def initialize(_, attributes)
|
6
|
+
#Return an empty arrar if there are no children
|
7
|
+
super(attributes[:children]) if attributes[:children]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
require_relative "thing"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
module Objects
|
5
|
-
# The model for private messages
|
6
|
-
class PrivateMessage < Thing
|
7
|
-
include Thing::Inboxable
|
8
|
-
|
9
|
-
alias_property :from, :author
|
10
|
-
alias_property :to, :dest
|
11
|
-
|
12
|
-
# Block the sender of the message from sending any more.
|
13
|
-
def block_sender!
|
14
|
-
post("/api/block", id: fullname)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Mark the message as read.
|
18
|
-
def mark_as_read
|
19
|
-
post("/api/read_message", id: fullname)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Mark the message as unread and add orangered to account.
|
23
|
-
def mark_as_unread
|
24
|
-
post("/api/unread_message", id: fullname)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
require_relative "thing"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
module Objects
|
5
|
+
# The model for private messages
|
6
|
+
class PrivateMessage < Thing
|
7
|
+
include Thing::Inboxable
|
8
|
+
|
9
|
+
alias_property :from, :author
|
10
|
+
alias_property :to, :dest
|
11
|
+
|
12
|
+
# Block the sender of the message from sending any more.
|
13
|
+
def block_sender!
|
14
|
+
post("/api/block", id: fullname)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Mark the message as read.
|
18
|
+
def mark_as_read
|
19
|
+
post("/api/read_message", id: fullname)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Mark the message as unread and add orangered to account.
|
23
|
+
def mark_as_unread
|
24
|
+
post("/api/unread_message", id: fullname)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,139 +1,139 @@
|
|
1
|
-
require_relative "thing"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
module Objects
|
5
|
-
# A submission made in a subreddit.
|
6
|
-
class Submission < Thing
|
7
|
-
include Thing::Editable
|
8
|
-
include Thing::Hideable
|
9
|
-
include Thing::Moderatable
|
10
|
-
include Thing::Refreshable
|
11
|
-
include Thing::Saveable
|
12
|
-
include Thing::Votable
|
13
|
-
|
14
|
-
alias_property :nsfw?, :over_18
|
15
|
-
alias_property :self?, :is_self
|
16
|
-
alias_property :comments_count, :num_comments
|
17
|
-
|
18
|
-
# The shorter url for sharing.
|
19
|
-
def short_url
|
20
|
-
"http://redd.it/#{self[:id]}"
|
21
|
-
end
|
22
|
-
|
23
|
-
# Whether the comment was gilded.
|
24
|
-
def gilded?
|
25
|
-
self[:gilded] > 0
|
26
|
-
end
|
27
|
-
|
28
|
-
# Mark the thing as Not Suitable For Work.
|
29
|
-
def mark_as_nsfw
|
30
|
-
get("/api/marknsfw", id: fullname)
|
31
|
-
self[:over_18] = true
|
32
|
-
end
|
33
|
-
|
34
|
-
# No longer mark the thing as Not Suitable For Work.
|
35
|
-
def unmark_as_nsfw
|
36
|
-
get("/api/unmarknsfw", id: fullname)
|
37
|
-
self[:over_18] = false
|
38
|
-
end
|
39
|
-
alias_method :mark_as_safe, :unmark_as_nsfw
|
40
|
-
|
41
|
-
# Reply to the thing.
|
42
|
-
# @param text [String] The text to comment.
|
43
|
-
# @return [Objects::Comment] The reply.
|
44
|
-
def add_comment(text)
|
45
|
-
client.add_comment(self, text)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Set the submission to "contest mode" (comments are randomly sorted)
|
49
|
-
def set_contest_mode
|
50
|
-
post("/api/set_contest_mode", id: fullname, state: true)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Unset the "contest mode".
|
54
|
-
def unset_contest_mode
|
55
|
-
post("/api/set_contest_mode", id: fullname, state: false)
|
56
|
-
end
|
57
|
-
|
58
|
-
# Set the submission as the sticky post of the subreddit
|
59
|
-
def set_sticky
|
60
|
-
post("/api/set_subreddit_sticky", id: fullname, state: true)
|
61
|
-
self[:stickied] = true
|
62
|
-
end
|
63
|
-
|
64
|
-
# Unsticky the post from the subreddit
|
65
|
-
def unset_sticky
|
66
|
-
post("/api/set_subreddit_sticky", id: fullname, state: false)
|
67
|
-
self[:stickied] = false
|
68
|
-
end
|
69
|
-
|
70
|
-
# @return [Listing] The submission's comments.
|
71
|
-
# @todo Allow for various depths and contexts and what not. Maybe a
|
72
|
-
# get_comment method?
|
73
|
-
def comments
|
74
|
-
refresh! unless @comments
|
75
|
-
@comments
|
76
|
-
end
|
77
|
-
alias_method :replies, :comments
|
78
|
-
|
79
|
-
# Refresh the submission AND its comments.
|
80
|
-
# @return [Submission] The updated submission.
|
81
|
-
def refresh!
|
82
|
-
body = get("/comments/#{id}.json").body
|
83
|
-
@comments = client.object_from_body(body[1])
|
84
|
-
deep_merge!(body[0])
|
85
|
-
end
|
86
|
-
|
87
|
-
# Take a MoreComments and return a listing of comments.
|
88
|
-
# @param [MoreComments] more The object to expand.
|
89
|
-
# @return [Listing] A listing of the expanded comments.
|
90
|
-
def expand_more(more)
|
91
|
-
response = client.get(
|
92
|
-
"/api/morechildren",
|
93
|
-
children: more.join(","),
|
94
|
-
link_id: fullname
|
95
|
-
)
|
96
|
-
|
97
|
-
client.object_from_body(
|
98
|
-
kind: "Listing",
|
99
|
-
data: {
|
100
|
-
before: "", after: "",
|
101
|
-
children: response.body[:json][:data][:things]
|
102
|
-
}
|
103
|
-
)
|
104
|
-
end
|
105
|
-
|
106
|
-
# Get the related articles.
|
107
|
-
# @param [Hash] params A list of params to send with the request.
|
108
|
-
# @option params [String] :after Return results after the given
|
109
|
-
# fullname.
|
110
|
-
# @option params [String] :before Return results before the given
|
111
|
-
# fullname.
|
112
|
-
# @option params [Integer] :count The number of items already seen
|
113
|
-
# in the listing.
|
114
|
-
# @option params [1..100] :limit The maximum number of things to
|
115
|
-
# return.
|
116
|
-
# @return [Objects::Listing<Objects::Thing>]
|
117
|
-
def get_related(**params)
|
118
|
-
related = get("/related/#{id}.json", params).body[1]
|
119
|
-
client.object_from_body(related)
|
120
|
-
end
|
121
|
-
|
122
|
-
# Get other articles with the same URL.
|
123
|
-
# @param [Hash] params A list of params to send with the request.
|
124
|
-
# @option params [String] :after Return results after the given
|
125
|
-
# fullname.
|
126
|
-
# @option params [String] :before Return results before the given
|
127
|
-
# fullname.
|
128
|
-
# @option params [Integer] :count The number of items already seen
|
129
|
-
# in the listing.
|
130
|
-
# @option params [1..100] :limit The maximum number of things to
|
131
|
-
# return.
|
132
|
-
# @return [Objects::Listing<Objects::Submission>]
|
133
|
-
def get_duplicates(**params)
|
134
|
-
duplicates = get("/duplicates/#{id}.json", params).body[1]
|
135
|
-
client.object_from_body(duplicates)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
1
|
+
require_relative "thing"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
module Objects
|
5
|
+
# A submission made in a subreddit.
|
6
|
+
class Submission < Thing
|
7
|
+
include Thing::Editable
|
8
|
+
include Thing::Hideable
|
9
|
+
include Thing::Moderatable
|
10
|
+
include Thing::Refreshable
|
11
|
+
include Thing::Saveable
|
12
|
+
include Thing::Votable
|
13
|
+
|
14
|
+
alias_property :nsfw?, :over_18
|
15
|
+
alias_property :self?, :is_self
|
16
|
+
alias_property :comments_count, :num_comments
|
17
|
+
|
18
|
+
# The shorter url for sharing.
|
19
|
+
def short_url
|
20
|
+
"http://redd.it/#{self[:id]}"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Whether the comment was gilded.
|
24
|
+
def gilded?
|
25
|
+
self[:gilded] > 0
|
26
|
+
end
|
27
|
+
|
28
|
+
# Mark the thing as Not Suitable For Work.
|
29
|
+
def mark_as_nsfw
|
30
|
+
get("/api/marknsfw", id: fullname)
|
31
|
+
self[:over_18] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# No longer mark the thing as Not Suitable For Work.
|
35
|
+
def unmark_as_nsfw
|
36
|
+
get("/api/unmarknsfw", id: fullname)
|
37
|
+
self[:over_18] = false
|
38
|
+
end
|
39
|
+
alias_method :mark_as_safe, :unmark_as_nsfw
|
40
|
+
|
41
|
+
# Reply to the thing.
|
42
|
+
# @param text [String] The text to comment.
|
43
|
+
# @return [Objects::Comment] The reply.
|
44
|
+
def add_comment(text)
|
45
|
+
client.add_comment(self, text)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Set the submission to "contest mode" (comments are randomly sorted)
|
49
|
+
def set_contest_mode
|
50
|
+
post("/api/set_contest_mode", id: fullname, state: true)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Unset the "contest mode".
|
54
|
+
def unset_contest_mode
|
55
|
+
post("/api/set_contest_mode", id: fullname, state: false)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Set the submission as the sticky post of the subreddit
|
59
|
+
def set_sticky
|
60
|
+
post("/api/set_subreddit_sticky", id: fullname, state: true)
|
61
|
+
self[:stickied] = true
|
62
|
+
end
|
63
|
+
|
64
|
+
# Unsticky the post from the subreddit
|
65
|
+
def unset_sticky
|
66
|
+
post("/api/set_subreddit_sticky", id: fullname, state: false)
|
67
|
+
self[:stickied] = false
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Listing] The submission's comments.
|
71
|
+
# @todo Allow for various depths and contexts and what not. Maybe a
|
72
|
+
# get_comment method?
|
73
|
+
def comments
|
74
|
+
refresh! unless @comments
|
75
|
+
@comments
|
76
|
+
end
|
77
|
+
alias_method :replies, :comments
|
78
|
+
|
79
|
+
# Refresh the submission AND its comments.
|
80
|
+
# @return [Submission] The updated submission.
|
81
|
+
def refresh!
|
82
|
+
body = get("/comments/#{id}.json").body
|
83
|
+
@comments = client.object_from_body(body[1])
|
84
|
+
deep_merge!(body[0])
|
85
|
+
end
|
86
|
+
|
87
|
+
# Take a MoreComments and return a listing of comments.
|
88
|
+
# @param [MoreComments] more The object to expand.
|
89
|
+
# @return [Listing] A listing of the expanded comments.
|
90
|
+
def expand_more(more)
|
91
|
+
response = client.get(
|
92
|
+
"/api/morechildren",
|
93
|
+
children: more.join(","),
|
94
|
+
link_id: fullname
|
95
|
+
)
|
96
|
+
|
97
|
+
client.object_from_body(
|
98
|
+
kind: "Listing",
|
99
|
+
data: {
|
100
|
+
before: "", after: "",
|
101
|
+
children: response.body[:json][:data][:things]
|
102
|
+
}
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Get the related articles.
|
107
|
+
# @param [Hash] params A list of params to send with the request.
|
108
|
+
# @option params [String] :after Return results after the given
|
109
|
+
# fullname.
|
110
|
+
# @option params [String] :before Return results before the given
|
111
|
+
# fullname.
|
112
|
+
# @option params [Integer] :count The number of items already seen
|
113
|
+
# in the listing.
|
114
|
+
# @option params [1..100] :limit The maximum number of things to
|
115
|
+
# return.
|
116
|
+
# @return [Objects::Listing<Objects::Thing>]
|
117
|
+
def get_related(**params)
|
118
|
+
related = get("/related/#{id}.json", params).body[1]
|
119
|
+
client.object_from_body(related)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Get other articles with the same URL.
|
123
|
+
# @param [Hash] params A list of params to send with the request.
|
124
|
+
# @option params [String] :after Return results after the given
|
125
|
+
# fullname.
|
126
|
+
# @option params [String] :before Return results before the given
|
127
|
+
# fullname.
|
128
|
+
# @option params [Integer] :count The number of items already seen
|
129
|
+
# in the listing.
|
130
|
+
# @option params [1..100] :limit The maximum number of things to
|
131
|
+
# return.
|
132
|
+
# @return [Objects::Listing<Objects::Submission>]
|
133
|
+
def get_duplicates(**params)
|
134
|
+
duplicates = get("/duplicates/#{id}.json", params).body[1]
|
135
|
+
client.object_from_body(duplicates)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|