Class: NeonRAW::Objects::Submission

Inherits:
Thing
  • Object
show all
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

Attributes included from Thing::Votable

#downs, #ups

Attributes included from Thing::Moderateable

#mod_reports, #user_reports

Attributes inherited from Thing

#id, #name

Instance Method Summary collapse

Methods included from Thing::Votable

#clear_vote, #downvote, #downvoted?, #upvote, #upvoted?, #voted?

Methods included from Thing::Saveable

#save, #unsave

Methods included from Thing::Repliable

#reply

Methods included from Thing::Refreshable

#refresh!

Methods included from Thing::Moderateable

#approve!, #distinguish!, #distinguished?, #distinguished_by, #ignore_reports!, #remove!, #report, #spam!, #stickied?, #unignore_reports!

Methods included from Thing::Gildable

#gild, #gilded?

Methods included from Thing::Editable

#delete!, #edit!, #edited?, #last_edit

Methods included from Thing::Createable

#created, #created_utc

Constructor Details

#initialize(client, data) ⇒ Submission

Returns a new instance of Submission.

Parameters:

  • client (NeonRAW::Clients::Web/Installed/Script)

    The client object.

  • data (Hash)

    The object data.



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.

Returns:

  • (Boolean)

    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

#authorString (readonly)

Returns the author of the submission.

Returns:

  • (String)

    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_classString? (readonly)

Returns the CSS class of the submitter’s flair or nil if there is none.

Returns:

  • (String, nil)

    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_textString? (readonly)

Returns the flair’s text of the submitter’s flair or nil if there is none.

Returns:

  • (String, nil)

    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”.

Returns:

  • (Boolean)

    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

#domainString (readonly)

Returns the domain of the submitted item.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    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

Returns the CSS class for the submission’s link flair or nil if there is none.

Returns:

  • (String, nil)

    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

Returns the Link flair’s text or nil if there is none.

Returns:

  • (String, nil)

    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.

Returns:

  • (Boolean)

    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

#mediaHash? (readonly)

Returns an object containing information about a video and its origins or nil if there is none.

Returns:

  • (Hash, nil)

    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_embedHash? (readonly)

Returns an object containing technical embed information or nil if there is none.

Returns:

  • (Hash, nil)

    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.

Returns:

  • (Boolean)

    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_commentsInteger (readonly)

Returns the number of comments in the submission.

Returns:

  • (Integer)

    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

Returns the permalink of the submission.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    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

#scoreInteger (readonly)

Returns the submission’s karma score.

Returns:

  • (Integer)

    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.

Returns:

  • (Boolean)

    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

#selftextString? (readonly)

Returns the text of selfposts or nil if there is none.

Returns:

  • (String, nil)

    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_htmlString? (readonly)

Returns the text of selfposts with HTML or nil if there is none.

Returns:

  • (String, nil)

    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

#subredditString (readonly)

Returns the subreddit the submission was posted to.

Returns:

  • (String)

    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_idString (readonly)

Returns the ID of the subreddit where the submission was posted to.

Returns:

  • (String)

    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

#thumbnailString? (readonly)

Returns the URL to the thumbnail of the post or nil if there is none.

Returns:

  • (String, nil)

    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

#titleString (readonly)

Returns the title of the submission.

Returns:

  • (String)

    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

#urlString (readonly)

Returns Either the URL submitted (link post) or the submission’s permalink (selfpost).

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    Returns false.



139
140
141
# File 'lib/NeonRAW/objects/submission.rb', line 139

def comment?
  false
end

#commentsArray

Fetches the comments for a submission.

Returns:

  • (Array)

    Returns an array full of Comments and MoreComments objects.



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.

Parameters:

  • enable (Boolean)

    Turns it 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.

Parameters:

  • params (Hash) (defaults to: { limit: 25 })

    Optional parameters.

  • :after (Hash)

    a customizable set of options

  • :before (Hash)

    a customizable set of options

  • :count (Hash)

    a customizable set of options

  • :limit (Hash)

    a customizable set of options

  • :show (Hash)

    a customizable set of options

Returns:



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.

Returns:

  • (Boolean)

    Returns 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

#hideObject

Note:

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.

Parameters:

  • enable (Boolean)

    Turns it on or off.



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.

Returns:

  • (Boolean)

    Returns 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

#lockObject

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_nsfwObject

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

The submission’s shortlink.

Returns:

  • (String)

    Returns 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.

Parameters:

  • enable (Boolean)

    Stickies/unstickies the thing.



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.

Returns:

  • (Boolean)

    Returns true.



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.

Parameters:

  • sort (Symbol)

    The sort to set [confidence, top, new, controversial, old, random, qa]



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

#unhideObject

Note:

See lock/unlock for source code.

Set submission visibility.



# File 'lib/NeonRAW/objects/submission.rb', line 188

#unlockObject

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_nsfwObject

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