Class: NeonRAW::Objects::Submission
- Includes:
- Thing::Createable, Thing::Editable, Thing::Gildable, Thing::Moderateable, Thing::Refreshable, Thing::Repliable, Thing::Saveable, Thing::Votable
- Defined in:
- lib/NeonRAW/objects/submission.rb
Overview
The submission object.
Instance Attribute Summary collapse
-
#archived? ⇒ Boolean
readonly
Returns whether or not the submission is archived.
-
#author ⇒ String
readonly
Returns the author of the submission.
-
#author_flair_css_class ⇒ String?
readonly
Returns the CSS class of the submitter’s flair or nil if there is none.
-
#author_flair_text ⇒ String?
readonly
Returns the flair’s text of the submitter’s flair or nil if there is none.
-
#clicked? ⇒ Boolean
readonly
Returns whether or not the submission has been “clicked”.
-
#domain ⇒ String
readonly
Returns the domain of the submitted item.
-
#hidden? ⇒ Boolean
readonly
Returns whether or not you hid the submission.
-
#link_flair_css_class ⇒ String?
readonly
Returns the CSS class for the submission’s link flair or nil if there is none.
-
#link_flair_text ⇒ String?
readonly
Returns the Link flair’s text or nil if there is none.
-
#locked? ⇒ Boolean
readonly
Returns whether or not the submission is locked.
-
#media ⇒ Hash?
readonly
Returns an object containing information about a video and its origins or nil if there is none.
-
#media_embed ⇒ Hash?
readonly
Returns an object containing technical embed information or nil if there is none.
-
#nsfw? ⇒ Boolean
readonly
Returns whether or not the post is flagged as NSFW.
-
#num_comments ⇒ Integer
readonly
Returns the number of comments in the submission.
-
#permalink ⇒ String
readonly
Returns the permalink of the submission.
-
#saved? ⇒ Boolean
readonly
Returns whether or not you saved the submission.
-
#score ⇒ Integer
readonly
Returns the submission’s karma score.
-
#selfpost? ⇒ Boolean
readonly
Returns whether or not the submission is a selfpost.
-
#selftext ⇒ String?
readonly
Returns the text of selfposts or nil if there is none.
-
#selftext_html ⇒ String?
readonly
Returns the text of selfposts with HTML or nil if there is none.
-
#subreddit ⇒ String
readonly
Returns the subreddit the submission was posted to.
-
#subreddit_id ⇒ String
readonly
Returns the ID of the subreddit where the submission was posted to.
-
#thumbnail ⇒ String?
readonly
Returns the URL to the thumbnail of the post or nil if there is none.
-
#title ⇒ String
readonly
Returns the title of the submission.
-
#url ⇒ String
readonly
Either the URL submitted (link post) or the submission’s permalink (selfpost).
Attributes included from Thing::Votable
Attributes included from Thing::Moderateable
Attributes inherited from Thing
Instance Method Summary collapse
-
#comment? ⇒ Boolean
Checks whether or not this is a comment.
-
#comments ⇒ Array
Fetches the comments for a submission.
-
#contest_mode(enable) ⇒ Object
Set contest mode on or off.
-
#duplicates(params = { limit: 25 }) ⇒ NeonRAW::Objects::Listing
Fetches duplicates for the submission.
-
#flair? ⇒ Boolean
Checks whether or not the submission has flair.
-
#hide ⇒ Object
Set submission visibility.
-
#inbox_replies(enable) ⇒ Object
Toggle getting inbox replies from the submission.
-
#initialize(client, data) ⇒ Submission
constructor
A new instance of Submission.
-
#linkpost? ⇒ Boolean
Checks whether or not the submission is a link post.
-
#lock ⇒ Object
Set whether or not users can comment on the submission.
-
#mark_nsfw ⇒ Object
Set the submission’s NSFW status.‘.
-
#shortlink ⇒ String
The submission’s shortlink.
-
#sticky(enable) ⇒ Object
Sticky a submission/comment.
-
#submission? ⇒ Boolean
Checks whether or not this is a submission.
-
#suggested_sort(sort) ⇒ Object
Sets the suggested sort for a submission.
-
#unhide ⇒ Object
Set submission visibility.
-
#unlock ⇒ Object
Set whether or not users can comment on the submission.
-
#unmark_nsfw ⇒ Object
Set the submission’s NSFW status.‘.
Methods included from Thing::Votable
#clear_vote, #downvote, #downvoted?, #upvote, #upvoted?, #voted?
Methods included from Thing::Saveable
Methods included from Thing::Repliable
Methods included from Thing::Refreshable
Methods included from Thing::Moderateable
#approve!, #distinguish!, #distinguished?, #distinguished_by, #ignore_reports!, #remove!, #report, #spam!, #stickied?, #unignore_reports!
Methods included from Thing::Gildable
Methods included from Thing::Editable
#delete!, #edit!, #edited?, #last_edit
Methods included from Thing::Createable
Constructor Details
#initialize(client, data) ⇒ Submission
Returns a new instance of Submission.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/NeonRAW/objects/submission.rb', line 88 def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end |
Instance Attribute Details
#archived? ⇒ Boolean (readonly)
Returns whether or not the submission is archived.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#author ⇒ String (readonly)
Returns the author of the submission.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#author_flair_css_class ⇒ String? (readonly)
Returns the CSS class of the submitter’s flair or nil if there is none.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#author_flair_text ⇒ String? (readonly)
Returns the flair’s text of the submitter’s flair or nil if there is none.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#clicked? ⇒ Boolean (readonly)
Returns whether or not the submission has been “clicked”.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#domain ⇒ String (readonly)
Returns the domain of the submitted item.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#hidden? ⇒ Boolean (readonly)
Returns whether or not you hid the submission.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#link_flair_css_class ⇒ String? (readonly)
Returns the CSS class for the submission’s link flair or nil if there is none.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#link_flair_text ⇒ String? (readonly)
Returns the Link flair’s text or nil if there is none.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#locked? ⇒ Boolean (readonly)
Returns whether or not the submission is locked.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#media ⇒ Hash? (readonly)
Returns an object containing information about a video and its origins or nil if there is none.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#media_embed ⇒ Hash? (readonly)
Returns an object containing technical embed information or nil if there is none.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#nsfw? ⇒ Boolean (readonly)
Returns whether or not the post is flagged as NSFW.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#num_comments ⇒ Integer (readonly)
Returns the number of comments in the submission.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#permalink ⇒ String (readonly)
Returns the permalink of the submission.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#saved? ⇒ Boolean (readonly)
Returns whether or not you saved the submission.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#score ⇒ Integer (readonly)
Returns the submission’s karma score.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#selfpost? ⇒ Boolean (readonly)
Returns whether or not the submission is a selfpost.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#selftext ⇒ String? (readonly)
Returns the text of selfposts or nil if there is none.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#selftext_html ⇒ String? (readonly)
Returns the text of selfposts with HTML or nil if there is none.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#subreddit ⇒ String (readonly)
Returns the subreddit the submission was posted to.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#subreddit_id ⇒ String (readonly)
Returns the ID of the subreddit where the submission was posted to.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#thumbnail ⇒ String? (readonly)
Returns the URL to the thumbnail of the post or nil if there is none.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#title ⇒ String (readonly)
Returns the title of the submission.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
#url ⇒ String (readonly)
Returns Either the URL submitted (link post) or the submission’s permalink (selfpost).
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/NeonRAW/objects/submission.rb', line 74 class Submission < Thing include Thing::Createable include Thing::Editable include Thing::Gildable include Thing::Moderateable include Thing::Refreshable include Thing::Repliable include Thing::Saveable include Thing::Votable # @!method initialize(client, data) # @param client [NeonRAW::Clients::Web/Installed/Script] The client # object. # @param data [Hash] The object data. def initialize(client, data) @client = client data.each do |key, value| # for consistency, empty strings/arrays/hashes are set to nil # because most of the keys returned by Reddit are nil when they # don't have a value, besides a few value = nil if ['', [], {}].include?(value) if key == :permalink instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value) else instance_variable_set(:"@#{key}", value) end next if %i[created created_utc].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :clicked?, :clicked alias_method :hidden?, :hidden alias_method :selfpost?, :is_self alias_method :locked?, :locked alias_method :nsfw?, :over_18 alias_method :saved?, :saved alias_method :archived?, :archived alias_method :add_comment, :reply end end # Checks whether or not the submission is a link post. # @!method linkpost? # @return [Boolean] Returns whether or not the submission is a link post. def linkpost? !@is_self end # Checks whether or not the submission has flair. # @!method flair? # @return [Boolean] Returns whether or not the submission has flair. def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end # Checks whether or not this is a submission. # @!method submission? # @return [Boolean] Returns true. def submission? true end # Checks whether or not this is a comment. # @!method comment? # @return [Boolean] Returns false. def comment? false end # Fetches the comments for a submission. # @!method comments # @return [Array] Returns an array full of Comments and MoreComments # objects. def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end # Fetches duplicates for the submission. # @!method duplicates(params = { limit: 25 }) # @param params [Hash] Optional parameters. # @option :after [String] The fullname of the next data block. # @option :before [String] The fullname of the previous data block. # @option :count [Integer] The number of posts already in the listing. # @option :limit [1..1000] The number of listing items to fetch. # @option :show [String] Literally the string 'all'. # @return [NeonRAW::Objects::Listing] Returns the listing with all the # duplicate submissions. def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end # Set submission visibility. # @!method hide # @!method unhide # @note See lock/unlock for source code. # Set whether or not users can comment on the submission. # @!method lock # @!method unlock %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end # Set the submission's NSFW status.' # @!method mark_nsfw # @!method unmark_nsfw %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end # Toggle getting inbox replies from the submission. # @!method inbox_replies(enable) # @param enable [Boolean] Turns it on or off. def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end # Set contest mode on or off. # @!method contest_mode(enable) # @param enable [Boolean] Turns it on or off. def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end # Sets the suggested sort for a submission. # @!method suggested_sort(sort) # @param sort [Symbol] The sort to set [confidence, top, new, # controversial, old, random, qa] def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end # Sticky a submission/comment. # @!method sticky(enable) # @param enable [Boolean] Stickies/unstickies the thing. def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end # The submission's shortlink. # @!method shortlink # @return [String] Returns the submission's shortlink. def shortlink "https://redd.it/#{id}" end end |
Instance Method Details
#comment? ⇒ Boolean
Checks whether or not this is a comment.
139 140 141 |
# File 'lib/NeonRAW/objects/submission.rb', line 139 def comment? false end |
#comments ⇒ Array
Fetches the comments for a submission.
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/NeonRAW/objects/submission.rb', line 147 def comments data = @client.request_data("/comments/#{id}", :get) data_arr = [] data[1][:data][:children].each do |comment| if comment[:kind] == 't1' data_arr << Comment.new(@client, comment[:data]) elsif comment[:kind] == 'more' data_arr << MoreComments.new(@client, comment[:data]) end end data_arr end |
#contest_mode(enable) ⇒ Object
Set contest mode on or off.
224 225 226 227 |
# File 'lib/NeonRAW/objects/submission.rb', line 224 def contest_mode(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_contest_mode', :post, params) end |
#duplicates(params = { limit: 25 }) ⇒ NeonRAW::Objects::Listing
Fetches duplicates for the submission.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/NeonRAW/objects/submission.rb', line 170 def duplicates(params = { limit: 25 }) params[:sr_detail] = false data_arr = [] until data_arr.length == params[:limit] data = @client.request_data("/duplicates/#{id}", :get, params) params[:after] = data[1][:data][:after] params[:before] = data[1][:data][:before] data[1][:data][:children].each do |submission| data_arr << Submission.new(@client, submission[:data]) break if data_arr.length == params[:limit] end break if params[:after].nil? end listing = Listing.new(params[:after], params[:before]) data_arr.each { |submission| listing << submission } listing end |
#flair? ⇒ Boolean
Checks whether or not the submission has flair.
125 126 127 |
# File 'lib/NeonRAW/objects/submission.rb', line 125 def flair? !@link_flair_text.nil? || !@link_flair_css_class.nil? end |
#hide ⇒ Object
See lock/unlock for source code.
Set submission visibility.
|
# File 'lib/NeonRAW/objects/submission.rb', line 188
|
#inbox_replies(enable) ⇒ Object
Toggle getting inbox replies from the submission.
216 217 218 219 |
# File 'lib/NeonRAW/objects/submission.rb', line 216 def inbox_replies(enable) params = { id: name, state: enable } @client.request_data('/api/sendreplies', :post, params) end |
#linkpost? ⇒ Boolean
Checks whether or not the submission is a link post.
118 119 120 |
# File 'lib/NeonRAW/objects/submission.rb', line 118 def linkpost? !@is_self end |
#lock ⇒ Object
Set whether or not users can comment on the submission.
196 197 198 199 200 201 |
# File 'lib/NeonRAW/objects/submission.rb', line 196 %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end |
#mark_nsfw ⇒ Object
Set the submission’s NSFW status.‘
206 207 208 209 210 211 |
# File 'lib/NeonRAW/objects/submission.rb', line 206 %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end |
#shortlink ⇒ String
The submission’s shortlink.
249 250 251 |
# File 'lib/NeonRAW/objects/submission.rb', line 249 def shortlink "https://redd.it/#{id}" end |
#sticky(enable) ⇒ Object
Sticky a submission/comment.
241 242 243 244 |
# File 'lib/NeonRAW/objects/submission.rb', line 241 def sticky(enable) params = { api_type: 'json', id: name, state: enable } @client.request_data('/api/set_subreddit_sticky', :post, params) end |
#submission? ⇒ Boolean
Checks whether or not this is a submission.
132 133 134 |
# File 'lib/NeonRAW/objects/submission.rb', line 132 def submission? true end |
#suggested_sort(sort) ⇒ Object
Sets the suggested sort for a submission.
233 234 235 236 |
# File 'lib/NeonRAW/objects/submission.rb', line 233 def suggested_sort(sort) params = { api_type: 'json', id: name, sort: sort } @client.request_data('/api/set_suggested_sort', :post, params) end |
#unhide ⇒ Object
See lock/unlock for source code.
Set submission visibility.
|
# File 'lib/NeonRAW/objects/submission.rb', line 188
|
#unlock ⇒ Object
Set whether or not users can comment on the submission.
196 197 198 199 200 201 |
# File 'lib/NeonRAW/objects/submission.rb', line 196 %w[hide unhide lock unlock].each do |type| define_method :"#{type}" do params = { id: name } @client.request_data("/api/#{type}", :post, params) end end |
#unmark_nsfw ⇒ Object
Set the submission’s NSFW status.‘
206 207 208 209 210 211 |
# File 'lib/NeonRAW/objects/submission.rb', line 206 %w[mark unmark].each do |type| define_method :"#{type}_nsfw" do params = { id: name } @client.request_data("/api/#{type}nsfw", :post, params) end end |