Class: Redd::Models::Submission
- Includes:
- Gildable, Moderatable, Postable, Replyable, Reportable
- Defined in:
- lib/redd/models/submission.rb
Overview
A text or link post.
Instance Attribute Summary collapse
-
#approved_at ⇒ Time?
readonly
When the submission was last approved.
-
#approved_by ⇒ Object
readonly
The person that approved this post (not sure about the schema).
-
#archived? ⇒ Boolean
readonly
Whether the post is archived.
-
#author ⇒ User
readonly
The post author.
-
#author_flair_css_class ⇒ String
readonly
The author flair css class.
-
#author_flair_text ⇒ String
readonly
The author flair text.
-
#banned_at ⇒ Time?
readonly
The time the post was banned.
-
#banned_by ⇒ String
readonly
Not sure what this does.
-
#brand_safe? ⇒ Boolean
readonly
Whether the post is marked as brand safe.
-
#can_gild? ⇒ Boolean
readonly
Whether the user can gild this post.
-
#can_mod_post? ⇒ Boolean
readonly
Whether you can post as a mod, i think.
-
#clicked? ⇒ Boolean
readonly
Whether the post was clicked.
-
#comment_count ⇒ Integer
readonly
The post's comment count.
-
#comments ⇒ Array<Comment>
readonly
The comment tree.
-
#contest_mode_enabled? ⇒ Boolean
readonly
Whether contest mode is turned on.
-
#created_at ⇒ Time
readonly
Creation time.
-
#crosspostable? ⇒ Boolean
readonly
Whether the post can be crossposted.
-
#distinguished? ⇒ Boolean
readonly
Whether the post is distinguished.
-
#domain ⇒ String
readonly
The domain name of the link (or self.subreddit_name).
-
#downs ⇒ Integer
readonly
deprecated
Deprecated.
this always returns zero - use #score instead
-
#edited ⇒ Time, false
readonly
The time of the last edit.
-
#gilded ⇒ Integer
readonly
The number of times the post was gilded.
-
#hidden? ⇒ Boolean
readonly
Whether the logged-in user hid the post.
-
#id ⇒ String
readonly
The submission id.
-
#link_flair_css_class ⇒ String
readonly
The link flair css class.
-
#link_flair_text ⇒ String
readonly
The link flair text.
-
#locked? ⇒ Boolean
readonly
Whether the post is locked.
-
#media ⇒ Hash
readonly
Media details.
-
#media_embed ⇒ Hash
readonly
Media embed properties.
-
#mod_reports ⇒ Array
readonly
Moderator reports.
-
#name ⇒ String
readonly
The fullname (i.e. t3_xxxxxx).
-
#num_crossposts ⇒ Integer
readonly
The number of crossposts made to other subreddits.
-
#over_18? ⇒ Boolean
readonly
Whether the post is marked as over 18.
-
#parent_whitelist_status ⇒ String
readonly
Ad-related whitelist stuff.
-
#permalink ⇒ String
readonly
The *relative* url permalink.
-
#pinned? ⇒ Boolean
readonly
Whether the post is pinned.
-
#post_hint ⇒ String
readonly
A hint at what the link should contain.
-
#preview ⇒ Hash
readonly
Preview details.
-
#quarantined? ⇒ Boolean
readonly
Whether the post has been quarantined.
-
#removal_reason ⇒ String
readonly
The removal reason.
-
#report_count ⇒ Integer
readonly
The number of reports.
-
#report_reasons ⇒ Object
readonly
I think it's an array of strings?.
-
#saved? ⇒ String
readonly
Whether the post was saved by the logged-in user.
-
#score ⇒ Integer
readonly
The post's score.
-
#score_hidden? ⇒ Boolean
readonly
Whether the score is hidden.
-
#secure_media ⇒ Hash?
readonly
Secure media details.
-
#secure_media_embed ⇒ Hash
readonly
Secure media embed details.
-
#self? ⇒ Boolean
readonly
Whether the post is a self post.
-
#selftext ⇒ String
readonly
The self text contents.
-
#selftext_html ⇒ String?
readonly
The html-rendered self text, can be nil if link.
-
#sort_order ⇒ Symbol
readonly
The comment sort order.
-
#spoiler? ⇒ Boolean
readonly
Whether the post was marked as a spoiler.
-
#stickied? ⇒ Boolean
readonly
Whether the post was stickied.
-
#subreddit ⇒ Subreddit
readonly
The subreddit the post belongs to.
-
#subreddit_name_prefixed ⇒ String
readonly
R/[subreddit name].
-
#subreddit_type ⇒ String
readonly
The subreddit's type.
-
#suggested_sort ⇒ String?
readonly
The suggested sort.
-
#thumbnail ⇒ String
readonly
The thumbnail url.
-
#thumbnail_height ⇒ Integer
readonly
Thumbnail height.
-
#title ⇒ String
readonly
The post title.
-
#ups ⇒ Integer
readonly
deprecated
Deprecated.
this doesn't return the raw upvote count - use #score instead
-
#upvote_ratio ⇒ Float
readonly
The upvote ratio (ups/downs).
-
#upvoted? ⇒ Boolean?
readonly
Whether the user upvoted/downvoted this post.
-
#url ⇒ String
readonly
The link url.
-
#user_reports ⇒ Array<String>
readonly
User reports.
-
#video? ⇒ Boolean
readonly
Whether the post is probably a video.
-
#view_count ⇒ Integer?
readonly
The view count.
-
#visited? ⇒ Boolean
readonly
Whether the post was visited.
-
#whitelist_status ⇒ String
readonly
Ad-related whitelist stuff.
Attributes inherited from Model
Instance Method Summary collapse
-
#disable_contest_mode ⇒ Object
Disable the “contest mode”.
-
#duplicates(**params) ⇒ Listing<Submission>
Get all submissions for the same url.
-
#enable_contest_mode ⇒ Object
Set the submission to “contest mode” (comments are randomly sorted).
-
#lock ⇒ Object
Prevent users from commenting on the link (and hide it as well).
-
#make_sticky(slot: nil) ⇒ Object
Set the submission as the sticky post of the subreddit.
-
#mark_as_nsfw ⇒ Object
Mark the link as “Not Suitable For Work”.
-
#mark_as_spoiler ⇒ Object
Mark the link as a spoiler.
-
#remove_sticky ⇒ Object
Unsticky the post from the subreddit.
-
#set_suggested_sort(suggested) ⇒ Object
Set the suggested sort order for comments for all users.
-
#unlock ⇒ Object
Allow users to comment on the link again.
-
#unmark_as_nsfw ⇒ Object
No longer mark the link as “Not Suitable For Work”.
-
#unmark_as_spoiler ⇒ Object
No longer mark the link as a spoiler.
-
#update_sort_order(new_order) ⇒ Object
Set the sort order of the comments and reload the comments.
Methods included from Reportable
Methods included from Replyable
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
Methods inherited from Model
Constructor Details
This class inherits a constructor from Redd::Models::Model
Instance Attribute Details
#approved_at ⇒ Time? (readonly)
Returns 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_by ⇒ Object (readonly)
Returns 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.
179 |
# File 'lib/redd/models/submission.rb', line 179 property :archived?, from: :archived |
#author ⇒ User (readonly)
Returns the post author.
341 |
# File 'lib/redd/models/submission.rb', line 341 property :author, with: ->(n) { User.new(client, name: n) } |
#author_flair_css_class ⇒ String (readonly)
Returns the author flair css class.
259 |
# File 'lib/redd/models/submission.rb', line 259 property :author_flair_css_class |
#author_flair_text ⇒ String (readonly)
Returns the author flair text.
255 |
# File 'lib/redd/models/submission.rb', line 255 property :author_flair_text |
#banned_at ⇒ Time? (readonly)
Returns 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_by ⇒ String (readonly)
Returns 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.
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.
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.
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.
183 |
# File 'lib/redd/models/submission.rb', line 183 property :clicked?, from: :clicked |
#comment_count ⇒ Integer (readonly)
Returns the post's comment count.
235 |
# File 'lib/redd/models/submission.rb', line 235 property :comment_count, from: :num_comments |
#comments ⇒ Array<Comment> (readonly)
Returns 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.
263 |
# File 'lib/redd/models/submission.rb', line 263 property :contest_mode_enabled?, from: :contest_mode |
#created_at ⇒ Time (readonly)
Returns 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.
207 |
# File 'lib/redd/models/submission.rb', line 207 property :crosspostable?, from: :is_crosspostable |
#distinguished? ⇒ Boolean (readonly)
Returns whether the post is distinguished.
354 |
# File 'lib/redd/models/submission.rb', line 354 property :distinguished?, from: :distinguished |
#domain ⇒ String (readonly)
Returns the domain name of the link (or self.subreddit_name).
115 |
# File 'lib/redd/models/submission.rb', line 115 property :domain |
#downs ⇒ Integer (readonly)
this always returns zero - use #score instead
Returns downvote count.
281 |
# File 'lib/redd/models/submission.rb', line 281 property :downs |
#edited ⇒ Time, false (readonly)
Returns the time of the last edit.
251 |
# File 'lib/redd/models/submission.rb', line 251 property :edited, with: ->(t) { Time.at(t) if t } |
#gilded ⇒ Integer (readonly)
Returns 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.
227 |
# File 'lib/redd/models/submission.rb', line 227 property :hidden?, from: :hidden |
#id ⇒ String (readonly)
Returns the submission id.
167 |
# File 'lib/redd/models/submission.rb', line 167 property :id |
#link_flair_css_class ⇒ String (readonly)
Returns the link flair css class.
163 |
# File 'lib/redd/models/submission.rb', line 163 property :link_flair_css_class |
#link_flair_text ⇒ String (readonly)
Returns 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.
271 |
# File 'lib/redd/models/submission.rb', line 271 property :locked?, from: :locked |
#media ⇒ Hash (readonly)
Returns media details.
358 |
# File 'lib/redd/models/submission.rb', line 358 property :media |
#media_embed ⇒ Hash (readonly)
Returns media embed properties.
127 |
# File 'lib/redd/models/submission.rb', line 127 property :media_embed |
#mod_reports ⇒ Array (readonly)
Returns moderator reports.
366 |
# File 'lib/redd/models/submission.rb', line 366 property :mod_reports |
#name ⇒ String (readonly)
Returns the fullname (i.e. t3_xxxxxx).
309 |
# File 'lib/redd/models/submission.rb', line 309 property :name |
#num_crossposts ⇒ Integer (readonly)
Returns 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.
223 |
# File 'lib/redd/models/submission.rb', line 223 property :over_18?, from: :over_18 |
#parent_whitelist_status ⇒ String (readonly)
Returns ad-related whitelist stuff.
305 |
# File 'lib/redd/models/submission.rb', line 305 property :parent_whitelist_status |
#permalink ⇒ String (readonly)
Returns the *relative* url permalink.
317 |
# File 'lib/redd/models/submission.rb', line 317 property :permalink |
#pinned? ⇒ Boolean (readonly)
Returns whether the post is pinned.
211 |
# File 'lib/redd/models/submission.rb', line 211 property :pinned?, from: :pinned |
#post_hint ⇒ String (readonly)
Returns a hint at what the link should contain.
297 |
# File 'lib/redd/models/submission.rb', line 297 property :post_hint |
#preview ⇒ Hash (readonly)
Returns preview details.
231 |
# File 'lib/redd/models/submission.rb', line 231 property :preview |
#quarantined? ⇒ Boolean (readonly)
Returns whether the post has been quarantined.
337 |
# File 'lib/redd/models/submission.rb', line 337 property :quarantined?, from: :quarantine |
#removal_reason ⇒ String (readonly)
Returns the removal reason.
293 |
# File 'lib/redd/models/submission.rb', line 293 property :removal_reason |
#report_count ⇒ Integer (readonly)
Returns the number of reports.
321 |
# File 'lib/redd/models/submission.rb', line 321 property :report_count, from: :num_reports |
#report_reasons ⇒ Object (readonly)
Returns 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.
199 |
# File 'lib/redd/models/submission.rb', line 199 property :saved?, from: :saved |
#score ⇒ Integer (readonly)
Returns 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.
247 |
# File 'lib/redd/models/submission.rb', line 247 property :score_hidden?, from: :hide_score |
#secure_media ⇒ Hash? (readonly)
Returns secure media details.
155 |
# File 'lib/redd/models/submission.rb', line 155 property :secure_media |
#secure_media_embed ⇒ Hash (readonly)
Returns 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.
370 |
# File 'lib/redd/models/submission.rb', line 370 property :self?, from: :is_self |
#selftext ⇒ String (readonly)
Returns the self text contents.
139 |
# File 'lib/redd/models/submission.rb', line 139 property :selftext |
#selftext_html ⇒ String? (readonly)
Returns the html-rendered self text, can be nil if link.
135 |
# File 'lib/redd/models/submission.rb', line 135 property :selftext_html |
#sort_order ⇒ Symbol (readonly)
Returns 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.
313 |
# File 'lib/redd/models/submission.rb', line 313 property :spoiler?, from: :spoiler |
#stickied? ⇒ Boolean (readonly)
Returns whether the post was stickied.
329 |
# File 'lib/redd/models/submission.rb', line 329 property :stickied?, from: :stickied |
#subreddit ⇒ Subreddit (readonly)
Returns 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_prefixed ⇒ String (readonly)
Returns 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_type ⇒ String (readonly)
Returns the subreddit's type.
378 |
# File 'lib/redd/models/submission.rb', line 378 property :subreddit_type |
#suggested_sort ⇒ String? (readonly)
Returns the suggested sort.
147 |
# File 'lib/redd/models/submission.rb', line 147 property :suggested_sort |
#thumbnail ⇒ String (readonly)
Returns the thumbnail url.
239 |
# File 'lib/redd/models/submission.rb', line 239 property :thumbnail |
#thumbnail_height ⇒ Integer (readonly)
Returns thumbnail height.
243 |
# File 'lib/redd/models/submission.rb', line 243 property :thumbnail_height |
#title ⇒ String (readonly)
Returns the post title.
191 |
# File 'lib/redd/models/submission.rb', line 191 property :title |
#ups ⇒ Integer (readonly)
this doesn't return the raw upvote count - use #score instead
Returns upvote count.
276 |
# File 'lib/redd/models/submission.rb', line 276 property :ups |
#upvote_ratio ⇒ Float (readonly)
Returns 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.
143 |
# File 'lib/redd/models/submission.rb', line 143 property :upvoted?, from: :likes |
#url ⇒ String (readonly)
Returns the link url.
333 |
# File 'lib/redd/models/submission.rb', line 333 property :url |
#user_reports ⇒ Array<String> (readonly)
Returns 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.
382 |
# File 'lib/redd/models/submission.rb', line 382 property :video, from: :is_video |
#view_count ⇒ Integer? (readonly)
Returns the view count.
175 |
# File 'lib/redd/models/submission.rb', line 175 property :view_count |
#visited? ⇒ Boolean (readonly)
Returns whether the post was visited.
374 |
# File 'lib/redd/models/submission.rb', line 374 property :visited?, from: :visited |
#whitelist_status ⇒ String (readonly)
Returns ad-related whitelist stuff.
325 |
# File 'lib/redd/models/submission.rb', line 325 property :whitelist_status |
Instance Method Details
#disable_contest_mode ⇒ Object
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.
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_mode ⇒ Object
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 |
#lock ⇒ Object
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.
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_nsfw ⇒ Object
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_spoiler ⇒ Object
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_sticky ⇒ Object
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.
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 |
#unlock ⇒ Object
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_nsfw ⇒ Object
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_spoiler ⇒ Object
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.
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 |