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,36 @@
|
|
1
|
+
module NeonRAW
|
2
|
+
module Objects
|
3
|
+
# The object for /r/all.
|
4
|
+
class All
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
# @!group Listings
|
10
|
+
# Fetches a listing from /r/all.
|
11
|
+
# @!method hot(params = { limit: 25 })
|
12
|
+
# @!method rising(params = { limit: 25 })
|
13
|
+
# @!method top(params = { limit: 25 })
|
14
|
+
# @!method old(params = { limit: 25 })
|
15
|
+
# @!method new(params = { limit: 25 })
|
16
|
+
# @!method controversial(params = { limit: 25 })
|
17
|
+
# @!method comments(param = { limit: 25 })
|
18
|
+
# @param params [Hash] The parameters for the request.
|
19
|
+
# @option params :t [String] Time for relevant sorting [hour, day, week,
|
20
|
+
# month, year, all]
|
21
|
+
# @option params :after [String] The name of the next data block.
|
22
|
+
# @option params :before [String] The name of the previous data block.
|
23
|
+
# @option params :count [Integer] The number of items already in the
|
24
|
+
# listing.
|
25
|
+
# @option params :limit [1..1000] The number of items to fetch.
|
26
|
+
# @option params :show [String] Literally the string 'all'.
|
27
|
+
# @return [NeonRAW::Objects::Listing] Returns the listing object.
|
28
|
+
%w(hot rising top old new controversial comments).each do |type|
|
29
|
+
define_method :"#{type}" do |params = { limit: 25 }|
|
30
|
+
path = "/r/all/#{type}/.json"
|
31
|
+
@client.send(:build_listing, path, params)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require_relative 'thing'
|
2
|
+
|
3
|
+
module NeonRAW
|
4
|
+
module Objects
|
5
|
+
# The comment object.
|
6
|
+
# @!attribute [r] approved_by
|
7
|
+
# @return [String, nil] Returns which mod approved the comment or nil if
|
8
|
+
# none did or you aren't a moderator of that subreddit.
|
9
|
+
# @!attribute [r] archived?
|
10
|
+
# @return [Boolean] Returns whether or not the comment is archived.
|
11
|
+
# @!attribute [r] author
|
12
|
+
# @return [String] Returns the author of the comment.
|
13
|
+
# @!attribute [r] author_flair_css_class
|
14
|
+
# @return [String, nil] Returns the author's flair CSS class or nil if
|
15
|
+
# there is none.
|
16
|
+
# @!attribute [r] author_flair_text
|
17
|
+
# @return [String, nil] Returns the author's flair text or nil if there
|
18
|
+
# is none.
|
19
|
+
# @!attribute [r] removed_by
|
20
|
+
# @return [String, nil] Returns which mod removed the comment or nil if
|
21
|
+
# none did or you aren't a moderator of that subreddit.
|
22
|
+
# @!attribute [r] body
|
23
|
+
# @return [String, nil] Returns the text body of the comment or nil if
|
24
|
+
# there isn't one.
|
25
|
+
# @!attribute [r] body_html
|
26
|
+
# @return [String, nil] Returns the text body of the comment with HTML or
|
27
|
+
# nil if there isn't one.
|
28
|
+
# @!attribute [r] gold_count
|
29
|
+
# @return [Integer] Returns the amount of gold a comment has been given.
|
30
|
+
# @!attribute [r] link_author
|
31
|
+
# @return [String] Returns the author of the submission link that the
|
32
|
+
# comment was made in response to.
|
33
|
+
# @note This attribute only exists if the comment is fetched from outside
|
34
|
+
# the thread it was posted in (so like user pages,
|
35
|
+
# /r/subreddit/comments, that type of stuff).
|
36
|
+
# @!attribute [r] link_id
|
37
|
+
# @return [String] Returns the id of the link that this comment is in.
|
38
|
+
# @!attribute [r] link_title
|
39
|
+
# @return [String] Returns the title of the parent link.
|
40
|
+
# @note This attribute only exists if the comment is fetched from outside
|
41
|
+
# the thread it was posted in (so like user pages,
|
42
|
+
# /r/subreddit/comments, that type of stuff).
|
43
|
+
# @!attribute [r] link_url
|
44
|
+
# @return [String] Returns the URL of the parent link.
|
45
|
+
# @note This attribute only exists if the comment is fetched from outside
|
46
|
+
# the thread it was posted in (so like user pages,
|
47
|
+
# /r/subreddit/comments, that type of stuff).
|
48
|
+
# @!attribute [r] num_reports
|
49
|
+
# @return [Integer, nil] Returns the number of times the comment has been
|
50
|
+
# reported or nil if it hasn't or you aren't a moderator.
|
51
|
+
# @!attribute [r] parent_id
|
52
|
+
# @return [String] Returns the ID of either the link or the comment that
|
53
|
+
# this comment is a reply to.
|
54
|
+
# @!attribute [r] saved?
|
55
|
+
# @return [Boolean] Returns whether or not you saved the comment.
|
56
|
+
# @!attribute [r] score
|
57
|
+
# @return [Integer] Returns the karma score of the comment.
|
58
|
+
# @!attribute [r] score_hidden?
|
59
|
+
# @return [Boolean] Returns whether or not the karma score of the comment
|
60
|
+
# is hidden.
|
61
|
+
# @!attribute [r] subreddit
|
62
|
+
# @return [String] Returns the subreddit the comment was posted to.
|
63
|
+
# @!attribute [r] subreddit_id
|
64
|
+
# @return [String] Returns the ID of the subreddit where the comment was
|
65
|
+
# posted to.
|
66
|
+
class Comment < Thing
|
67
|
+
include Thing::Createable
|
68
|
+
include Thing::Editable
|
69
|
+
include Thing::Gildable
|
70
|
+
include Thing::Inboxable
|
71
|
+
include Thing::Moderateable
|
72
|
+
include Thing::Refreshable
|
73
|
+
include Thing::Repliable
|
74
|
+
include Thing::Saveable
|
75
|
+
include Thing::Votable
|
76
|
+
|
77
|
+
# @!method initialize(client, data)
|
78
|
+
# @param client [NeonRAW::Clients::Web/Installed/Script] The client
|
79
|
+
# object.
|
80
|
+
# @param data [Hash] The comment data.
|
81
|
+
def initialize(client, data)
|
82
|
+
@client = client
|
83
|
+
data.each do |key, value|
|
84
|
+
value = nil if ['', [], {}].include?(value)
|
85
|
+
instance_variable_set(:"@#{key}", value)
|
86
|
+
next if key == :created || key == :created_utc || key == :replies
|
87
|
+
self.class.send(:attr_reader, key)
|
88
|
+
end
|
89
|
+
class << self
|
90
|
+
alias_method :removed_by, :banned_by
|
91
|
+
alias_method :gold_count, :gilded
|
92
|
+
alias_method :saved?, :saved
|
93
|
+
alias_method :score_hidden?, :score_hidden
|
94
|
+
alias_method :archived?, :archived
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Checks whether or not the comment has replies to it.
|
99
|
+
# @!method replies?
|
100
|
+
# @return [Boolean] Returns whether or not the comment has replies to it.
|
101
|
+
def replies?
|
102
|
+
if @replies.nil?
|
103
|
+
false
|
104
|
+
else
|
105
|
+
true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Gets the replies made to the comment.
|
110
|
+
# @!method replies
|
111
|
+
# @return [Array<NeonRAW::Objects::Comment,
|
112
|
+
# NeonRAW::Objects::MoreComments>, nil] Returns either a list of the
|
113
|
+
# Comments/MoreComments or nil if there were no replies.
|
114
|
+
def replies
|
115
|
+
return nil if @replies.nil?
|
116
|
+
comments = []
|
117
|
+
@replies[:data][:children].each do |reply|
|
118
|
+
if reply[:kind] == 't1'
|
119
|
+
comments << Comment.new(@client, reply[:data])
|
120
|
+
elsif reply[:kind] == 'more'
|
121
|
+
comments << MoreComments.new(@client, reply[:data])
|
122
|
+
end
|
123
|
+
end
|
124
|
+
comments
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative 'thing'
|
2
|
+
|
3
|
+
module NeonRAW
|
4
|
+
module Objects
|
5
|
+
# The inboxed comment object.
|
6
|
+
# @!attribute [r] body
|
7
|
+
# @return [String, nil] Returns the text body of the comment or nil if
|
8
|
+
# there is none.
|
9
|
+
# @!attribute [r] link_title
|
10
|
+
# @return [String] Returns the title of the submission where the comment
|
11
|
+
# was posted.
|
12
|
+
# @!attribute [r] dest
|
13
|
+
# @return [String] Returns whom the InboxComment was sent to.
|
14
|
+
# @!attribute [r] author
|
15
|
+
# @return [String] Returns the author of the comment.
|
16
|
+
# @!attribute [r] body_html
|
17
|
+
# @return [String, nil] Returns the text body of the comment with HTML or
|
18
|
+
# nil if there is none.
|
19
|
+
# @!attribute [r] subreddit
|
20
|
+
# @return [String] Returns the subreddit where the comment was posted.
|
21
|
+
# @!attribute [r] parent_id
|
22
|
+
# @return [String] Returns the fullname of the comment's parent object.
|
23
|
+
# @!attribute [r] context
|
24
|
+
# @return [String] Returns a link to the comment with context provided.
|
25
|
+
# @!attribute [r] new?
|
26
|
+
# @return [Boolean] Returns whether the comment is new or not.
|
27
|
+
# @!attribute [r] subject
|
28
|
+
# @return [String] Returns the subject of the comment (post/comment
|
29
|
+
# reply).
|
30
|
+
class InboxComment < Thing
|
31
|
+
include Thing::Createable
|
32
|
+
include Thing::Inboxable
|
33
|
+
include Thing::Moderateable
|
34
|
+
include Thing::Repliable
|
35
|
+
include Thing::Votable
|
36
|
+
|
37
|
+
# @!method initialize(client, data)
|
38
|
+
# @param client [NeonRAW::Clients::Web/Installed/Script] The client.
|
39
|
+
# @param data [Hash] The object data.
|
40
|
+
def initialize(client, data)
|
41
|
+
@client = client
|
42
|
+
data.each do |key, value|
|
43
|
+
value = nil if ['', [], {}].include?(value)
|
44
|
+
instance_variable_set(:"@#{key}", value)
|
45
|
+
next if key == :created || key == :created_utc
|
46
|
+
self.class.send(:attr_reader, key)
|
47
|
+
end
|
48
|
+
class << self
|
49
|
+
alias_method :new?, :new
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,268 @@
|
|
1
|
+
require_relative 'user'
|
2
|
+
require_relative 'trophy'
|
3
|
+
require_relative 'multireddit'
|
4
|
+
# rubocop:disable Metrics/AbcSize, Metrics/ClassLength
|
5
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
6
|
+
|
7
|
+
module NeonRAW
|
8
|
+
# Objects module.
|
9
|
+
module Objects
|
10
|
+
# The me object.
|
11
|
+
# @!attribute [r] employee?
|
12
|
+
# @return [Boolean] Returns whether or not you're a Reddit
|
13
|
+
# employee.
|
14
|
+
# @!attribute [r] mail?
|
15
|
+
# @return [Boolean] Returns whether or not you've got mail.
|
16
|
+
# @!attribute [r] suspended?
|
17
|
+
# @return [Boolean] Returns whether or not your account is
|
18
|
+
# suspended.
|
19
|
+
# @!attribute [r] modmail?
|
20
|
+
# @return [Boolean] Returns whether or not you've got modmail.
|
21
|
+
# @!attribute [r] beta?
|
22
|
+
# @return [Boolean] Returns whether or not you're opted into
|
23
|
+
# beta testing.
|
24
|
+
# @!attribute [r] over_18?
|
25
|
+
# @return [Boolean] Returns whether or not you can view adult
|
26
|
+
# content.
|
27
|
+
# @!attribute [r] inbox_count
|
28
|
+
# @return [Integer] Returns the number of unread messages
|
29
|
+
# in your inbox.
|
30
|
+
class Me < User
|
31
|
+
# @!method initialize(client, data)
|
32
|
+
# @param client [NeonRAW::Clients::Web/Installed/Script] The client
|
33
|
+
# object.
|
34
|
+
# @param data [Hash] The object data.
|
35
|
+
def initialize(client, data)
|
36
|
+
@client = client
|
37
|
+
data.each do |key, value|
|
38
|
+
value = nil if ['', [], {}].include?(value)
|
39
|
+
instance_variable_set(:"@#{key}", value)
|
40
|
+
next if key == :created || key == :created_utc
|
41
|
+
self.class.send(:attr_reader, key)
|
42
|
+
end
|
43
|
+
class << self
|
44
|
+
alias_method :employee?, :is_employee
|
45
|
+
alias_method :mail?, :has_mail
|
46
|
+
alias_method :hide_from_robots?, :hide_from_robots
|
47
|
+
alias_method :suspended?, :is_suspended
|
48
|
+
alias_method :modmail?, :has_mod_mail
|
49
|
+
alias_method :beta?, :in_beta
|
50
|
+
alias_method :over_18?, :over_18
|
51
|
+
alias_method :gold?, :is_gold
|
52
|
+
alias_method :moderator?, :is_mod
|
53
|
+
alias_method :verified_email?, :has_verified_email
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @!group Listings
|
58
|
+
# Fetches your private messages.
|
59
|
+
# @!method messages(params = { limit: 25 })
|
60
|
+
# @!method inbox(params = { limit: 25 })
|
61
|
+
# @!method unread(params = { limit: 25 })
|
62
|
+
# @!method sent(params = { limit: 25 })
|
63
|
+
# @param params [Hash] Optional parameters.
|
64
|
+
# @option params :mark [Boolean] Whether or not to remove the orangered
|
65
|
+
# from your inbox.
|
66
|
+
# @option params :after [String] Fullname of the next data block.
|
67
|
+
# @option params :before [String] Fullname of the previous data block
|
68
|
+
# @option params :count [Integer] The number of items already in the
|
69
|
+
# listing.
|
70
|
+
# @option params :limit [1..1000] The number of listing items to fetch.
|
71
|
+
# @option params :show [String] Literally the string 'all'.
|
72
|
+
# @return [NeonRAW::Objects::Listing] Returns a listing with all your PMs.
|
73
|
+
%w(messages inbox unread sent).each do |type|
|
74
|
+
define_method :"#{type}" do |params = { limit: 25 }|
|
75
|
+
@client.send(:build_listing, "/message/#{type}", params)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Fetches your modmail.
|
80
|
+
# @!method modmail(params = { limit: 25 })
|
81
|
+
# @param params [Hash] The parameters.
|
82
|
+
# @option params :after [String] Fullname of the next data block.
|
83
|
+
# @option params :before [String] Fullname of the previous data block.
|
84
|
+
# @option params :count [Integer] The number of items already in the
|
85
|
+
# listing.
|
86
|
+
# @option params :limit [1..1000] The number of listing items to fetch.
|
87
|
+
# @option params :show [String] Literally the string 'all'.
|
88
|
+
# @return [NeonRAW::Objects::Listing] Returns a listing with all your
|
89
|
+
# modmails.
|
90
|
+
def modmail(params = { limit: 25 })
|
91
|
+
@client.send(:build_listing, '/message/moderator.json', params)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Fetches your subreddits.
|
95
|
+
# @!method subscribed(params = { limit: 25 })
|
96
|
+
# @!method contributed(params = { limit: 25 })
|
97
|
+
# @!method moderated(params = { limit: 25 })
|
98
|
+
# @param params [Hash] The parameters.
|
99
|
+
# @option params :after [String] Fullname of the next data block.
|
100
|
+
# @option params :before [String] Fullname of the previous data block.
|
101
|
+
# @option params :count [Integer] The number of items already in the
|
102
|
+
# listing.
|
103
|
+
# @option params :limit [1..1000] The number of listing items to fetch.
|
104
|
+
# @option params :show [String] Literally the string 'all'.
|
105
|
+
# @return [NeonRAW::Objects::Listing] Returns a listing with all your
|
106
|
+
# subreddits.
|
107
|
+
%w(subscribed contributed moderated).each do |type|
|
108
|
+
define_method :"#{type}" do |params = { limit: 25 }|
|
109
|
+
type = 'subscriber' if type == 'subscribed'
|
110
|
+
type = 'contributor' if type == 'contributed'
|
111
|
+
type = 'moderator' if type == 'moderated'
|
112
|
+
@client.send(:build_listing, "/subreddits/mine/#{type}", params)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
# @!endgroup
|
116
|
+
|
117
|
+
# Fetches your karma breakdown.
|
118
|
+
# @!method karma_breakdown
|
119
|
+
# @return [Array<Hash<String, Integer, Integer>>] Returns a list with your
|
120
|
+
# karma distribution in it.
|
121
|
+
def karma_breakdown
|
122
|
+
@client.request_data('/api/v1/me/karma', :get)[:data]
|
123
|
+
end
|
124
|
+
|
125
|
+
# Fetches your preferences.
|
126
|
+
# @!method prefs
|
127
|
+
# @return [Hash] Returns your account preferences.
|
128
|
+
def prefs
|
129
|
+
@client.request_data('/api/v1/me/prefs', :get)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Edits your preferences.
|
133
|
+
# @!method edit_prefs(data)
|
134
|
+
# @param data [JSON] Your preferences data. Read Reddit's API docs for
|
135
|
+
# how to format the data.
|
136
|
+
# @see https://www.reddit.com/dev/api#PATCH_api_v1_me_prefs
|
137
|
+
# @todo Figure out why this is raising BadRequest exceptions when I try
|
138
|
+
# to use it.
|
139
|
+
def edit_prefs(data)
|
140
|
+
@client.request_data('/api/v1/me/prefs', :patch, {}, content: data)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Fetches your trophies.
|
144
|
+
# @!method trophies
|
145
|
+
# @return [Array<NeonRAW::Objects::Trophy>] Returns a list of trophies.
|
146
|
+
def trophies
|
147
|
+
data_arr = []
|
148
|
+
data = @client.request_data('/api/v1/me/trophies', :get)[:data]
|
149
|
+
data[:trophies].each do |trophy|
|
150
|
+
data_arr << Trophy.new(trophy[:data])
|
151
|
+
end
|
152
|
+
data_arr
|
153
|
+
end
|
154
|
+
|
155
|
+
# Fetches your friends.
|
156
|
+
# @!method friends(params = { limit: 25 })
|
157
|
+
# @param params [Hash] The parameters for the request.
|
158
|
+
# @option params :after [String] The fullname of a thing.
|
159
|
+
# @option params :before [String] The fullname of a thing.
|
160
|
+
# @option params :count [Integer] The number of items fetch already.
|
161
|
+
# @option params :limit [1..100] The number of items to fetch.
|
162
|
+
# @option params :show [String] Literally the string 'all'.
|
163
|
+
# @return [Array<Hash<Float, String, String>>] Returns the list of your
|
164
|
+
# friends.
|
165
|
+
def friends(params = { limit: 25 })
|
166
|
+
data_arr = []
|
167
|
+
data = @client.request_data('/prefs/friends', :get, params)
|
168
|
+
data[0][:data][:children].each do |friend|
|
169
|
+
data_arr << friend
|
170
|
+
end
|
171
|
+
data_arr
|
172
|
+
end
|
173
|
+
|
174
|
+
# Fetches your blocked users.
|
175
|
+
# @!method blocked(params = { limit: 25 })
|
176
|
+
# @param params [Hash] The parameters for the request.
|
177
|
+
# @option params :after [String] The fullname of a thing.
|
178
|
+
# @option params :before [String] The fullname of a thing.
|
179
|
+
# @option params :count [Integer] The number of items fetch already.
|
180
|
+
# @option params :limit [1..100] The number of items to fetch.
|
181
|
+
# @option params :show [String] Literally the string 'all'.
|
182
|
+
# @return [Array<Hash<Float, String, String>>] Returns the list of your
|
183
|
+
# blocked users.
|
184
|
+
def blocked(params = { limit: 25 })
|
185
|
+
data_arr = []
|
186
|
+
data = @client.request_data('/prefs/blocked', :get, params)
|
187
|
+
data[:data][:children].each do |blocked|
|
188
|
+
data_arr << blocked
|
189
|
+
end
|
190
|
+
data_arr
|
191
|
+
end
|
192
|
+
|
193
|
+
# Mark all your messages as "read."
|
194
|
+
# @!method read_all_messages!
|
195
|
+
def read_all_messages!
|
196
|
+
@client.request_nonjson('/api/read_all_messages', :post)
|
197
|
+
end
|
198
|
+
|
199
|
+
# Fetches your multireddits.
|
200
|
+
# @!method multireddits
|
201
|
+
# @return [Array<NeonRAW::Objects::MultiReddit>] Returns a list of
|
202
|
+
# multireddits.
|
203
|
+
def multireddits
|
204
|
+
data_arr = []
|
205
|
+
params = { expand_srs: false }
|
206
|
+
data = @client.request_data('/api/multi/mine', :get, params)
|
207
|
+
data.each do |multireddit|
|
208
|
+
data_arr << MultiReddit.new(@client, multireddit[:data])
|
209
|
+
end
|
210
|
+
data_arr
|
211
|
+
end
|
212
|
+
|
213
|
+
# Goes through and edits then deletes your post history. Defaults to
|
214
|
+
# 2 weeks.
|
215
|
+
# @!method purge(queue, params = {})
|
216
|
+
# @param queue [String] The queue you want to get your posts from
|
217
|
+
# [overview, submitted, comments, upvoted, downvoted, hidden, saved,
|
218
|
+
# giled]
|
219
|
+
# @param params [Hash] The additional parameters.
|
220
|
+
# @option params :edit [String] The text to edit your posts with.
|
221
|
+
# @option params :blacklist [Array<String>] Subreddits to avoid purging
|
222
|
+
# from.
|
223
|
+
# @option params :whitelist [Array<String>] Subreddits to purge.
|
224
|
+
# @option params :sort [String] The sort of the data (defaults to new)
|
225
|
+
# [new, hot, top, controversial].
|
226
|
+
# @option params :hours [Integer] The number of hours to go back from.
|
227
|
+
# @option params :days [Integer] The number of days to go back from.
|
228
|
+
# @option params :weeks [Integer] The number of weeks to go back from.
|
229
|
+
# @option params :months [Integer] The number of months to go back from.
|
230
|
+
# @option params :years [Integer] The number of years to go back from.
|
231
|
+
def purge(queue, params = {})
|
232
|
+
params[:edit] = '.' if params[:edit].nil?
|
233
|
+
params[:blacklist] = [] if params[:blacklist].nil?
|
234
|
+
params[:whitelist] = ['*'] if params[:whitelist].nil?
|
235
|
+
whitelist = params[:whitelist]
|
236
|
+
params[:age] = max_age(params)
|
237
|
+
items = send(:"#{queue}", sort: params[:sort] || 'new', limit: 1000)
|
238
|
+
items.each do |item|
|
239
|
+
next if params[:blacklist].include?(item.subreddit)
|
240
|
+
next if item.created < params[:age]
|
241
|
+
next unless whitelist.include?(item.subreddit) || whitelist[0] == '*'
|
242
|
+
if item.is_a?(Submission)
|
243
|
+
item.edit! params[:edit] if item.selfpost? && !item.archived?
|
244
|
+
else
|
245
|
+
item.edit! params[:edit] unless item.archived?
|
246
|
+
end
|
247
|
+
item.delete!
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
# Fetches the max age of things to be purged.
|
252
|
+
# @!method max_age(params)
|
253
|
+
# @param params [Hash] The hours/days/weeks/months/years to go back from.
|
254
|
+
def max_age(params)
|
255
|
+
start = Time.now
|
256
|
+
age = start
|
257
|
+
age -= 3600 * params[:hours] unless params[:hours].nil?
|
258
|
+
age -= 86_400 * params[:days] unless params[:days].nil?
|
259
|
+
age -= 604_800 * params[:weeks] unless params[:weeks].nil?
|
260
|
+
age -= 2_419_200 * params[:months] unless params[:months].nil?
|
261
|
+
age -= 29_030_400 * params[:years] unless params[:years].nil?
|
262
|
+
age -= (604_800 * 2) if age == start # defaults to 2 weeks
|
263
|
+
age
|
264
|
+
end
|
265
|
+
private :max_age
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative 'thing'
|
2
|
+
|
3
|
+
module NeonRAW
|
4
|
+
module Objects
|
5
|
+
# The modlogaction object.
|
6
|
+
# @!attribute [r] description
|
7
|
+
# @return [String, nil] Returns the description or nil if there is none.
|
8
|
+
# @!attribute [r] target_body
|
9
|
+
# @return [String, nil] Returns the text body of the target object or nil
|
10
|
+
# if there is none.
|
11
|
+
# @!attribute [r] mod_id36
|
12
|
+
# @return [String] Returns the ID of the mod who did the action.
|
13
|
+
# @!attribute [r] subreddit
|
14
|
+
# @return [String] Returns the subreddit where the action occured.
|
15
|
+
# @!attribute [r] target_title
|
16
|
+
# @return [String, nil] Returns the title of the target object or nil if
|
17
|
+
# there is none.
|
18
|
+
# @!attribute [r] target_permalink
|
19
|
+
# @return [String, nil] Returns the permalink of the target object or nil
|
20
|
+
# if there is none.
|
21
|
+
# @!attribute [r] details
|
22
|
+
# @return [String] Returns the details of the action.
|
23
|
+
# @!attribute [r] action
|
24
|
+
# @return [String] Returns the type of action.
|
25
|
+
# @!attribute [r] target_author
|
26
|
+
# @return [String, nil] Returns the author of the target object or nil if
|
27
|
+
# there is none.
|
28
|
+
# @!attribute [r] target_fullname
|
29
|
+
# @return [String, nil] Returns the fullname of the target object or nil
|
30
|
+
# if there is none.
|
31
|
+
# @!attribute [r] sr_id36
|
32
|
+
# @return [String] Returns the ID of the subreddit where the action
|
33
|
+
# occured.
|
34
|
+
# @!attribute [r] mod
|
35
|
+
# @return [String] Returns the mod who did the action.
|
36
|
+
# @!attribute [r] id
|
37
|
+
# @return [String] Returns the ID of the modlog action.
|
38
|
+
class ModLogAction
|
39
|
+
include Thing::Createable
|
40
|
+
|
41
|
+
def initialize(client, data)
|
42
|
+
@client = client
|
43
|
+
data.each do |key, value|
|
44
|
+
value = nil if ['', [], {}].include?(value)
|
45
|
+
instance_variable_set(:"@#{key}", value)
|
46
|
+
next if key == :created_utc
|
47
|
+
self.class.send(:attr_reader, key)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Gets when the mod log action was done.
|
52
|
+
# @!method created
|
53
|
+
# @return [Time] Returns the date/time when the mod log action was done.
|
54
|
+
def created
|
55
|
+
Time.at(@created_utc).localtime
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'thing'
|
2
|
+
|
3
|
+
module NeonRAW
|
4
|
+
module Objects
|
5
|
+
# The modloguser object.
|
6
|
+
# @!attribute [r] note
|
7
|
+
# @return [String, nil] Returns the reason for the banning or nil if there
|
8
|
+
# is none. This attribute is only available for the banned and
|
9
|
+
# wikibanned methods.
|
10
|
+
# @!attribute [r] mod_permissions
|
11
|
+
# @return [Array<String>] Returns the mod permissions for the user. This
|
12
|
+
# attribute is only available for the moderators method.
|
13
|
+
class ModLogUser < Thing
|
14
|
+
# @!method initialize(client, data)
|
15
|
+
# @param client [NeonRAW::Clients::Web/Installed/Script] The client.
|
16
|
+
# @param data [Hash] The object data.
|
17
|
+
def initialize(client, data)
|
18
|
+
@client = client
|
19
|
+
data.each do |key, value|
|
20
|
+
value = nil if ['', [], {}].include?(value)
|
21
|
+
instance_variable_set(:"@#{key}", value)
|
22
|
+
next if key == :date
|
23
|
+
self.class.send(:attr_reader, key)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Gets the date of when the user was added to the list.
|
28
|
+
# @!method date
|
29
|
+
# @return [Time] Returns when the user was added to the list.
|
30
|
+
def date
|
31
|
+
Time.at(@date)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'comment'
|
2
|
+
|
3
|
+
module NeonRAW
|
4
|
+
module Objects
|
5
|
+
# The MoreComments object.
|
6
|
+
class MoreComments
|
7
|
+
def initialize(client, data)
|
8
|
+
@client = client
|
9
|
+
data.each do |key, value|
|
10
|
+
value = nil if ['', [], {}].include?(value)
|
11
|
+
instance_variable_set(:"@#{key}", value)
|
12
|
+
self.class.send(:attr_reader, key)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Expands the MoreComments object.
|
17
|
+
# @!method expand(subreddit)
|
18
|
+
# @param subreddit [String] The name of the subreddit where the
|
19
|
+
# MoreComments object resides.
|
20
|
+
# @return [Array] Returns a list of the comments that were expanded.
|
21
|
+
def expand(subreddit)
|
22
|
+
comments = []
|
23
|
+
params = { id: children.map { |the_id| 't1_' + the_id }.join(',') }
|
24
|
+
# /api/morechildren is buggy shit. This is better.
|
25
|
+
data = @client.request_data("/r/#{subreddit}/api/info", :get, params)
|
26
|
+
data[:data][:children].each do |comment|
|
27
|
+
comments << Comment.new(@client, comment[:data])
|
28
|
+
end
|
29
|
+
comments
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|