Class: Redd::Models::Submission

Inherits:
Model
  • Object
show all
Includes:
Gildable, Moderatable, Postable, Replyable, Reportable
Defined in:
lib/redd/models/submission.rb

Overview

A text or link post.

Instance Attribute Summary collapse

Attributes inherited from Model

#client

Instance Method Summary collapse

Methods included from Reportable

#report

Methods included from Replyable

#reply

Methods included from Postable

#delete, #deleted?, #disable_inbox_replies, #downvote, #edit, #enable_inbox_replies, #hide, #save, #undo_vote, #unhide, #unsave, #upvote

Methods included from Moderatable

#approve, #distinguish, #ignore_reports, #remove, #undistinguish, #unignore_reports

Methods included from Gildable

#gild

Methods inherited from Model

#initialize

Constructor Details

This class inherits a constructor from Redd::Models::Model

Instance Attribute Details

#approved_atTime? (readonly)

Returns when the submission was last approved.

Returns:

  • (Time, nil)

    when the submission was last approved


119
# File 'lib/redd/models/submission.rb', line 119

property :approved_at, from: :approved_at_utc, with: ->(t) { Time.at(t) if t }

#approved_byObject (readonly)

Returns the person that approved this post (not sure about the schema).

Returns:

  • (Object)

    the person that approved this post (not sure about the schema)


219
# File 'lib/redd/models/submission.rb', line 219

property :approved_by

#archived?Boolean (readonly)

Returns whether the post is archived.

Returns:

  • (Boolean)

    whether the post is archived


179
# File 'lib/redd/models/submission.rb', line 179

property :archived?, from: :archived

#authorUser (readonly)

Returns the post author.

Returns:

  • (User)

    the post author


341
# File 'lib/redd/models/submission.rb', line 341

property :author, with: ->(n) { User.new(client, name: n) }

#author_flair_css_classString (readonly)

Returns the author flair css class.

Returns:

  • (String)

    the author flair css class


259
# File 'lib/redd/models/submission.rb', line 259

property :author_flair_css_class

#author_flair_textString (readonly)

Returns the author flair text.

Returns:

  • (String)

    the author flair text


255
# File 'lib/redd/models/submission.rb', line 255

property :author_flair_text

#banned_atTime? (readonly)

Returns the time the post was banned.

Returns:

  • (Time, nil)

    the time the post was banned


171
# File 'lib/redd/models/submission.rb', line 171

property :banned_at, from: :banned_at_utc, with: ->(t) { Time.at(t) if t }

#banned_byString (readonly)

Returns not sure what this does.

Returns:

  • (String)

    not sure what this does


123
# File 'lib/redd/models/submission.rb', line 123

property :banned_by

#brand_safe?Boolean (readonly)

Returns whether the post is marked as brand safe.

Returns:

  • (Boolean)

    whether the post is marked as brand safe


285
# File 'lib/redd/models/submission.rb', line 285

property :brand_safe?, from: :brand_safe

#can_gild?Boolean (readonly)

Returns whether the user can gild this post.

Returns:

  • (Boolean)

    whether the user can gild this post


301
# File 'lib/redd/models/submission.rb', line 301

property :can_gild?, from: :can_gild

#can_mod_post?Boolean (readonly)

Returns whether you can post as a mod, i think.

Returns:

  • (Boolean)

    whether you can post as a mod, i think


203
# File 'lib/redd/models/submission.rb', line 203

property :can_mod_post?, from: :can_mod_post

#clicked?Boolean (readonly)

Returns whether the post was clicked.

Returns:

  • (Boolean)

    whether the post was clicked


183
# File 'lib/redd/models/submission.rb', line 183

property :clicked?, from: :clicked

#comment_countInteger (readonly)

Returns the post's comment count.

Returns:

  • (Integer)

    the post's comment count


235
# File 'lib/redd/models/submission.rb', line 235

property :comment_count, from: :num_comments

#commentsArray<Comment> (readonly)

Returns the comment tree.

Returns:

  • (Array<Comment>)

    the comment tree


111
# File 'lib/redd/models/submission.rb', line 111

property :comments, :nil, with: ->(l) { Listing.new(client, l) if l }

#contest_mode_enabled?Boolean (readonly)

Returns whether contest mode is turned on.

Returns:

  • (Boolean)

    whether contest mode is turned on


263
# File 'lib/redd/models/submission.rb', line 263

property :contest_mode_enabled?, from: :contest_mode

#created_atTime (readonly)

Returns creation time.

Returns:

  • (Time)

    creation time


345
# File 'lib/redd/models/submission.rb', line 345

property :created_at, from: :created_utc, with: ->(t) { Time.at(t) }

#crosspostable?Boolean (readonly)

Returns whether the post can be crossposted.

Returns:

  • (Boolean)

    whether the post can be crossposted


207
# File 'lib/redd/models/submission.rb', line 207

property :crosspostable?, from: :is_crosspostable

#distinguished?Boolean (readonly)

Returns whether the post is distinguished.

Returns:

  • (Boolean)

    whether the post is distinguished


354
# File 'lib/redd/models/submission.rb', line 354

property :distinguished?, from: :distinguished

#domainString (readonly)

Returns the domain name of the link (or self.subreddit_name).

Returns:

  • (String)

    the domain name of the link (or self.subreddit_name)


115
# File 'lib/redd/models/submission.rb', line 115

property :domain

#downsInteger (readonly)

Deprecated.

this always returns zero - use #score instead

Returns downvote count.

Returns:

  • (Integer)

    downvote count


281
# File 'lib/redd/models/submission.rb', line 281

property :downs

#editedTime, false (readonly)

Returns the time of the last edit.

Returns:

  • (Time, false)

    the time of the last edit


251
# File 'lib/redd/models/submission.rb', line 251

property :edited, with: ->(t) { Time.at(t) if t }

#gildedInteger (readonly)

Returns the number of times the post was gilded.

Returns:

  • (Integer)

    the number of times the post was gilded


267
# File 'lib/redd/models/submission.rb', line 267

property :gilded

#hidden?Boolean (readonly)

Returns whether the logged-in user hid the post.

Returns:

  • (Boolean)

    whether the logged-in user hid the post


227
# File 'lib/redd/models/submission.rb', line 227

property :hidden?, from: :hidden

#idString (readonly)

Returns the submission id.

Returns:

  • (String)

    the submission id


167
# File 'lib/redd/models/submission.rb', line 167

property :id

Returns the link flair css class.

Returns:

  • (String)

    the link flair css class


163
# File 'lib/redd/models/submission.rb', line 163

property :link_flair_css_class

Returns the link flair text.

Returns:

  • (String)

    the link flair text


159
# File 'lib/redd/models/submission.rb', line 159

property :link_flair_text

#locked?Boolean (readonly)

Returns whether the post is locked.

Returns:

  • (Boolean)

    whether the post is locked


271
# File 'lib/redd/models/submission.rb', line 271

property :locked?, from: :locked

#mediaHash (readonly)

Returns media details.

Returns:

  • (Hash)

    media details


358
# File 'lib/redd/models/submission.rb', line 358

property :media

#media_embedHash (readonly)

Returns media embed properties.

Returns:

  • (Hash)

    media embed properties


127
# File 'lib/redd/models/submission.rb', line 127

property :media_embed

#mod_reportsArray (readonly)

Returns moderator reports.

Returns:

  • (Array)

    moderator reports


366
# File 'lib/redd/models/submission.rb', line 366

property :mod_reports

#nameString (readonly)

Returns the fullname (i.e. t3_xxxxxx).

Returns:

  • (String)

    the fullname (i.e. t3_xxxxxx)


309
# File 'lib/redd/models/submission.rb', line 309

property :name

#num_crosspostsInteger (readonly)

Returns the number of crossposts made to other subreddits.

Returns:

  • (Integer)

    the number of crossposts made to other subreddits


195
# File 'lib/redd/models/submission.rb', line 195

property :num_crossposts

#over_18?Boolean (readonly)

Returns whether the post is marked as over 18.

Returns:

  • (Boolean)

    whether the post is marked as over 18


223
# File 'lib/redd/models/submission.rb', line 223

property :over_18?, from: :over_18

#parent_whitelist_statusString (readonly)

Returns ad-related whitelist stuff.

Returns:

  • (String)

    ad-related whitelist stuff


305
# File 'lib/redd/models/submission.rb', line 305

property :parent_whitelist_status

Returns the *relative* url permalink.

Returns:

  • (String)

    the *relative* url permalink


317
# File 'lib/redd/models/submission.rb', line 317

property :permalink

#pinned?Boolean (readonly)

Returns whether the post is pinned.

Returns:

  • (Boolean)

    whether the post is pinned


211
# File 'lib/redd/models/submission.rb', line 211

property :pinned?, from: :pinned

#post_hintString (readonly)

Returns a hint at what the link should contain.

Returns:

  • (String)

    a hint at what the link should contain


297
# File 'lib/redd/models/submission.rb', line 297

property :post_hint

#previewHash (readonly)

Returns preview details.

Returns:

  • (Hash)

    preview details


231
# File 'lib/redd/models/submission.rb', line 231

property :preview

#quarantined?Boolean (readonly)

Returns whether the post has been quarantined.

Returns:

  • (Boolean)

    whether the post has been quarantined


337
# File 'lib/redd/models/submission.rb', line 337

property :quarantined?, from: :quarantine

#removal_reasonString (readonly)

Returns the removal reason.

Returns:

  • (String)

    the removal reason


293
# File 'lib/redd/models/submission.rb', line 293

property :removal_reason

#report_countInteger (readonly)

Returns the number of reports.

Returns:

  • (Integer)

    the number of reports


321
# File 'lib/redd/models/submission.rb', line 321

property :report_count, from: :num_reports

#report_reasonsObject (readonly)

Returns i think it's an array of strings?.

Returns:

  • (Object)

    i think it's an array of strings?


187
# File 'lib/redd/models/submission.rb', line 187

property :report_reasons

#saved?String (readonly)

Returns whether the post was saved by the logged-in user.

Returns:

  • (String)

    whether the post was saved by the logged-in user


199
# File 'lib/redd/models/submission.rb', line 199

property :saved?, from: :saved

#scoreInteger (readonly)

Returns the post's score.

Returns:

  • (Integer)

    the post's score


215
# File 'lib/redd/models/submission.rb', line 215

property :score

#score_hidden?Boolean (readonly)

Returns whether the score is hidden.

Returns:

  • (Boolean)

    whether the score is hidden


247
# File 'lib/redd/models/submission.rb', line 247

property :score_hidden?, from: :hide_score

#secure_mediaHash? (readonly)

Returns secure media details.

Returns:

  • (Hash, nil)

    secure media details


155
# File 'lib/redd/models/submission.rb', line 155

property :secure_media

#secure_media_embedHash (readonly)

Returns secure media embed details.

Returns:

  • (Hash)

    secure media embed details


289
# File 'lib/redd/models/submission.rb', line 289

property :secure_media_embed

#self?Boolean (readonly)

Returns whether the post is a self post.

Returns:

  • (Boolean)

    whether the post is a self post


370
# File 'lib/redd/models/submission.rb', line 370

property :self?, from: :is_self

#selftextString (readonly)

Returns the self text contents.

Returns:

  • (String)

    the self text contents


139
# File 'lib/redd/models/submission.rb', line 139

property :selftext

#selftext_htmlString? (readonly)

Returns the html-rendered self text, can be nil if link.

Returns:

  • (String, nil)

    the html-rendered self text, can be nil if link


135
# File 'lib/redd/models/submission.rb', line 135

property :selftext_html

#sort_orderSymbol (readonly)

Returns the comment sort order.

Returns:

  • (Symbol)

    the comment sort order


24
25
26
# File 'lib/redd/models/submission.rb', line 24

def sort_order
  exists_locally?(:sort_order) ? read_attribute(:sort_order) : nil
end

#spoiler?Boolean (readonly)

Returns whether the post was marked as a spoiler.

Returns:

  • (Boolean)

    whether the post was marked as a spoiler


313
# File 'lib/redd/models/submission.rb', line 313

property :spoiler?, from: :spoiler

#stickied?Boolean (readonly)

Returns whether the post was stickied.

Returns:

  • (Boolean)

    whether the post was stickied


329
# File 'lib/redd/models/submission.rb', line 329

property :stickied?, from: :stickied

#subredditSubreddit (readonly)

Returns the subreddit the post belongs to.

Returns:

  • (Subreddit)

    the subreddit the post belongs to.


131
# File 'lib/redd/models/submission.rb', line 131

property :subreddit, with: ->(n) { Subreddit.new(client, display_name: n) }

#subreddit_name_prefixedString (readonly)

Returns r/[subreddit name].

Returns:

  • (String)

    r/[subreddit name]


349
350
# File 'lib/redd/models/submission.rb', line 349

property :subreddit_name_prefixed,
default: ->() { "r/#{read_attribute(:subreddit).display_name}" }

#subreddit_typeString (readonly)

Returns the subreddit's type.

Returns:

  • (String)

    the subreddit's type


378
# File 'lib/redd/models/submission.rb', line 378

property :subreddit_type

#suggested_sortString? (readonly)

Returns the suggested sort.

Returns:

  • (String, nil)

    the suggested sort


147
# File 'lib/redd/models/submission.rb', line 147

property :suggested_sort

#thumbnailString (readonly)

Returns the thumbnail url.

Returns:

  • (String)

    the thumbnail url


239
# File 'lib/redd/models/submission.rb', line 239

property :thumbnail

#thumbnail_heightInteger (readonly)

Returns thumbnail height.

Returns:

  • (Integer)

    thumbnail height


243
# File 'lib/redd/models/submission.rb', line 243

property :thumbnail_height

#titleString (readonly)

Returns the post title.

Returns:

  • (String)

    the post title


191
# File 'lib/redd/models/submission.rb', line 191

property :title

#upsInteger (readonly)

Deprecated.

this doesn't return the raw upvote count - use #score instead

Returns upvote count.

Returns:

  • (Integer)

    upvote count


276
# File 'lib/redd/models/submission.rb', line 276

property :ups

#upvote_ratioFloat (readonly)

Returns the upvote ratio (ups/downs).

Returns:

  • (Float)

    the upvote ratio (ups/downs)


362
# File 'lib/redd/models/submission.rb', line 362

property :upvote_ratio

#upvoted?Boolean? (readonly)

Returns whether the user upvoted/downvoted this post.

Returns:

  • (Boolean, nil)

    whether the user upvoted/downvoted this post


143
# File 'lib/redd/models/submission.rb', line 143

property :upvoted?, from: :likes

#urlString (readonly)

Returns the link url.

Returns:

  • (String)

    the link url


333
# File 'lib/redd/models/submission.rb', line 333

property :url

#user_reportsArray<String> (readonly)

Returns user reports.

Returns:

  • (Array<String>)

    user reports


151
# File 'lib/redd/models/submission.rb', line 151

property :user_reports

#video?Boolean (readonly)

Returns whether the post is probably a video.

Returns:

  • (Boolean)

    whether the post is probably a video


382
# File 'lib/redd/models/submission.rb', line 382

property :video, from: :is_video

#view_countInteger? (readonly)

Returns the view count.

Returns:

  • (Integer, nil)

    the view count


175
# File 'lib/redd/models/submission.rb', line 175

property :view_count

#visited?Boolean (readonly)

Returns whether the post was visited.

Returns:

  • (Boolean)

    whether the post was visited


374
# File 'lib/redd/models/submission.rb', line 374

property :visited?, from: :visited

#whitelist_statusString (readonly)

Returns ad-related whitelist stuff.

Returns:

  • (String)

    ad-related whitelist stuff


325
# File 'lib/redd/models/submission.rb', line 325

property :whitelist_status

Instance Method Details

#disable_contest_modeObject

Disable the “contest mode”.


73
74
75
# File 'lib/redd/models/submission.rb', line 73

def disable_contest_mode
  client.post('/api/set_contest_mode', id: read_attribute(:name), state: false)
end

#duplicates(**params) ⇒ Listing<Submission>

Get all submissions for the same url.

Parameters:

  • params (Hash)

    A list of optional params to send with the request.

Options Hash (**params):

  • :after (String)

    return results after the given fullname

  • :before (String)

    return results before the given fullname

  • :count (Integer) — default: 0

    the number of items already seen in the listing

  • :limit (1..100) — default: 25

    the maximum number of things to return

Returns:


43
44
45
# File 'lib/redd/models/submission.rb', line 43

def duplicates(**params)
  client.unmarshal(client.get("/duplicates/#{read_attribute(:id)}", params).body[1])
end

#enable_contest_modeObject

Set the submission to “contest mode” (comments are randomly sorted)


68
69
70
# File 'lib/redd/models/submission.rb', line 68

def enable_contest_mode
  client.post('/api/set_contest_mode', id: read_attribute(:name), state: true)
end

#lockObject

Prevent users from commenting on the link (and hide it as well).


89
90
91
# File 'lib/redd/models/submission.rb', line 89

def lock
  client.post('/api/lock', id: read_attribute(:name))
end

#make_sticky(slot: nil) ⇒ Object

Set the submission as the sticky post of the subreddit.

Parameters:

  • slot (1, 2) (defaults to: nil)

    which “slot” to place the sticky on


79
80
81
# File 'lib/redd/models/submission.rb', line 79

def make_sticky(slot: nil)
  client.post('/api/set_subreddit_sticky', id: read_attribute(:name), num: slot, state: true)
end

#mark_as_nsfwObject

Mark the link as “Not Suitable For Work”.


48
49
50
# File 'lib/redd/models/submission.rb', line 48

def mark_as_nsfw
  client.get('/api/marknsfw', id: read_attribute(:name))
end

#mark_as_spoilerObject

Mark the link as a spoiler.


58
59
60
# File 'lib/redd/models/submission.rb', line 58

def mark_as_spoiler
  client.get('/api/spoiler', id: read_attribute(:name))
end

#remove_stickyObject

Unsticky the post from the subreddit.


84
85
86
# File 'lib/redd/models/submission.rb', line 84

def remove_sticky
  client.post('/api/set_subreddit_sticky', id: read_attribute(:name), state: false)
end

#set_suggested_sort(suggested) ⇒ Object

Set the suggested sort order for comments for all users.

Parameters:

  • suggested ('blank', 'confidence', 'top', 'new', 'controversial', 'old', 'random', 'qa', 'live')

    the sort type


101
102
103
# File 'lib/redd/models/submission.rb', line 101

def set_suggested_sort(suggested) # rubocop:disable Naming/AccessorMethodName
  client.post('/api/set_suggested_sort', id: read_attribute(:name), sort: suggested)
end

#unlockObject

Allow users to comment on the link again.


94
95
96
# File 'lib/redd/models/submission.rb', line 94

def unlock
  client.post('/api/unlock', id: read_attribute(:name))
end

#unmark_as_nsfwObject

No longer mark the link as “Not Suitable For Work”.


53
54
55
# File 'lib/redd/models/submission.rb', line 53

def unmark_as_nsfw
  client.get('/api/unmarknsfw', id: read_attribute(:name))
end

#unmark_as_spoilerObject

No longer mark the link as a spoiler.


63
64
65
# File 'lib/redd/models/submission.rb', line 63

def unmark_as_spoiler
  client.get('/api/unspoiler', id: read_attribute(:name))
end

#update_sort_order(new_order) ⇒ Object

Set the sort order of the comments and reload the comments.

Parameters:

  • new_order (:confidence, :top, :controversial, :old, :qa)

    the sort order


30
31
32
33
34
# File 'lib/redd/models/submission.rb', line 30

def update_sort_order(new_order)
  return self if new_order == read_attribute(:sort_order)
  write_attribute(:sort_order, new_order)
  reload
end