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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +11 -0
- data/Gemfile +4 -0
- data/LICENSE.md +373 -0
- data/NeonRAW.gemspec +26 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/crossposter.rb +78 -0
- data/examples/flairbot.rb +60 -0
- data/examples/publicmodlogger.rb +79 -0
- data/examples/settings.yaml +4 -0
- data/examples/userhistoryscraper.rb +108 -0
- data/examples/userhistorywiper.rb +10 -0
- data/lib/NeonRAW/clients/base/listing.rb +55 -0
- data/lib/NeonRAW/clients/base/objectbuilder.rb +173 -0
- data/lib/NeonRAW/clients/base/utilities.rb +46 -0
- data/lib/NeonRAW/clients/base.rb +109 -0
- data/lib/NeonRAW/clients/installed.rb +49 -0
- data/lib/NeonRAW/clients/script.rb +34 -0
- data/lib/NeonRAW/clients/web.rb +52 -0
- data/lib/NeonRAW/errors.rb +518 -0
- data/lib/NeonRAW/objects/access.rb +44 -0
- data/lib/NeonRAW/objects/all.rb +36 -0
- data/lib/NeonRAW/objects/comment.rb +128 -0
- data/lib/NeonRAW/objects/inboxcomment.rb +54 -0
- data/lib/NeonRAW/objects/listing.rb +12 -0
- data/lib/NeonRAW/objects/me.rb +268 -0
- data/lib/NeonRAW/objects/modlogaction.rb +59 -0
- data/lib/NeonRAW/objects/modloguser.rb +35 -0
- data/lib/NeonRAW/objects/morecomments.rb +33 -0
- data/lib/NeonRAW/objects/multireddit.rb +134 -0
- data/lib/NeonRAW/objects/privatemessage.rb +90 -0
- data/lib/NeonRAW/objects/rule.rb +41 -0
- data/lib/NeonRAW/objects/submission.rb +221 -0
- data/lib/NeonRAW/objects/subreddit/flair.rb +169 -0
- data/lib/NeonRAW/objects/subreddit/moderation.rb +200 -0
- data/lib/NeonRAW/objects/subreddit/utilities.rb +73 -0
- data/lib/NeonRAW/objects/subreddit/wiki.rb +31 -0
- data/lib/NeonRAW/objects/subreddit.rb +223 -0
- data/lib/NeonRAW/objects/thing/createable.rb +22 -0
- data/lib/NeonRAW/objects/thing/editable.rb +46 -0
- data/lib/NeonRAW/objects/thing/gildable.rb +29 -0
- data/lib/NeonRAW/objects/thing/inboxable.rb +26 -0
- data/lib/NeonRAW/objects/thing/moderateable.rb +98 -0
- data/lib/NeonRAW/objects/thing/refreshable.rb +21 -0
- data/lib/NeonRAW/objects/thing/repliable.rb +23 -0
- data/lib/NeonRAW/objects/thing/saveable.rb +26 -0
- data/lib/NeonRAW/objects/thing/votable.rb +69 -0
- data/lib/NeonRAW/objects/thing.rb +24 -0
- data/lib/NeonRAW/objects/trophy.rb +25 -0
- data/lib/NeonRAW/objects/user.rb +147 -0
- data/lib/NeonRAW/objects/wikipage.rb +176 -0
- data/lib/NeonRAW/objects/wikipagerevision.rb +45 -0
- data/lib/NeonRAW/version.rb +3 -0
- data/lib/NeonRAW.rb +43 -0
- metadata +161 -0
@@ -0,0 +1,200 @@
|
|
1
|
+
require_relative '../thing'
|
2
|
+
require_relative '../modloguser'
|
3
|
+
require_relative '../listing'
|
4
|
+
|
5
|
+
module NeonRAW
|
6
|
+
module Objects
|
7
|
+
class Subreddit < Thing
|
8
|
+
# Methods for moderators.
|
9
|
+
module Moderation
|
10
|
+
# @!group Listing
|
11
|
+
# Fetches the modlog for the subreddit.
|
12
|
+
# @!method modlog(params = { limit: 25 })
|
13
|
+
# @param params [Hash] The parameters.
|
14
|
+
# @option params :after [String] Fullname of the next data block.
|
15
|
+
# @option params :before [String] Fullname of the previous data block.
|
16
|
+
# @option params :count [Integer] The number of items already in the
|
17
|
+
# listing.
|
18
|
+
# @option params :limit [1..500] The number of listing items to fetch.
|
19
|
+
# @option params :mod [String] The moderator to filter actions by. Also
|
20
|
+
# 'a' can be given to filter by admin actions.
|
21
|
+
# @option params :show [String] Literally the string 'all'.
|
22
|
+
# @option params :type [String] The type of mod action to filter by
|
23
|
+
# [banuser, unbanuser, removelink, approvelink, removecomment,
|
24
|
+
# approvecomment, addmoderator, invitemoderator, uninvitemoderator,
|
25
|
+
# acceptmoderatorinvite, removemoderator, addcontributor,
|
26
|
+
# removecontributor, editsettings, editflair, distinguish, marknsfw,
|
27
|
+
# wikibanned, wikicontributor, wikiunbanned, wikipagelisted,
|
28
|
+
# removewikicontributor, wikirevise, wikipermlevel, ignorereports,
|
29
|
+
# unignorereports, setpermissions, setsuggestedsort, sticky, unsticky,
|
30
|
+
# setcontestmode, unsetcontestmode, lock, unlock, muteuser,
|
31
|
+
# unmuteuser, createrule, editrule, deleterule]
|
32
|
+
# @return [NeonRAW::Objects::Listing] Returns a listing of the modlog
|
33
|
+
# actions.
|
34
|
+
def modlog(params = { limit: 25 })
|
35
|
+
path = "/r/#{display_name}/about/log.json"
|
36
|
+
@client.send(:build_listing, path, params)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Fetches the subreddit's modmail.
|
40
|
+
# @!method modmail(params = { limit: 25 })
|
41
|
+
# @param params [Hash] The parameters.
|
42
|
+
# @option params :after [String] Fullname of the next data block.
|
43
|
+
# @option params :before [String] Fullname of the previous data block.
|
44
|
+
# @option params :count [Integer] The number of things already in the
|
45
|
+
# listing.
|
46
|
+
# @option params :limit [1..1000] The number of listing items to fetch.
|
47
|
+
# @option params :only [Symbol] Only fetch either [links, comments].
|
48
|
+
# @option params :show [String] Literally the string 'all'.
|
49
|
+
# @return [NeonRAW::Objects::Listing] Returns a listing with all the
|
50
|
+
# things.
|
51
|
+
def modmail(params = { limit: 25 })
|
52
|
+
path = "/r/#{display_name}/about/message/inbox"
|
53
|
+
@client.send(:build_listing, path, params)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Fetches things for review by moderators.
|
57
|
+
# @!method reported(params = { limit: 25 })
|
58
|
+
# @!method spam(params = { limit: 25 })
|
59
|
+
# @!method modqueue(params = { limit: 25 })
|
60
|
+
# @!method unmoderated(params = { limit: 25 })
|
61
|
+
# @!method edited(params = { limit: 25 })
|
62
|
+
# @param params [Hash] The parameters.
|
63
|
+
# @option params :after [String] Fullname of the next data block.
|
64
|
+
# @option params :before [String] Fullname of the previous data block.
|
65
|
+
# @option params :count [Integer] The number of things already in the
|
66
|
+
# listing.
|
67
|
+
# @option params :limit [1..1000] The number of listing items to fetch.
|
68
|
+
# @option params :only [Symbol] Only fetch either [links, comments].
|
69
|
+
# @option params :show [String] Literally the string 'all'.
|
70
|
+
# @return [NeonRAW::Objects::Listing] Returns a listing with all the
|
71
|
+
# things.
|
72
|
+
%w(reported spam modqueue unmoderated edited).each do |type|
|
73
|
+
define_method :"#{type}" do |params = { limit: 25 }|
|
74
|
+
type = 'reports' if type == 'reported'
|
75
|
+
path = "/r/#{display_name}/about/#{type}.json"
|
76
|
+
@client.send(:build_listing, path, params)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Fetches users with altered privileges.
|
81
|
+
# @!method banned(params = { limit: 25 })
|
82
|
+
# @!method muted(params = { limit: 25 })
|
83
|
+
# @!method wikibanned(params = { limit: 25 })
|
84
|
+
# @!method contributors(params = { limit: 25 })
|
85
|
+
# @!method wikicontributors(params = { limit: 25 })
|
86
|
+
# @!method moderators(params = { limit: 25 })
|
87
|
+
# @param params [Hash] The parameters.
|
88
|
+
# @option params :after [String] Fullname of the next data block.
|
89
|
+
# @option params :before [String] Fullname of the previous data block.
|
90
|
+
# @option params :count [Integer] Number of items already in the
|
91
|
+
# listing.
|
92
|
+
# @option params :limit [1..1000] The number of listing items to fetch.
|
93
|
+
# @option params :show [String] Literally the string 'all'.
|
94
|
+
# @option params :user [String] The name of the user to fetch.
|
95
|
+
# @return [NeonRAW::Objects::Listing] Returns a listing of the users.
|
96
|
+
%w(banned muted wikibanned
|
97
|
+
contributors wikicontributors moderators).each do |type|
|
98
|
+
define_method :"#{type}" do |params = { limit: 25 }|
|
99
|
+
data_arr = []
|
100
|
+
path = "/r/#{display_name}/about/#{type}"
|
101
|
+
until data_arr.length == params[:limit]
|
102
|
+
data = @client.request_data(path, :get, params)
|
103
|
+
params[:after] = data[:data][:after]
|
104
|
+
params[:before] = data[:data][:before]
|
105
|
+
data[:data][:children].each do |item|
|
106
|
+
data_arr << ModLogUser.new(@client, item)
|
107
|
+
break if data_arr.length == params[:limit]
|
108
|
+
end
|
109
|
+
break if params[:after].nil?
|
110
|
+
end
|
111
|
+
listing = Listing.new(params[:after], params[:before])
|
112
|
+
data_arr.each { |user| listing << user }
|
113
|
+
listing
|
114
|
+
end
|
115
|
+
end
|
116
|
+
# @!endgroup
|
117
|
+
|
118
|
+
# Accept a pending mod invite to the subreddit.
|
119
|
+
# @!method accept_mod_invite!
|
120
|
+
def accept_mod_invite!
|
121
|
+
params = { api_type: 'json' }
|
122
|
+
path = "/r/#{display_name}/api/accept_moderator_invite"
|
123
|
+
@client.request_data(path, :post, params)
|
124
|
+
refresh!
|
125
|
+
end
|
126
|
+
|
127
|
+
# Ditch your privileged status in the subreddit.
|
128
|
+
# @!method leave_contributor!
|
129
|
+
# @!method leave_moderator!
|
130
|
+
%w(contributor moderator).each do |type|
|
131
|
+
define_method :"leave_#{type}!" do
|
132
|
+
params = { id: name }
|
133
|
+
@client.request_data("/api/leave#{type}", :post, params)
|
134
|
+
refresh!
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Upload a subreddit image.
|
139
|
+
# @!method upload_image!(file_path, file_type, image_name, upload_type)
|
140
|
+
# @param file_path [String] The path to the file (500 KiB maximum).
|
141
|
+
# @param file_type [String] The file extension [png, jpg].
|
142
|
+
# @param image_name [String] The name of the image.
|
143
|
+
# @param upload_type [String] The type of upload [img, header, icon,
|
144
|
+
# banner].
|
145
|
+
def upload_image!(file_path, file_type, image_name, upload_type)
|
146
|
+
params = { img_type: file_type, name: image_name,
|
147
|
+
upload_type: upload_type }
|
148
|
+
path = "/r/#{display_name}/api/upload_sr_img"
|
149
|
+
file = File.open(file_path, 'r')
|
150
|
+
@client.request_data(path, :post, params, file: file)
|
151
|
+
refresh!
|
152
|
+
end
|
153
|
+
|
154
|
+
# Remove a subreddit image.
|
155
|
+
# @!method remove_banner!
|
156
|
+
# @!method remove_header!
|
157
|
+
# @!method remove_icon!
|
158
|
+
%w(banner header icon).each do |type|
|
159
|
+
define_method :"remove_#{type}!" do
|
160
|
+
params = { api_type: 'json' }
|
161
|
+
path = "/r/#{display_name}/api/delete_sr_#{type}"
|
162
|
+
@client.request_data(path, :post, params)
|
163
|
+
refresh!
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Remove a subreddit image.
|
168
|
+
# @!method remove_image!(image)
|
169
|
+
# @param image [String] The name of the image.
|
170
|
+
def remove_image!(image)
|
171
|
+
params = { api_type: 'json', img_name: image }
|
172
|
+
path = "/r/#{display_name}/api/delete_sr_img"
|
173
|
+
@client.request_data(path, :post, params)
|
174
|
+
refresh!
|
175
|
+
end
|
176
|
+
|
177
|
+
# Edit the subreddit's stylesheet.
|
178
|
+
# @!method edit_stylesheet(data, opts = {})
|
179
|
+
# @param data [String] The CSS for the stylesheet.
|
180
|
+
# @param opts [Hash] Optional parameters.
|
181
|
+
# @option opts :reason [String] The reason for the edit (256 characters
|
182
|
+
# maximum).
|
183
|
+
def edit_stylesheet(data, opts = {})
|
184
|
+
params = { api_type: 'json', op: 'save',
|
185
|
+
reason: opts[:reason], stylesheet_contents: data }
|
186
|
+
path = "/r/#{display_name}/api/subreddit_stylesheet"
|
187
|
+
@client.request_data(path, :post, params)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Fetches the settings for the subreddit.
|
191
|
+
# @!method settings
|
192
|
+
# @return [Hash] Returns the subreddit's settings.
|
193
|
+
def settings
|
194
|
+
path = "/r/#{display_name}/about/edit.json"
|
195
|
+
@client.request_data(path, :get)[:data]
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module NeonRAW
|
2
|
+
module Objects
|
3
|
+
class Subreddit
|
4
|
+
# Utilities for subreddits.
|
5
|
+
module Utilities
|
6
|
+
# Get info on a link/comment/subreddit.
|
7
|
+
# @!method info(params = {})
|
8
|
+
# @param params [Hash] The parameters.
|
9
|
+
# @option params :id [String] The fullname of the thing.
|
10
|
+
# @option params :url [String] The URL of the thing.
|
11
|
+
# @return [NeonRAW::Objects::Comment/Submission/Subreddit] Returns the
|
12
|
+
# object.
|
13
|
+
def info(params = {})
|
14
|
+
path = "/r/#{display_name}/api/info"
|
15
|
+
data = @client.request_data(path, :get, params)
|
16
|
+
case data[:data][:children][0][:kind]
|
17
|
+
when 't1'
|
18
|
+
Comment.new(@client, data[:data][:children][0][:data])
|
19
|
+
when 't3'
|
20
|
+
Submission.new(@client, data[:data][:children][0][:data])
|
21
|
+
when 't5'
|
22
|
+
Subreddit.new(@client, data[:data][:children][0][:data])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Submit a thread to the subreddit.
|
27
|
+
# @!method submit(title, params = {})
|
28
|
+
# @param title [String] The title of the submission (300
|
29
|
+
# characters maximum).
|
30
|
+
# @param params [Hash] The parameters.
|
31
|
+
# @option params :text [String] The text of the submission (selfpost).
|
32
|
+
# @option params :url [String] The URL of the submission (link post).
|
33
|
+
# @return [NeonRAW::Objects::Submission] Returns the submission object.
|
34
|
+
def submit(title, params = {})
|
35
|
+
params[:kind] = 'self' if params[:text]
|
36
|
+
params[:kind] = 'link' if params[:url]
|
37
|
+
params[:sr] = display_name
|
38
|
+
params[:title] = title
|
39
|
+
response = @client.request_data('/api/submit', :post, params)
|
40
|
+
# Seriously though, fucking convoluted data structures.
|
41
|
+
submission_id = response[:jquery].last[3].first.split('/')[6]
|
42
|
+
info(id: 't3_' + submission_id)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Gets recommended subreddits for the subreddit.
|
46
|
+
# @!method recommended_subreddits(opts = {})
|
47
|
+
# @param opts [Hash] Optional parameters.
|
48
|
+
# @option opts :omit [String] A comma-separated list of subreddits to
|
49
|
+
# omit from the results.
|
50
|
+
# @return [Array<String>] Returns a list of the recommended subreddits.
|
51
|
+
def recommended_subreddits(opts = {})
|
52
|
+
params = { omit: opts[:omit], srnames: display_name }
|
53
|
+
path = "/api/recommend/sr/#{display_name}"
|
54
|
+
data = @client.request_data(path, :get, params)
|
55
|
+
data.map { |subreddit| subreddit[:sr_name] }
|
56
|
+
end
|
57
|
+
|
58
|
+
# Toggle your subscription to the subreddit.
|
59
|
+
# @!method subscribe!
|
60
|
+
# @!method unsubscribe!
|
61
|
+
%w(subscribe unsubscribe).each do |type|
|
62
|
+
define_method :"#{type}!" do
|
63
|
+
params = { sr: name }
|
64
|
+
params[:action] = 'sub' if type == 'subscribe'
|
65
|
+
params[:action] = 'unsub' if type == 'unsubscribe'
|
66
|
+
@client.request_data('/api/subscribe', :post, params)
|
67
|
+
refresh!
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../thing'
|
2
|
+
require_relative '../wikipage'
|
3
|
+
|
4
|
+
module NeonRAW
|
5
|
+
module Objects
|
6
|
+
class Subreddit < Thing
|
7
|
+
# Methods for wiki pages.
|
8
|
+
module WikiPages
|
9
|
+
# Fetches the wiki page.
|
10
|
+
# @!method wikipage(page)
|
11
|
+
# @param page [String] The name of the page.
|
12
|
+
# @return [NeonRAW::Objects::WikiPage] Returns the wiki page object.
|
13
|
+
def wikipage(page)
|
14
|
+
params = { page: page }
|
15
|
+
path = "/r/#{display_name}/wiki/#{page}"
|
16
|
+
data = @client.request_data(path, :get, params)
|
17
|
+
data[:data][:name] = page
|
18
|
+
data[:data][:subreddit] = display_name
|
19
|
+
WikiPage.new(@client, data[:data])
|
20
|
+
end
|
21
|
+
|
22
|
+
# Fetches a list of wiki pages for the subreddit.
|
23
|
+
# @!method wikipages
|
24
|
+
# @return [Array<String>] Returns a list of wiki pages.
|
25
|
+
def wikipages
|
26
|
+
@client.request_data("/r/#{display_name}/wiki/pages", :get)[:data]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
require_relative '../objects/submission'
|
2
|
+
require_relative '../objects/listing'
|
3
|
+
require_relative '../objects/comment'
|
4
|
+
require_relative '../objects/thing'
|
5
|
+
require_relative '../objects/rule'
|
6
|
+
require_relative 'subreddit/flair'
|
7
|
+
require_relative 'subreddit/moderation'
|
8
|
+
require_relative 'subreddit/utilities'
|
9
|
+
require_relative 'subreddit/wiki'
|
10
|
+
# rubocop:disable Metrics/MethodLength
|
11
|
+
|
12
|
+
module NeonRAW
|
13
|
+
module Objects
|
14
|
+
# The subreddit object.
|
15
|
+
# @!attribute [r] subscribed?
|
16
|
+
# @return [Boolean] Returns whether or not you're subscribed
|
17
|
+
# to the subreddit.
|
18
|
+
# @!attribute [r] approved_submitter?
|
19
|
+
# @return [Boolean] Returns whether or not you're an approved
|
20
|
+
# submitter to the subreddit.
|
21
|
+
# @!attribute [r] moderator?
|
22
|
+
# @return [Boolean] Returns whether or not you're a moderator
|
23
|
+
# of the subreddit.
|
24
|
+
# @!attribute [r] im_banned?
|
25
|
+
# @return [Boolean] Returns whether or not you're banned from
|
26
|
+
# the subreddit.
|
27
|
+
# @!attribute [r] collapse_deleted_comments?
|
28
|
+
# @return [Boolean] Returns whether or not the subreddit
|
29
|
+
# collapses deleted comments.
|
30
|
+
# @!attribute [r] nsfw?
|
31
|
+
# @return [Boolean] Returns whether or not the subreddit is
|
32
|
+
# marked for adult content.
|
33
|
+
# @!attribute [r] muted?
|
34
|
+
# @return [Boolean] Returns whether or not you're muted from
|
35
|
+
# the subreddit's modmail.
|
36
|
+
# @!attribute [r] quarantined?
|
37
|
+
# @return [Boolean] Returns whether or not the subreddit is
|
38
|
+
# quarantined.
|
39
|
+
# @!attribute [r] public_traffic?
|
40
|
+
# @return [Boolean] Returns whether or not the subreddit made
|
41
|
+
# their traffic stats public.
|
42
|
+
# @!attribute [r] theme_enabled?
|
43
|
+
# @return [Boolean] Returns whether or not you have the
|
44
|
+
# subreddit theme enabled.
|
45
|
+
# @!attribute [r] wiki_enabled?
|
46
|
+
# @return [Boolean] Returns whether or not the subreddit has
|
47
|
+
# its wiki enabled.
|
48
|
+
# @!attribute [r] hide_ads?
|
49
|
+
# @return [Boolean] Returns whether or not the subreddit hides
|
50
|
+
# ads.
|
51
|
+
# @!attribute [r] banner_img
|
52
|
+
# @return [String, nil] Returns a string container a link to the
|
53
|
+
# banner image or nil if there is none.
|
54
|
+
# @!attribute [r] submit_text_html
|
55
|
+
# @return [String, nil] Returns the text with HTML included in the
|
56
|
+
# thread submission page or nil if there is none..
|
57
|
+
# @!attribute [r] submit_text
|
58
|
+
# @return [String, nil] Returns the text included in the thread
|
59
|
+
# submission page or nil if there is none.
|
60
|
+
# @!attribute [r] display_name
|
61
|
+
# @return [String] Returns the display name of the subreddit.
|
62
|
+
# @!attribute [r] header_img
|
63
|
+
# @return [String, nil] Returns the link to the header image
|
64
|
+
# or nil if there is none.
|
65
|
+
# @!attribute [r] sidebar_html
|
66
|
+
# @return [String, nil] Returns the subreddit's sidebar text
|
67
|
+
# with HTML or nil if there is none..
|
68
|
+
# @!attribute [r] title
|
69
|
+
# @return [String] Returns the subreddit's title.
|
70
|
+
# @!attribute [r] public_description
|
71
|
+
# @return [String, nil] Returns the subreddit's public description or nil
|
72
|
+
# if there is none..
|
73
|
+
# @!attribute [r] public_description_html
|
74
|
+
# @return [String, nil] Returns the subreddit's public description
|
75
|
+
# with HTML included or nil if there is none.
|
76
|
+
# @!attribute [r] suggested_comment_sort
|
77
|
+
# @return [String, nil] Returns the subreddit's suggested
|
78
|
+
# comment sort or nil if there isn't one [hot, top, new,
|
79
|
+
# old, controversial, random]
|
80
|
+
# @!attribute [r] submit_link_label
|
81
|
+
# @return [String, nil] Returns the subreddit's custom label
|
82
|
+
# for the submit link button or nil if there is none.
|
83
|
+
# @!attribute [r] submit_text_label
|
84
|
+
# @return [String, nil] Returns the subreddit's custom label
|
85
|
+
# for the submit text button or nil if there is none.
|
86
|
+
# @!attribute [r] header_title
|
87
|
+
# @return [String, nil] Returns the header title or nil if
|
88
|
+
# there is none.
|
89
|
+
# @!attribute [r] sidebar
|
90
|
+
# @return [String] Returns the subreddit's sidebar text.
|
91
|
+
# @!attribute [r] accounts_active
|
92
|
+
# @return [Integer] Returns the number of users online browsing
|
93
|
+
# the subreddit.
|
94
|
+
# @!attribute [r] header_size
|
95
|
+
# @return [Array<Integer, Integer>, nil] Returns an array containing the
|
96
|
+
# header's dimensions or nil if there isn't one.
|
97
|
+
# @!attribute [r] subscribers
|
98
|
+
# @return [Integer] Returns the number of subscribers the
|
99
|
+
# subreddit has.
|
100
|
+
# @!attribute [r] lang
|
101
|
+
# @return [String] Returns the subreddit's primary language.
|
102
|
+
# @!attribute [r] url
|
103
|
+
# @return [String] Returns the subreddit's URL.
|
104
|
+
# @!attribute [r] comment_score_hide_mins
|
105
|
+
# @return [Integer] Returns the number of minutes that comment
|
106
|
+
# scores are hidden.
|
107
|
+
# @!attribute [r] subreddit_type
|
108
|
+
# @return [String] Returns the type of subreddit [public,
|
109
|
+
# restricted, private, gold_restricted, archived].
|
110
|
+
# @!attribute [r] submission_type
|
111
|
+
# @return [String] Returns the type of submissions allowed
|
112
|
+
# to be posted [any, link, self].
|
113
|
+
class Subreddit < Thing
|
114
|
+
include Thing::Createable
|
115
|
+
include Thing::Refreshable
|
116
|
+
include Subreddit::Flair
|
117
|
+
include Subreddit::Moderation
|
118
|
+
include Subreddit::Utilities
|
119
|
+
include Subreddit::WikiPages
|
120
|
+
|
121
|
+
# @!method initialize(client, data)
|
122
|
+
# @param client [NeonRAW::Clients::Web/Installed/Script] The client.
|
123
|
+
# @param data [Hash] The object data.
|
124
|
+
def initialize(client, data)
|
125
|
+
@client = client
|
126
|
+
data.each do |key, value|
|
127
|
+
value = nil if ['', [], {}].include?(value)
|
128
|
+
instance_variable_set(:"@#{key}", value)
|
129
|
+
next if key == :created || key == :created_utc
|
130
|
+
self.class.send(:attr_reader, key)
|
131
|
+
end
|
132
|
+
class << self
|
133
|
+
alias_method :subscribed?, :user_is_subscriber
|
134
|
+
alias_method :approved_submitter?, :user_is_contributor
|
135
|
+
alias_method :moderator?, :user_is_moderator
|
136
|
+
alias_method :im_banned?, :user_is_banned
|
137
|
+
alias_method :collapses_deleted_comments?, :collapse_deleted_comments
|
138
|
+
alias_method :nsfw?, :over18
|
139
|
+
alias_method :muted?, :user_is_muted
|
140
|
+
alias_method :quarantined?, :quarantine
|
141
|
+
alias_method :public_traffic?, :public_traffic
|
142
|
+
alias_method :theme_enabled?, :user_sr_theme_enabled
|
143
|
+
alias_method :wiki_enabled?, :wiki_enabled
|
144
|
+
alias_method :hide_ads?, :hide_ads
|
145
|
+
alias_method :sidebar, :description
|
146
|
+
alias_method :sidebar_html, :description_html
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# Fetches the subreddit's rules.
|
151
|
+
# @!method rules
|
152
|
+
# @return [Array<NeonRAW::Objects::Rule>] Returns a list of the rules.
|
153
|
+
def rules
|
154
|
+
data_arr = []
|
155
|
+
data = @client.request_data("/r/#{display_name}/about/rules.json", :get)
|
156
|
+
data[:rules].each do |rule|
|
157
|
+
data_arr << Rule.new(@client, rule)
|
158
|
+
end
|
159
|
+
data_arr
|
160
|
+
end
|
161
|
+
|
162
|
+
# Fetches the subreddit's stylesheet.
|
163
|
+
# @!method stylesheet
|
164
|
+
# @return [Hash<Array, String, String>] Returns the stylesheet data.
|
165
|
+
def stylesheet
|
166
|
+
path = "/r/#{display_name}/about/stylesheet.json"
|
167
|
+
@client.request_data(path, :get)[:data]
|
168
|
+
end
|
169
|
+
|
170
|
+
# @!group Listings
|
171
|
+
# Fetches a listing from the subreddit.
|
172
|
+
# @!method hot(params = { limit: 25 })
|
173
|
+
# @!method rising(params = { limit: 25 })
|
174
|
+
# @!method top(params = { limit: 25 })
|
175
|
+
# @!method old(params = { limit: 25 })
|
176
|
+
# @!method new(params = { limit: 25 })
|
177
|
+
# @!method controversial(params = { limit: 25 })
|
178
|
+
# @!method comments(param = { limit: 25 })
|
179
|
+
# @param params [Hash] The parameters for the request.
|
180
|
+
# @option params :t [String] Time for relevant sorting [hour, day, week,
|
181
|
+
# month, year, all]
|
182
|
+
# @option params :after [String] The name of the next data block.
|
183
|
+
# @option params :before [String] The name of the previous data block.
|
184
|
+
# @option params :count [Integer] The number of items already in the
|
185
|
+
# listing.
|
186
|
+
# @option params :limit [1..1000] The number of items to fetch.
|
187
|
+
# @option params :show [String] Literally the string 'all'.
|
188
|
+
# @return [NeonRAW::Objects::Listing] Returns the listing object.
|
189
|
+
%w(hot rising top old new controversial comments).each do |type|
|
190
|
+
define_method :"#{type}" do |params = { limit: 25 }|
|
191
|
+
path = "/r/#{display_name}/#{type}/.json"
|
192
|
+
@client.send(:build_listing, path, params)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Search for links in the subreddit.
|
197
|
+
# @!method search(query, opts = { limit: 25 })
|
198
|
+
# @param query [String] The text to search for (512 characters maximum).
|
199
|
+
# @param opts [Hash] Optional parameters.
|
200
|
+
# @option opts :after [String] Fullname of the next data block.
|
201
|
+
# @option opts :before [String] Fullname of the previous data block.
|
202
|
+
# @option opts :count [Integer] Number of items already in the listing.
|
203
|
+
# @option opts :include_facets [Boolean] Whether or not to include facets.
|
204
|
+
# @option opts :limit [1..1000] The number of listing items to fetch.
|
205
|
+
# @option opts :show [String] Literally the string 'all'.
|
206
|
+
# @option opts :sort [String] The sort of the data [relevance, hot, top,
|
207
|
+
# new, comments].
|
208
|
+
# @option opts :syntax [String] The type of search you want [cloudsearch,
|
209
|
+
# lucene, plain]
|
210
|
+
# @option opts :t [String] Time for relevant sorting [hour, day, week,
|
211
|
+
# month, year, all]
|
212
|
+
def search(query, opts = { limit: 25 })
|
213
|
+
params = opts
|
214
|
+
params[:q] = query
|
215
|
+
params[:restrict_sr] = true
|
216
|
+
params[:sr_detail] = false
|
217
|
+
params[:type] = 'link'
|
218
|
+
@client.send(:build_listing, "/r/#{display_name}/search", params)
|
219
|
+
end
|
220
|
+
# @!endgroup
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module NeonRAW
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Methods for things that can be created.
|
5
|
+
module Createable
|
6
|
+
# Fetch when the thing was created.
|
7
|
+
# @!method created
|
8
|
+
# @return [Time] Returns a Time object containing the time/date.
|
9
|
+
def created
|
10
|
+
Time.at(@created)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Fetch when the thing was created UTC.
|
14
|
+
# @!method created_utc
|
15
|
+
# @return [Time] Returns a Time object containing the time/date.
|
16
|
+
def created_utc
|
17
|
+
Time.at(@created_utc)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module NeonRAW
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Methods for editing.
|
5
|
+
module Editable
|
6
|
+
# Checks whether or not the thing was edited.
|
7
|
+
# @!method edited?
|
8
|
+
# @return [Boolean] Returns whether or not the comment was edited.
|
9
|
+
def edited?
|
10
|
+
if @edited != false
|
11
|
+
true
|
12
|
+
else
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Gets the timestamp of the thing's lastest edit.
|
18
|
+
# @!method last_edit
|
19
|
+
# @return [Float, nil] Returns the UNIX timestamp of the edit or nil if
|
20
|
+
# the comment hasn't been edited.
|
21
|
+
# @note If you crawl some old comments on /r/reddit.com this may return
|
22
|
+
# true instead of the timestamp.
|
23
|
+
def last_edit
|
24
|
+
nil || @edited if @edited != false
|
25
|
+
end
|
26
|
+
|
27
|
+
# Edit a thing.
|
28
|
+
# @!method edit!(text)
|
29
|
+
# @param text [String] The text to replace the current text with.
|
30
|
+
def edit!(text)
|
31
|
+
params = { api_type: 'json', text: text, thing_id: name }
|
32
|
+
@client.request_data('/api/editusertext', :post, params)
|
33
|
+
refresh!
|
34
|
+
end
|
35
|
+
|
36
|
+
# Deletes the thing.
|
37
|
+
# @!method delete!
|
38
|
+
def delete!
|
39
|
+
params = { id: name }
|
40
|
+
@client.request_data('/api/del', :post, params)
|
41
|
+
refresh!
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module NeonRAW
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Methods for things that can be gilded.
|
5
|
+
module Gildable
|
6
|
+
# Checks whether a comment was gilded or not.
|
7
|
+
# @!method gilded?
|
8
|
+
# @return [Boolean] Returns whether or not the comment was gilded.
|
9
|
+
def gilded?
|
10
|
+
if @gilded > 0
|
11
|
+
true
|
12
|
+
else
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Give a thing gold.
|
18
|
+
# @!method gild(quantity)
|
19
|
+
# @param quantity [Integer] The amount of gold to give.
|
20
|
+
def gild(quantity)
|
21
|
+
quantity.times do
|
22
|
+
@client.request_data("/api/v1/gold/gild/#{name}", :post)
|
23
|
+
end
|
24
|
+
refresh!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module NeonRAW
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Methods for things that appear in your inbox.
|
5
|
+
module Inboxable
|
6
|
+
# Changes the read status of a PM.
|
7
|
+
# @!method mark_as_read
|
8
|
+
# @!method mark_as_unread
|
9
|
+
%w(read unread).each do |type|
|
10
|
+
define_method :"mark_as_#{type}" do
|
11
|
+
params = { id: name }
|
12
|
+
@client.request_data("/api/#{type}_message", :post, params)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Add a text reply to a comment/private message.
|
17
|
+
# @!method reply(text)
|
18
|
+
# @param text [String] The text you want to reply with.
|
19
|
+
def reply(text)
|
20
|
+
params = { api_type: 'json', text: text, thing_id: name }
|
21
|
+
@client.request_data('/api/comment', :post, params)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|