class Redd::Objects::Submission

A submission made in a subreddit.

Public Instance Methods

add_comment(text) click to toggle source

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
comments() click to toggle source

@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
Also aliased as: replies
expand_more(more) click to toggle source

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_duplicates(**params) click to toggle source

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
gilded?() click to toggle source

Whether the comment was gilded.

# File lib/redd/objects/submission.rb, line 24
def gilded?
  self[:gilded] > 0
end
mark_as_nsfw() click to toggle source

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
mark_as_safe()
Alias for: unmark_as_nsfw
refresh!() click to toggle source

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
replies()
Alias for: comments
set_contest_mode() click to toggle source

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_sticky() click to toggle source

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
short_url() click to toggle source

The shorter url for sharing.

# File lib/redd/objects/submission.rb, line 19
def short_url
  "http://redd.it/#{self[:id]}"
end
unmark_as_nsfw() click to toggle source

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
Also aliased as: mark_as_safe
unset_contest_mode() click to toggle source

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
unset_sticky() click to toggle source

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