Class: Redd::Models::Submission
- Inherits:
-
LazyModel
- Object
- BasicModel
- LazyModel
- Redd::Models::Submission
- Includes:
- Gildable, Moderatable, Postable, Replyable
- Defined in:
- lib/redd/models/submission.rb
Overview
A text or link post.
Instance Attribute Summary
Attributes inherited from BasicModel
Class Method Summary collapse
-
.from_id(client, id) ⇒ Submission
Create a Subreddit from its fullname.
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.
-
#sort_order ⇒ Symbol
The requested sort order.
-
#sort_order=(new_order) ⇒ Object
Set the sort order of the comments and reload if necessary.
-
#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.
Methods included from Replyable
Methods included from Postable
#delete, #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 LazyModel
#force_load, #initialize, #method_missing, #respond_to_missing?, #to_h
Methods inherited from BasicModel
#initialize, #inspect, #method_missing, #respond_to_missing?, #to_ary, #to_h
Constructor Details
This class inherits a constructor from Redd::Models::LazyModel
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Redd::Models::LazyModel
Class Method Details
.from_id(client, id) ⇒ Submission
Create a Subreddit from its fullname.
25 26 27 |
# File 'lib/redd/models/submission.rb', line 25 def self.from_id(client, id) new(client, name: id) end |
Instance Method Details
#disable_contest_mode ⇒ Object
Disable the “contest mode”.
88 89 90 |
# File 'lib/redd/models/submission.rb', line 88 def disable_contest_mode @client.post('/api/set_contest_mode', id: get_attribute(:name), state: false) end |
#duplicates(**params) ⇒ Listing<Submission>
Get all submissions for the same url.
54 55 56 |
# File 'lib/redd/models/submission.rb', line 54 def duplicates(**params) @client.unmarshal(@client.get("/duplicates/#{get_attribute(:id)}", params).body[1]) end |
#enable_contest_mode ⇒ Object
Set the submission to “contest mode” (comments are randomly sorted)
83 84 85 |
# File 'lib/redd/models/submission.rb', line 83 def enable_contest_mode @client.post('/api/set_contest_mode', id: get_attribute(:name), state: true) end |
#lock ⇒ Object
Prevent users from commenting on the link (and hide it as well).
104 105 106 |
# File 'lib/redd/models/submission.rb', line 104 def lock @client.post('/api/lock', id: get_attribute(:name)) end |
#make_sticky(slot: nil) ⇒ Object
Set the submission as the sticky post of the subreddit.
94 95 96 |
# File 'lib/redd/models/submission.rb', line 94 def make_sticky(slot: nil) @client.post('/api/set_subreddit_sticky', id: get_attribute(:name), num: slot, state: true) end |
#mark_as_nsfw ⇒ Object
Mark the link as “Not Suitable For Work”.
59 60 61 62 |
# File 'lib/redd/models/submission.rb', line 59 def mark_as_nsfw @client.get('/api/marknsfw', id: get_attribute(:name)) @attributes[:over_18] = true end |
#mark_as_spoiler ⇒ Object
Mark the link as a spoiler.
71 72 73 74 |
# File 'lib/redd/models/submission.rb', line 71 def mark_as_spoiler @client.get('/api/spoiler', id: get_attribute(:name)) @attributes[:spoiler] = true end |
#remove_sticky ⇒ Object
Unsticky the post from the subreddit.
99 100 101 |
# File 'lib/redd/models/submission.rb', line 99 def remove_sticky @client.post('/api/set_subreddit_sticky', id: get_attribute(:name), state: false) end |
#set_suggested_sort(suggested) ⇒ Object
Set the suggested sort order for comments for all users.
116 117 118 119 120 |
# File 'lib/redd/models/submission.rb', line 116 def set_suggested_sort(suggested) # rubocop:disable Style/AccessorMethodName # Style/AccessorMethodName is disabled because it feels wrong for accessor methods to make # HTTP requests. @client.post('/api/set_suggested_sort', id: get_attribute(:name), sort: suggested) end |
#sort_order ⇒ Symbol
Returns the requested sort order.
30 31 32 |
# File 'lib/redd/models/submission.rb', line 30 def sort_order @sort_order ||= nil end |
#sort_order=(new_order) ⇒ Object
Set the sort order of the comments and reload if necessary.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/redd/models/submission.rb', line 36 def sort_order=(new_order) # If the comments were loaded in a different sort order, delete them and invalidate this # model. if @attributes.key?(:comments) && @sort_order != new_order @attributes.delete(:comments) @definitely_fully_loaded = false end @sort_order = new_order end |
#unlock ⇒ Object
Allow users to comment on the link again.
109 110 111 |
# File 'lib/redd/models/submission.rb', line 109 def unlock @client.post('/api/unlock', id: get_attribute(:name)) end |
#unmark_as_nsfw ⇒ Object
No longer mark the link as “Not Suitable For Work”.
65 66 67 68 |
# File 'lib/redd/models/submission.rb', line 65 def unmark_as_nsfw @client.get('/api/unmarknsfw', id: get_attribute(:name)) @attributes[:over_18] = false end |
#unmark_as_spoiler ⇒ Object
No longer mark the link as a spoiler.
77 78 79 80 |
# File 'lib/redd/models/submission.rb', line 77 def unmark_as_spoiler @client.get('/api/unspoiler', id: get_attribute(:name)) @attributes[:spoiler] = false end |