NeonRAW 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +5 -0
  5. data/.travis.yml +4 -0
  6. data/CHANGELOG.md +7 -0
  7. data/CONTRIBUTING.md +11 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.md +373 -0
  10. data/NeonRAW.gemspec +26 -0
  11. data/README.md +62 -0
  12. data/Rakefile +6 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/examples/crossposter.rb +78 -0
  16. data/examples/flairbot.rb +60 -0
  17. data/examples/publicmodlogger.rb +79 -0
  18. data/examples/settings.yaml +4 -0
  19. data/examples/userhistoryscraper.rb +108 -0
  20. data/examples/userhistorywiper.rb +10 -0
  21. data/lib/NeonRAW/clients/base/listing.rb +55 -0
  22. data/lib/NeonRAW/clients/base/objectbuilder.rb +173 -0
  23. data/lib/NeonRAW/clients/base/utilities.rb +46 -0
  24. data/lib/NeonRAW/clients/base.rb +109 -0
  25. data/lib/NeonRAW/clients/installed.rb +49 -0
  26. data/lib/NeonRAW/clients/script.rb +34 -0
  27. data/lib/NeonRAW/clients/web.rb +52 -0
  28. data/lib/NeonRAW/errors.rb +518 -0
  29. data/lib/NeonRAW/objects/access.rb +44 -0
  30. data/lib/NeonRAW/objects/all.rb +36 -0
  31. data/lib/NeonRAW/objects/comment.rb +128 -0
  32. data/lib/NeonRAW/objects/inboxcomment.rb +54 -0
  33. data/lib/NeonRAW/objects/listing.rb +12 -0
  34. data/lib/NeonRAW/objects/me.rb +268 -0
  35. data/lib/NeonRAW/objects/modlogaction.rb +59 -0
  36. data/lib/NeonRAW/objects/modloguser.rb +35 -0
  37. data/lib/NeonRAW/objects/morecomments.rb +33 -0
  38. data/lib/NeonRAW/objects/multireddit.rb +134 -0
  39. data/lib/NeonRAW/objects/privatemessage.rb +90 -0
  40. data/lib/NeonRAW/objects/rule.rb +41 -0
  41. data/lib/NeonRAW/objects/submission.rb +221 -0
  42. data/lib/NeonRAW/objects/subreddit/flair.rb +169 -0
  43. data/lib/NeonRAW/objects/subreddit/moderation.rb +200 -0
  44. data/lib/NeonRAW/objects/subreddit/utilities.rb +73 -0
  45. data/lib/NeonRAW/objects/subreddit/wiki.rb +31 -0
  46. data/lib/NeonRAW/objects/subreddit.rb +223 -0
  47. data/lib/NeonRAW/objects/thing/createable.rb +22 -0
  48. data/lib/NeonRAW/objects/thing/editable.rb +46 -0
  49. data/lib/NeonRAW/objects/thing/gildable.rb +29 -0
  50. data/lib/NeonRAW/objects/thing/inboxable.rb +26 -0
  51. data/lib/NeonRAW/objects/thing/moderateable.rb +98 -0
  52. data/lib/NeonRAW/objects/thing/refreshable.rb +21 -0
  53. data/lib/NeonRAW/objects/thing/repliable.rb +23 -0
  54. data/lib/NeonRAW/objects/thing/saveable.rb +26 -0
  55. data/lib/NeonRAW/objects/thing/votable.rb +69 -0
  56. data/lib/NeonRAW/objects/thing.rb +24 -0
  57. data/lib/NeonRAW/objects/trophy.rb +25 -0
  58. data/lib/NeonRAW/objects/user.rb +147 -0
  59. data/lib/NeonRAW/objects/wikipage.rb +176 -0
  60. data/lib/NeonRAW/objects/wikipagerevision.rb +45 -0
  61. data/lib/NeonRAW/version.rb +3 -0
  62. data/lib/NeonRAW.rb +43 -0
  63. metadata +161 -0
@@ -0,0 +1,134 @@
1
+ require_relative 'thing'
2
+
3
+ module NeonRAW
4
+ module Objects
5
+ # The multireddit object.
6
+ # @!attribute [r] editable?
7
+ # @return [Boolean] Returns whether or not you can edit the multireddit.
8
+ # @!attribute [r] display_name
9
+ # @return [String] Returns the display name of the multireddit.
10
+ # @!attribute [r] name
11
+ # @return [String] Returns the name of the multireddit.
12
+ # @!attribute [r] description_html
13
+ # @return [String, nil] Returns the description of the multireddit with
14
+ # HTML or nil if there is none.
15
+ # @!attribute [r] copied_from
16
+ # @return [String, nil] Returns where the multireddit was copied from or
17
+ # nil if it wasn't copied.
18
+ # @!attribute [r] icon_url
19
+ # @return [String, nil] Returns the icon URL of the multireddit or nil if
20
+ # there is none.
21
+ # @!attribute [r] key_color
22
+ # @return [String, nil] Returns the color of the key or nil if there is
23
+ # none.
24
+ # @!attribute [r] visibility
25
+ # @return [String] Returns the visibility status of the multireddit
26
+ # [public, private, hidden].
27
+ # @!attribute [r] icon_name
28
+ # @return [String, nil] Returns the name of the icon or nil if there is
29
+ # none ['art and design', 'ask', 'books', 'business', 'cars',
30
+ # 'comics', 'cute animals', 'diy', 'entertainment', 'food and drink',
31
+ # 'funny', 'games', 'grooming', 'health', 'life advice', 'military',
32
+ # 'models pinup', 'music', 'news', 'philosophy', 'pictures and gifs',
33
+ # 'science', 'shopping', 'sports', 'style', 'tech', 'travel',
34
+ # 'unusual stories', 'video', '', 'None'].
35
+ # @!attribute [r] weighting_scheme
36
+ # @return [String] Returns the weighting scheme for the multireddit
37
+ # [classic, fresh].
38
+ # @!attribute [r] path
39
+ # @return [String] Returns the path to the multireddit.
40
+ # @!attribute [r] description
41
+ # @return [String, nil] Returns the description of the multireddit or nil
42
+ # if there is none.
43
+ class MultiReddit < Thing
44
+ include Thing::Createable
45
+
46
+ def initialize(client, data)
47
+ @client = client
48
+ data.each do |key, value|
49
+ value = nil if ['', [], {}].include?(value)
50
+ instance_variable_set(:"@#{key}", value)
51
+ next if key == :created || key == :created_utc || key == :subreddits
52
+ self.class.send(:attr_reader, key)
53
+ end
54
+ class << self
55
+ alias_method :editable?, :can_edit
56
+ alias_method :description, :description_md
57
+ end
58
+ end
59
+
60
+ # Fetches a list of subreddits in the multireddit.
61
+ # @!method subreddits
62
+ # @return [Array<String>] Returns a list of subreddit display_names.
63
+ def subreddits
64
+ subreddits = @subreddits || []
65
+ subreddits.map { |subreddit| subreddit[:name] }
66
+ end
67
+
68
+ # Copy the multireddit.
69
+ # @!method copy(opts = {})
70
+ # @param opts [Hash] Optional parameters.
71
+ # @option opts :name [String] The new name of the multireddit. Defaults to
72
+ # the name of the original copy.
73
+ # @return [NeonRAW::Objects::MultiReddit] Returns the new object.
74
+ def copy(opts = {})
75
+ params = { display_name: display_name, from: path,
76
+ to: "/user/#{@client.me.name}/m/" }
77
+ params[:to] += opts[:name] || display_name
78
+ data = @client.request_data('/api/multi/copy', :post, params)
79
+ MultiReddit.new(@client, data[:data])
80
+ end
81
+
82
+ # Renames the multireddit.
83
+ # @!method rename!(new_name)
84
+ # @param new_name [String] The new name for the multireddit.
85
+ # @return [NeonRAW::objects::MultiReddit] Returns the multireddit object.
86
+ def rename!(new_name)
87
+ params = { display_name: new_name, from: path,
88
+ to: "/user/#{@client.me.name}/m/#{new_name}" }
89
+ data = @client.request_data('/api/multi/rename', :post, params)
90
+ MultiReddit.new(@client, data[:data])
91
+ end
92
+
93
+ # Deletes the multireddit.
94
+ # @!method delete!
95
+ def delete!
96
+ @client.request_nonjson("/api/multi/#{path}", :delete)
97
+ end
98
+
99
+ # Edit the multireddit.
100
+ # @!method edit(data)
101
+ # @param data [JSON] The data for the multireddit.
102
+ # @see https://www.reddit.com/dev/api#PUT_api_multi_{multipath}
103
+ def edit(data)
104
+ params = { model: data, multipath: path, expand_srs: false }
105
+ data = @client.request_data("/api/multi/#{path}", :put, params)
106
+ data[:data].each do |key, value|
107
+ value = nil if ['', [], {}].include?(value)
108
+ instance_variable_set(:"@#{key}", value)
109
+ end
110
+ end
111
+
112
+ # Adds a subreddit to the multireddit.
113
+ # @!method add_subreddit(subreddit)
114
+ # @param subreddit [String] The name of the subreddit to add.
115
+ def add_subreddit(subreddit)
116
+ params = { model: { 'name' => subreddit }.to_json, multipath: path,
117
+ srname: subreddit }
118
+ api_path = "/api/multi/#{path}/r/#{subreddit}"
119
+ @client.request_data(api_path, :put, params)
120
+ @subreddits << { name: subreddit }
121
+ end
122
+
123
+ # Remove a subreddit from the multireddit.
124
+ # @!method remove_subreddit(subreddit)
125
+ # @param subreddit [String] The name of the subreddit to remove.
126
+ def remove_subreddit(subreddit)
127
+ params = { multipath: path, srname: subreddit }
128
+ api_path = "/api/multi/#{path}/r/#{subreddit}"
129
+ @client.request_nonjson(api_path, :delete, params)
130
+ @subreddits.delete(name: subreddit)
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,90 @@
1
+ require_relative 'thing'
2
+
3
+ module NeonRAW
4
+ module Objects
5
+ # The private message object.
6
+ # @!attribute [r] author
7
+ # @return [String] Returns the author of the private message.
8
+ # @!attribute [r] body
9
+ # @return [String, nil] Returns the PM text body or nil if there is none.
10
+ # @!attribute [r] was_comment?
11
+ # @return [Boolean] Returns whether or not the object was a comment first.
12
+ # @!attribute [r] first_message
13
+ # @return [String, nil] Returns the first message ID or nil if there was
14
+ # none.
15
+ # @!attribute [r] dest
16
+ # @return [String] Returns the user whom the PM was sent to.
17
+ # @!attribute [r] body_html
18
+ # @return [String, nil] Returns the text body with HTML or nil if there
19
+ # is none.
20
+ # @!attribute [r] subreddit
21
+ # @return [String, nil] Returns the subreddit it was sent from or nil if
22
+ # it wasn't a comment.
23
+ # @!attribute [r] context
24
+ # @return [String, nil] Returns the comment permalink with context or nil
25
+ # if it wasn't a comment.
26
+ # @!attribute [r] new?
27
+ # @return [Boolean] Returns whether or not the message is unread.
28
+ # @!attribute [r] subject
29
+ # @return [String] Returns the subject of the PM.
30
+ class PrivateMessage < Thing
31
+ include Thing::Createable
32
+ include Thing::Inboxable
33
+ include Thing::Moderateable
34
+ include Thing::Repliable
35
+
36
+ def initialize(client, data)
37
+ @client = client
38
+ data.each do |key, value|
39
+ value = nil if ['', [], {}].include?(value)
40
+ instance_variable_set(:"@#{key}", value)
41
+ next if key == :created || key == :created_utc || key == :replies
42
+ self.class.send(:attr_reader, key)
43
+ end
44
+ class << self
45
+ alias_method :was_comment?, :was_comment
46
+ end
47
+ end
48
+
49
+ # Creates a list of replies to a private message.
50
+ # @!method replies
51
+ # @return [Array<NeonRAW::Objects::PrivateMessage>] Returns a list of
52
+ # replies.
53
+ def replies
54
+ return nil if @replies.nil?
55
+ messages = []
56
+ @replies[:data][:children].each do |reply|
57
+ messages << PrivateMessage.new(@client, reply[:data])
58
+ end
59
+ messages
60
+ end
61
+
62
+ # Block a user.
63
+ # @!method block!
64
+ def block!
65
+ params = { id: name }
66
+ @client.request_data('/api/block', :post, params)
67
+ end
68
+
69
+ # Toggle the read status of a message.
70
+ # @!method mark_as_read!
71
+ # @!method mark_as_unread!
72
+ %w(read unread).each do |type|
73
+ define_method :"mark_as_#{type}!" do
74
+ params = { id: name }
75
+ @client.request_data("/api/#{type}_message", :post, params)
76
+ end
77
+ end
78
+
79
+ # Set whether to mute a user in modmail or not.
80
+ # @!method mute!
81
+ # @!method unmute!
82
+ %w(mute unmute).each do |type|
83
+ define_method :"#{type}!" do
84
+ params = { id: name }
85
+ @client.request_data("/api/#{type}_message_author", :post, params)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,41 @@
1
+ require_relative 'thing'
2
+
3
+ module NeonRAW
4
+ module Objects
5
+ # The subreddit rule object.
6
+ # @!attribute [r] kind
7
+ # @return [String] Returns the kind of rule.
8
+ # @!attribute [r] description
9
+ # @return [String] Returns the description of the rule.
10
+ # @!attribute [r] short_name
11
+ # @return [String] Returns the name of the rule.
12
+ # @!attribute [r] priority
13
+ # @return [Integer] Returns the priority of the rule.
14
+ # @!attribute [r] description_html
15
+ # @return [String] Returns the description of the rule with HTML.
16
+ class Rule < Thing
17
+ include Thing::Createable
18
+
19
+ # @!method initialize(client, data)
20
+ # @param client [NeonRAW::Clients::Web/Installed/Script] The client
21
+ # object.
22
+ # @param data [Hash] The object data.
23
+ def initialize(client, data)
24
+ @client = client
25
+ data.each do |key, value|
26
+ value = nil if ['', [], {}].include?(value)
27
+ instance_variable_set(:"@#{key}", value)
28
+ next if key == :created_utc
29
+ self.class.send(:attr_reader, key)
30
+ end
31
+ end
32
+
33
+ # Says when the rule was created.
34
+ # @!method created
35
+ # @return [Time] Returns when the rule was created.
36
+ def created
37
+ Time.at(@created_utc).localtime
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,221 @@
1
+ require_relative 'thing'
2
+ require_relative 'comment'
3
+ require_relative 'morecomments'
4
+
5
+ module NeonRAW
6
+ module Objects
7
+ # The submission object.
8
+ # @!attribute [r] archived?
9
+ # @return [Boolean] Returns whether or not the submission is archived.
10
+ # @!attribute [r] author
11
+ # @return [String] Returns the author of the submission.
12
+ # @!attribute [r] author_flair_css_class
13
+ # @return [String, nil] Returns the CSS class of the submitter's flair or
14
+ # nil if there is none.
15
+ # @!attribute [r] author_flair_text
16
+ # @return [String, nil] Returns the flair's text of the submitter's flair
17
+ # or nil if there is none.
18
+ # @!attribute [r] clicked?
19
+ # @return [Boolean] Returns whether or not the submission has been
20
+ # "clicked".
21
+ # @!attribute [r] domain
22
+ # @return [String] Returns the domain of the submitted item.
23
+ # @!attribute [r] hidden?
24
+ # @return [Boolean] Returns whether or not you hid the submission.
25
+ # @!attribute [r] selfpost?
26
+ # @return [Boolean] Returns whether or not the submission is a selfpost.
27
+ # @!attribute [r] link_flair_css_class
28
+ # @return [String, nil] Returns the CSS class for the submission's link
29
+ # flair or nil if there is none.
30
+ # @!attribute [r] link_flair_text
31
+ # @return [String, nil] Returns the Link flair's text or nil if there is
32
+ # none.
33
+ # @!attribute [r] locked?
34
+ # @return [Boolean] Returns whether or not the submission is locked.
35
+ # @!attribute [r] media
36
+ # @return [Hash, nil] Returns an object containing information about a
37
+ # video and its origins or nil if there is none.
38
+ # @!attribute [r] media_embed
39
+ # @return [Hash, nil] Returns an object containing technical embed
40
+ # information or nil if there is none.
41
+ # @!attribute [r] num_comments
42
+ # @return [Integer] Returns the number of comments in the submission.
43
+ # @!attribute [r] nsfw?
44
+ # @return [Boolean] Returns whether or not the post is flagged as NSFW.
45
+ # @!attribute [r] permalink
46
+ # @return [String] Returns the permalink of the submission.
47
+ # @!attribute [r] saved?
48
+ # @return [Boolean] Returns whether or not you saved the submission.
49
+ # @!attribute [r] score
50
+ # @return [Integer] Returns the submission's karma score.
51
+ # @!attribute [r] selftext
52
+ # @return [String, nil] Returns the text of selfposts or nil if there is
53
+ # none.
54
+ # @!attribute [r] selftext_html
55
+ # @return [String, nil] Returns the text of selfposts with HTML or nil if
56
+ # there is none.
57
+ # @!attribute [r] subreddit
58
+ # @return [String] Returns the subreddit the submission was posted to.
59
+ # @!attribute [r] subreddit_id
60
+ # @return [String] Returns the ID of the subreddit where the submission
61
+ # was posted to.
62
+ # @!attribute [r] thumbnail
63
+ # @return [String, nil] Returns the URL to the thumbnail of the post or
64
+ # nil if there is none.
65
+ # @!attribute [r] title
66
+ # @return [String] Returns the title of the submission.
67
+ # @!attribute [r] url
68
+ # @return [String] Either the URL submitted (link post) or the
69
+ # submission's permalink (selfpost).
70
+ class Submission < Thing
71
+ include Thing::Createable
72
+ include Thing::Editable
73
+ include Thing::Gildable
74
+ include Thing::Moderateable
75
+ include Thing::Refreshable
76
+ include Thing::Repliable
77
+ include Thing::Saveable
78
+ include Thing::Votable
79
+
80
+ # @!method initialize(client, data)
81
+ # @param client [NeonRAW::Clients::Web/Installed/Script] The client
82
+ # object.
83
+ # @param data [Hash] The object data.
84
+ def initialize(client, data)
85
+ @client = client
86
+ data.each do |key, value|
87
+ value = nil if ['', [], {}].include?(value)
88
+ instance_variable_set(:"@#{key}", value)
89
+ next if key == :created || key == :created_utc
90
+ self.class.send(:attr_reader, key)
91
+ end
92
+ class << self
93
+ alias_method :clicked?, :clicked
94
+ alias_method :hidden?, :hidden
95
+ alias_method :selfpost?, :is_self
96
+ alias_method :locked?, :locked
97
+ alias_method :nsfw?, :over_18
98
+ alias_method :saved?, :saved
99
+ alias_method :archived?, :archived
100
+ alias_method :add_comment, :reply
101
+ end
102
+ end
103
+
104
+ # Checks whether or not the submission is a link post.
105
+ # @!method linkpost?
106
+ # @return [Boolean] Returns whether or not the submission is a link post.
107
+ def linkpost?
108
+ !@is_self
109
+ end
110
+
111
+ # Checks whether or not the submission has flair.
112
+ # @!method flair?
113
+ # @return [Boolean] Returns whether or not the submission has flair.
114
+ def flair?
115
+ !@link_flair_text.nil? || !@link_flair_css_class.nil?
116
+ end
117
+
118
+ # Fetches the comments for a submission.
119
+ # @!method comments
120
+ # @return [Array] Returns an array full of Comments and MoreComments
121
+ # objects.
122
+ def comments
123
+ data = @client.request_data(permalink + '.json', :get)
124
+ data_arr = []
125
+ data[1][:data][:children].each do |comment|
126
+ if comment[:kind] == 't1'
127
+ data_arr << Comment.new(@client, comment[:data])
128
+ elsif comment[:kind] == 'more'
129
+ data_arr << MoreComments.new(@client, comment[:data])
130
+ end
131
+ end
132
+ data_arr
133
+ end
134
+
135
+ # Flattens comment trees into a single array.
136
+ # @!method flatten_comments(comments)
137
+ # @param comments [Array] A list of comments to be checked for replies to
138
+ # flatten.
139
+ # @return [Array] Returns a list of the flattened comments.
140
+ def flatten_comments(comments)
141
+ flattened = []
142
+ stack = comments.dup
143
+
144
+ until stack.empty?
145
+ comment = stack.shift
146
+ if comment.is_a?(Comment)
147
+ replies = comment.replies
148
+ stack = replies + stack unless replies.nil?
149
+ end
150
+ flattened << comment
151
+ end
152
+ flattened
153
+ end
154
+
155
+ # Set submission visibility.
156
+ # @!method hide
157
+ # @!method unhide
158
+ # @note See lock/unlock for source code.
159
+
160
+ # Set whether or not users can comment on the submission.
161
+ # @!method lock
162
+ # @!method unlock
163
+ %w(hide unhide lock unlock).each do |type|
164
+ define_method :"#{type}" do
165
+ params = { id: name }
166
+ @client.request_data("/api/#{type}", :post, params)
167
+ end
168
+ end
169
+
170
+ # Set the submission's NSFW status.'
171
+ # @!method mark_nsfw
172
+ # @!method unmark_nsfw
173
+ %w(mark unmark).each do |type|
174
+ define_method :"#{type}_nsfw" do
175
+ params = { id: name }
176
+ @client.request_data("/api/#{type}nsfw", :post, params)
177
+ end
178
+ end
179
+
180
+ # Toggle getting inbox replies from the submission.
181
+ # @!method inbox_replies(enable)
182
+ # @param enable [Boolean] Turns it on or off.
183
+ def inbox_replies(enable)
184
+ params = { id: name, state: enable }
185
+ @client.request_data('/api/sendreplies', :post, params)
186
+ end
187
+
188
+ # Set contest mode on or off.
189
+ # @!method contest_mode(enable)
190
+ # @param enable [Boolean] Turns it on or off.
191
+ def contest_mode(enable)
192
+ params = { api_type: 'json', id: name, state: enable }
193
+ @client.request_data('/api/set_contest_mode', :post, params)
194
+ end
195
+
196
+ # Sets the suggested sort for a submission.
197
+ # @!method suggested_sort(sort)
198
+ # @param sort [Symbol] The sort to set [confidence, top, new,
199
+ # controversial, old, random, qa]
200
+ def suggested_sort(sort)
201
+ params = { api_type: 'json', id: name, sort: sort }
202
+ @client.request_data('/api/set_suggested_sort', :post, params)
203
+ end
204
+
205
+ # Sticky a submission/comment.
206
+ # @!method sticky(enable)
207
+ # @param enable [Boolean] Stickies/unstickies the thing.
208
+ def sticky(enable)
209
+ params = { api_type: 'json', id: name, state: enable }
210
+ @client.request_data('/api/set_subreddit_sticky', :post, params)
211
+ end
212
+
213
+ # The submission's shortlink.
214
+ # @!method shortlink
215
+ # @return [String] Returns the submission's shortlink.
216
+ def shortlink
217
+ "https://redd.it/#{id}"
218
+ end
219
+ end
220
+ end
221
+ end
@@ -0,0 +1,169 @@
1
+ require_relative '../thing'
2
+ # rubocop:disable Style/AccessorMethodName, Metrics/LineLength
3
+
4
+ module NeonRAW
5
+ module Objects
6
+ class Subreddit < Thing
7
+ # Methods for flairs.
8
+ module Flair
9
+ # Clears flair templates.
10
+ # @!method clear_flair_templates(flair_type)
11
+ # @param flair_type [String] The type of flair [user, link].
12
+ def clear_flair_templates(flair_type)
13
+ flairs = { 'user' => 'USER_FLAIR', 'link' => 'LINK_FLAIR' }
14
+ params = { api_type: 'json', flair_type: flairs[flair_type] }
15
+ path = "/r/#{display_name}/api/clearflairtemplates"
16
+ @client.request_data(path, :post, params)
17
+ end
18
+
19
+ # Deletes a user's flair.
20
+ # @!method delete_flair(username)
21
+ # @param username [String] The username of the user whose flair will be
22
+ # deleted.
23
+ def delete_flair(username)
24
+ params = { api_type: 'json', name: username }
25
+ path = "/r/#{display_name}/api/deleteflair"
26
+ @client.request_data(path, :post, params)
27
+ end
28
+
29
+ # Delete a flair template.
30
+ # @!method delete_flair_template(template_id)
31
+ # @param template_id [String] The template's ID.
32
+ def delete_flair_template(template_id)
33
+ params = { api_type: 'json', flair_template_id: template_id }
34
+ path = "/r/#{display_name}/api/deleteflairtemplate"
35
+ @client.request_data(path, :post, params)
36
+ end
37
+
38
+ # Sets the flair on either a link or a user.
39
+ # @!method set_flair(thing, text, opts = {})
40
+ # @param thing [NeonRAW::Objects::User/Me/Submission] The thing to flair.
41
+ # @param text [String] The flair text (64 characters max).
42
+ # @param opts [Hash] Optional parameters.
43
+ # @option opts css_class [String] The CSS class of the flair.
44
+ def set_flair(thing, text, opts = {})
45
+ params = { api_type: 'json', text: text, css_class: opts[:css_class] }
46
+ if thing.is_a?(Objects::User) || thing.is_a?(Objects::Me)
47
+ params[:name] = thing.name
48
+ elsif thing.is_a?(Objects::Submission)
49
+ params[:link] = thing.name
50
+ end
51
+ path = "/r/#{display_name}/api/flair"
52
+ @client.request_data(path, :post, params)
53
+ end
54
+
55
+ # Configure the subreddit's flairs.
56
+ # @!method flair_config(enabled, position, self_assign_enabled, link_flair_position, self_link_flair_assign)
57
+ # @param enabled [Boolean] Enable/disable flair.
58
+ # @param position [Symbol] Flair position [left, right].
59
+ # @param self_assign_enabled [Boolean] Allow/disallow users to set their
60
+ # own flair.
61
+ # @param link_flair_position [Symbol] Link flair position ['', left,
62
+ # right].
63
+ # @param self_link_flair_assign [Boolean] Allow/disallow users to set
64
+ # their own link flair.
65
+ def flair_config(enabled, position, self_assign_enabled,
66
+ link_flair_position, self_link_flair_assign)
67
+ params = {}
68
+ params[:api_type] = 'json'
69
+ params[:flair_enabled] = enabled
70
+ params[:flair_position] = position
71
+ params[:flair_self_assign_enabled] = self_assign_enabled
72
+ params[:link_flair_position] = link_flair_position
73
+ params[:link_flair_self_assign_enabled] = self_link_flair_assign
74
+ path = "/r/#{display_name}/api/flairconfig"
75
+ @client.request_data(path, :post, params)
76
+ end
77
+
78
+ # Sets flairs for multiple users.
79
+ # @!method set_many_flairs(flair_data)
80
+ # @param flair_data [String] The flair data in CSV format. Format as such:
81
+ # "User,flair text,CSS class\\nUser 2,flair text, CSS class".
82
+ # @note This API can take up to 100 lines before it starts ignoring
83
+ # things. If the flair text and CSS class are both empty strings then
84
+ # it will clear the user's flair.
85
+ def set_many_flairs(flair_data)
86
+ params = { flair_csv: flair_data }
87
+ path = "/r/#{display_name}/api/flaircsv"
88
+ @client.request_data(path, :post, params)
89
+ end
90
+
91
+ # Fetches a list of flairs.
92
+ # @!method flairlist(params = { limit: 25 })
93
+ # @param params [Hash] The parameters.
94
+ # @option params :after [String] The name of the next data block.
95
+ # @option params :before [String] The name of the previous data block.
96
+ # @option params :count [Integer] The number of items already in the list.
97
+ # @option params :limit [1..1000] The number of items to fetch.
98
+ # @option params :name [String] The username of the user whose flair you
99
+ # want.
100
+ # @option params :show [String] Literally the string 'all'.
101
+ # @return [Hash<Array<Hash>>] Returns a list of the flairs.
102
+ def flairlist(params = { limit: 25 })
103
+ path = "/r/#{display_name}/api/flairlist"
104
+ @client.request_data(path, :get, params)
105
+ end
106
+
107
+ # Gets information about a user's flair options.
108
+ # @!method flair(thing)
109
+ # @param thing [NeonRAW::Objects::Submission/User/Me] The thing to get the
110
+ # flairs of.
111
+ # @return [Hash] Returns the flair data for the thing.
112
+ def flair(thing)
113
+ params = {}
114
+ if thing.is_a?(Objects::User) || thing.is_a?(Objects::Me)
115
+ params[:name] = thing.name
116
+ elsif thing.is_a?(Objects::Submission)
117
+ params[:link] = thing.name
118
+ end
119
+ path = "/r/#{display_name}/api/flairselector"
120
+ @client.request_data(path, :post, params)
121
+ end
122
+
123
+ # Creates a flair template.
124
+ # @!method flair_template(type, text, css_class, editable, template_id)
125
+ # @param type [String] The template type [user, link].
126
+ # @param text [String] The flair text (64 characters maximum).
127
+ # @param css_class [String] The flair's CSS class.
128
+ # @param editable [Boolean] Whether or not the user can edit the flair
129
+ # text.
130
+ def flair_template(type, text, css_class, editable)
131
+ flairs = { 'user' => 'USER_FLAIR', 'link' => 'LINK_FLAIR' }
132
+ params = { api_type: 'json', css_class: css_class,
133
+ flair_type: flairs[type], text: text,
134
+ text_editable: editable }
135
+ path = "/r/#{display_name}/api/flairtemplate"
136
+ @client.request_data(path, :post, params)
137
+ end
138
+
139
+ # Select a flair.
140
+ # @!method select_flair(thing, text, template_id)
141
+ # @param thing [NeonRAW::Objects::Submission/User/Me] The thing whose flair
142
+ # will be selected.
143
+ # @param text [String] The flair text (64 characters maximum).
144
+ # @param template_id [String] The flair template ID.
145
+ def select_flair(thing, text, template_id)
146
+ params = { api_type: 'json', text: text,
147
+ flair_template_id: template_id }
148
+ params[:api_type] = 'json'
149
+ if thing.is_a?(Objects::User) || thing.is_a?(Objects::Me)
150
+ params[:name] = thing.name
151
+ elsif thing.is_a?(Objects::Submission)
152
+ params[:link] = thing.name
153
+ end
154
+ path = "/r/#{display_name}/api/selectflair"
155
+ @client.request_data(path, :post, params)
156
+ end
157
+
158
+ # Let's you enable/disable the setting of flair.
159
+ # @!method enable_set_flair(can_set_flair)
160
+ # @param can_set_flair [Boolean] Whether or not you can set flair.
161
+ def enable_set_flair(can_set_flair)
162
+ params = { api_type: 'json', flair_enabled: can_set_flair }
163
+ path = "/r/#{display_name}/api/setflairenabled"
164
+ @client.request_data(path, :post, params)
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end