class Redd::Objects::Submission
A submission made in a subreddit.
Public Instance Methods
Reply to the thing. @param text [String] The text to comment. @return [Objects::Comment] The reply.
# File lib/redd/objects/submission.rb, line 44 def add_comment(text) client.add_comment(self, text) end
@return [Listing] The submission's comments. @todo Allow for various depths and contexts and what not. Maybe a
get_comment method?
# File lib/redd/objects/submission.rb, line 73 def comments refresh! unless @comments @comments end
Take a MoreComments
and return a listing of comments. @param [MoreComments] more The object to expand. @return [Listing] A listing of the expanded comments. rubocop:disable Metrics/MethodLength
# File lib/redd/objects/submission.rb, line 91 def expand_more(more) response = client.get( '/api/morechildren', children: more.join(','), link_id: fullname ) client.object_from_body( kind: 'Listing', data: { before: '', after: '', children: response.body[:json][:data][:things] } ) end
Get other articles with the same URL. @param [Hash] params A list of params to send with the request. @option params [String] :after Return results after the given
fullname.
@option params [String] :before Return results before the given
fullname.
@option params [Integer] :count The number of items already seen
in the listing.
@option params [1..100] :limit The maximum number of things to
return.
@return [Objects::Listing<Objects::Submission>]
# File lib/redd/objects/submission.rb, line 134 def get_duplicates(**params) duplicates = get("/duplicates/#{id}.json", params).body[1] client.object_from_body(duplicates) end
Whether the comment was gilded.
# File lib/redd/objects/submission.rb, line 24 def gilded? self[:gilded] > 0 end
Mark the thing as Not Suitable For Work.
# File lib/redd/objects/submission.rb, line 29 def mark_as_nsfw get('/api/marknsfw', id: fullname) self[:over_18] = true end
Refresh the submission AND its comments. @return [Submission] The updated submission.
# File lib/redd/objects/submission.rb, line 81 def refresh! body = get("/comments/#{id}.json").body @comments = client.object_from_body(body[1]) deep_merge!(body[0]) end
Set the submission to “contest mode” (comments are randomly sorted)
# File lib/redd/objects/submission.rb, line 49 def set_contest_mode post('/api/set_contest_mode', id: fullname, state: true) end
Set the submission as the sticky post of the subreddit
# File lib/redd/objects/submission.rb, line 59 def set_sticky post('/api/set_subreddit_sticky', id: fullname, state: true) self[:stickied] = true end
The shorter url for sharing.
# File lib/redd/objects/submission.rb, line 19 def short_url "http://redd.it/#{self[:id]}" end
No longer mark the thing as Not Suitable For Work.
# File lib/redd/objects/submission.rb, line 35 def unmark_as_nsfw get('/api/unmarknsfw', id: fullname) self[:over_18] = false end
Unset the “contest mode”.
# File lib/redd/objects/submission.rb, line 54 def unset_contest_mode post('/api/set_contest_mode', id: fullname, state: false) end
Unsticky the post from the subreddit
# File lib/redd/objects/submission.rb, line 65 def unset_sticky post('/api/set_subreddit_sticky', id: fullname, state: false) self[:stickied] = false end