Class: Redd::Objects::Submission
- Includes:
- Thing::Editable, Thing::Hideable, Thing::Moderatable, Thing::Refreshable, Thing::Saveable, Thing::Votable
- Defined in:
- lib/redd/objects/submission.rb
Overview
A submission made in a subreddit.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#add_comment(text) ⇒ Objects::Comment
Reply to the thing.
-
#comments ⇒ Listing
(also: #replies)
The submission’s comments.
-
#expand_more(more) ⇒ Listing
Take a MoreComments and return a listing of comments.
-
#get_duplicates(**params) ⇒ Objects::Listing<Objects::Submission>
Get other articles with the same URL.
-
#get_related(**params) ⇒ Objects::Listing<Objects::Thing>
Get the related articles.
-
#gilded? ⇒ Boolean
Whether the comment was gilded.
-
#mark_as_nsfw ⇒ Object
Mark the thing as Not Suitable For Work.
-
#refresh! ⇒ Submission
Refresh the submission AND its comments.
-
#set_contest_mode ⇒ Object
Set the submission to “contest mode” (comments are randomly sorted).
-
#set_sticky ⇒ Object
Set the submission as the sticky post of the subreddit.
-
#short_url ⇒ Object
The shorter url for sharing.
-
#unmark_as_nsfw ⇒ Object
(also: #mark_as_safe)
No longer mark the thing as Not Suitable For Work.
-
#unset_contest_mode ⇒ Object
Unset the “contest mode”.
-
#unset_sticky ⇒ Object
Unsticky the post from the subreddit.
Methods included from Thing::Votable
#clear_vote, #downvote, #upvote
Methods included from Thing::Saveable
Methods included from Thing::Moderatable
#approve!, #distinguish, #ignore_reports, #remove!, #undistinguish, #unignore_reports
Methods included from Thing::Hideable
Methods included from Thing::Editable
Methods inherited from Thing
Methods inherited from Base
Constructor Details
This class inherits a constructor from Redd::Objects::Base
Instance Method Details
#add_comment(text) ⇒ Objects::Comment
Reply to the thing.
44 45 46 |
# File 'lib/redd/objects/submission.rb', line 44 def add_comment(text) client.add_comment(self, text) end |
#comments ⇒ Listing Also known as: replies
Allow for various depths and contexts and what not. Maybe a get_comment method?
Returns The submission’s comments.
73 74 75 76 |
# File 'lib/redd/objects/submission.rb', line 73 def comments refresh! unless @comments @comments end |
#expand_more(more) ⇒ Listing
Take a MoreComments and return a listing of comments. rubocop:disable Metrics/MethodLength
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/redd/objects/submission.rb', line 91 def (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) ⇒ Objects::Listing<Objects::Submission>
Get other articles with the same URL.
134 135 136 137 |
# 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 |
#get_related(**params) ⇒ Objects::Listing<Objects::Thing>
Get the related articles.
118 119 120 121 |
# File 'lib/redd/objects/submission.rb', line 118 def (**params) = get("/related/#{id}.json", params).body[1] client.object_from_body() end |
#gilded? ⇒ Boolean
Whether the comment was gilded.
24 25 26 |
# File 'lib/redd/objects/submission.rb', line 24 def gilded? self[:gilded] > 0 end |
#mark_as_nsfw ⇒ Object
Mark the thing as Not Suitable For Work.
29 30 31 32 |
# File 'lib/redd/objects/submission.rb', line 29 def mark_as_nsfw get('/api/marknsfw', id: fullname) self[:over_18] = true end |
#refresh! ⇒ Submission
Refresh the submission AND its comments.
81 82 83 84 85 |
# 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_contest_mode ⇒ Object
Set the submission to “contest mode” (comments are randomly sorted)
49 50 51 |
# File 'lib/redd/objects/submission.rb', line 49 def set_contest_mode post('/api/set_contest_mode', id: fullname, state: true) end |
#set_sticky ⇒ Object
Set the submission as the sticky post of the subreddit
59 60 61 62 |
# 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 ⇒ Object
The shorter url for sharing.
19 20 21 |
# File 'lib/redd/objects/submission.rb', line 19 def short_url "http://redd.it/#{self[:id]}" end |
#unmark_as_nsfw ⇒ Object Also known as: mark_as_safe
No longer mark the thing as Not Suitable For Work.
35 36 37 38 |
# File 'lib/redd/objects/submission.rb', line 35 def unmark_as_nsfw get('/api/unmarknsfw', id: fullname) self[:over_18] = false end |
#unset_contest_mode ⇒ Object
Unset the “contest mode”.
54 55 56 |
# File 'lib/redd/objects/submission.rb', line 54 def unset_contest_mode post('/api/set_contest_mode', id: fullname, state: false) end |
#unset_sticky ⇒ Object
Unsticky the post from the subreddit
65 66 67 68 |
# File 'lib/redd/objects/submission.rb', line 65 def unset_sticky post('/api/set_subreddit_sticky', id: fullname, state: false) self[:stickied] = false end |