NeonRAW 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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,98 @@
1
+ module NeonRAW
2
+ module Objects
3
+ class Thing
4
+ # Methods for moderators.
5
+ # @!attribute [r] mod_reports
6
+ # @return [Array<String>, nil] Returns the mod reports or nil if there
7
+ # are none.
8
+ # @!attribute [r] user_reports
9
+ # @return [Array<String>, nil] Returns the user reports or nil if there
10
+ # are none.
11
+ module Moderateable
12
+ # Approve a comment or submission.
13
+ # @!method approve!
14
+ def approve!
15
+ params = { id: name }
16
+ @client.request_data('/api/approve', :post, params)
17
+ refresh!
18
+ end
19
+
20
+ # Checks whether or not the thing was distinguished by a privileged
21
+ # user.
22
+ # @!method distinguished?
23
+ # @return [Boolean] Returns whether or not the comment was
24
+ # distinguished.
25
+ def distinguished?
26
+ if @distinguished.nil?
27
+ false
28
+ else
29
+ true
30
+ end
31
+ end
32
+
33
+ # Distinguish a submission/comment.
34
+ # @!method distinguish(type)
35
+ # @param type [String] The type of distinguish you want to do [yes, no,
36
+ # admin, special].
37
+ # @!group Moderators
38
+ def distinguish(type)
39
+ params = { api_type: 'json', how: type, id: name }
40
+ @client.request_data('/api/distinguish', :post, params)
41
+ refresh!
42
+ end
43
+
44
+ # Checks who distinguished the thing.
45
+ # @!method distinguished_by
46
+ # @return [String, nil] Returns who distinguished the comment or nil if
47
+ # the comment isn't distinguished [moderator, admin, special].
48
+ def distinguished_by
49
+ @distinguished
50
+ end
51
+
52
+ # Checks whether or not the thing is stickied.
53
+ # @!method stickied?
54
+ # @return [Boolean] Returns whether or not the thing is stickied.
55
+ def stickied?
56
+ @stickied
57
+ end
58
+
59
+ # Report a thing to the subreddit's moderators or admins if the thing
60
+ # is a private message.
61
+ # @!method report(reason)
62
+ # @param reason [String] The reason for the report (100 characters
63
+ # maximum).
64
+ def report(reason)
65
+ params = { api_type: 'json', reason: reason, thing_id: name }
66
+ @client.request_data('/api/report', :post, params)
67
+ end
68
+
69
+ # Set whether to ignore reports on the thing or not.
70
+ # @!method ignore_reports!
71
+ # @!method unignore_reports!
72
+ %w(ignore unignore).each do |type|
73
+ define_method :"#{type}_reports!" do
74
+ params = { id: name }
75
+ @client.request_data("/api/#{type}_reports", :post, params)
76
+ refresh!
77
+ end
78
+ end
79
+
80
+ # Remove a comment/link/modmail message.
81
+ # @!method remove!
82
+ def remove!
83
+ params = { id: name, spam: false }
84
+ @client.request_data('/api/remove', :post, params)
85
+ refresh!
86
+ end
87
+
88
+ # Spamfilter a comment/link/modmail message.
89
+ # @!method spam!
90
+ def spam!
91
+ params = { id: name, spam: true }
92
+ @client.request_data('/api/remove', :post, params)
93
+ refresh!
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,21 @@
1
+ module NeonRAW
2
+ module Objects
3
+ class Thing
4
+ # Methods for things that can be refreshed.
5
+ module Refreshable
6
+ # Refreshes the data of a comment/submission/subreddit object.
7
+ # @!method refresh!
8
+ def refresh!
9
+ params = { id: name }
10
+ path = "/r/#{display_name}/api/info" if /t5_/ =~ name
11
+ path = "/r/#{subreddit}/api/info" unless /t5_/ =~ name
12
+ data = @client.request_data(path, :get, params)
13
+ data[:data][:children][0][:data].each do |key, value|
14
+ value = nil if ['', [], {}].include?(value)
15
+ instance_variable_set(:"@#{key}", value)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ module NeonRAW
2
+ module Objects
3
+ class Thing
4
+ # Methods for things that can be replied to.
5
+ module Repliable
6
+ # Leaves a comment/PM reply to the thing.
7
+ # @!method reply(text)
8
+ # @param text [String] The text body of the comment.
9
+ # @return [NeonRAW::Objects::Comment/PrivateMessage] Returns the object.
10
+ def reply(text)
11
+ params = { api_type: 'json', text: text, thing_id: name }
12
+ data = @client.request_data('/api/comment', :post, params)
13
+ object_data = data[:json][:data][:things][0][:data]
14
+ if data[:kind] == 't1'
15
+ Comment.new(@client, object_data)
16
+ elsif data[:kind] == 't4'
17
+ PrivateMessage.new(@client, object_data)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ module NeonRAW
2
+ module Objects
3
+ class Thing
4
+ # Methods for things that can be saved.
5
+ module Saveable
6
+ # Saves the thing.
7
+ # @!method save(opts = {})
8
+ # @param opts [Hash] Stores optional parameters.
9
+ # @option opts :category [String] The category you want to save to
10
+ # (Reddit Gold Feature).
11
+ def save(opts = {})
12
+ params = { id: name }
13
+ params[:category] = opts[:category] if opts[:category]
14
+ @client.request_data('/api/save', :post, params)
15
+ end
16
+
17
+ # Unsaves the thing.
18
+ # @!method unsave
19
+ def unsave
20
+ params = { id: name }
21
+ @client.request_data('/api/unsave', :post, params)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,69 @@
1
+ module NeonRAW
2
+ module Objects
3
+ class Thing
4
+ # Methods for objects that you can cast votes on.
5
+ # @!attribute [r] ups
6
+ # @return [Integer] Returns the number of upvotes the thing has.
7
+ # @!attribute [r] downs
8
+ # @return [Integer] Returns the number of downvotes the thing has.
9
+ module Votable
10
+ # Checks whether you voted on the thing.
11
+ # @!method voted?
12
+ # @return [Boolean] Returns whether or not you voted on the thing.
13
+ def voted?
14
+ if @likes.nil?
15
+ false
16
+ else
17
+ true
18
+ end
19
+ end
20
+
21
+ # Checks whether or not you upvoted the thing.
22
+ # @!method upvoted?
23
+ # @return [Boolean] Returns whether or not you upvoted the thing.
24
+ def upvoted?
25
+ if @likes == true
26
+ true
27
+ else
28
+ false
29
+ end
30
+ end
31
+
32
+ # Checks whether or not you downvoted the thing.
33
+ # @!method downvoted?
34
+ # @return [Boolean] Returns whether or not you downvoted the thing.
35
+ def downvoted?
36
+ if @likes == false
37
+ true
38
+ else
39
+ false
40
+ end
41
+ end
42
+
43
+ # Contains the values for each type of vote.
44
+ # @!method votes
45
+ # @return [Hash] Returns a hash containing the vote values.
46
+ def votes
47
+ {
48
+ upvote: 1,
49
+ clear_vote: 0,
50
+ downvote: -1
51
+ }
52
+ end
53
+
54
+ # Cast a vote on an object.
55
+ # @!method upvote
56
+ # @!method clear_vote
57
+ # @!method downvote
58
+ %i(upvote clear_vote downvote).each do |type|
59
+ define_method type do
60
+ params = { dir: votes[type], id: name }
61
+ @client.request_data('/api/vote', :post, params)
62
+ refresh!
63
+ end
64
+ end
65
+ private :votes
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'thing/votable'
2
+ require_relative 'thing/editable'
3
+ require_relative 'thing/moderateable'
4
+ require_relative 'thing/gildable'
5
+ require_relative 'thing/createable'
6
+ require_relative 'thing/saveable'
7
+ require_relative 'thing/refreshable'
8
+ require_relative 'thing/inboxable'
9
+ require_relative 'thing/repliable'
10
+
11
+ module NeonRAW
12
+ module Objects
13
+ # Exists to hold methods that work in all objects.
14
+ # @!attribute [r] id
15
+ # @return [String] The id of the thing.
16
+ # @!attribute [r] name
17
+ # @return [String] The fullname of the thing.
18
+ class Thing
19
+ class << self
20
+ public :define_method
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'thing'
2
+
3
+ module NeonRAW
4
+ module Objects
5
+ # The trophy object.
6
+ # @!attribute [r] icon_70
7
+ # @return [String] Returns a link to the icon file.
8
+ # @!attribute [r] description
9
+ # @return [String, nil] Returns the description or nil if there is none.
10
+ # @!attribute [r] url
11
+ # @return [String, nil] Returns the URL or nil if there is none.
12
+ # @!attribute [r] icon_40
13
+ # @return [String] Returns a link to the icon file.
14
+ # @!attribute [r] award_id
15
+ # @return [String] Returns the award ID.
16
+ class Trophy < Thing
17
+ def initialize(data)
18
+ data.each do |key, value|
19
+ instance_variable_set(:"@#{key}", value)
20
+ self.class.send(:attr_reader, key)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,147 @@
1
+ require_relative 'thing'
2
+ require_relative 'trophy'
3
+
4
+ module NeonRAW
5
+ module Objects
6
+ # The user object.
7
+ # @!attribute [r] friend?
8
+ # @return [Boolean] Returns whether or not the user is a friend.
9
+ # @!attribute [r] gold?
10
+ # @return [Boolean] Returns whether or not the user has gold.
11
+ # @!attribute [r] moderator?
12
+ # @return [Boolean] Returns whether or not the user is a
13
+ # moderator.
14
+ # @!attribute [r] verified_email?
15
+ # @return [Boolean] Returns whether or not the user has a
16
+ # verified email.
17
+ # @!attribute [r] hide_from_robots?
18
+ # @return [Boolean] Returns whether or not the user doesn't
19
+ # want web crawlers indexing their profile page.
20
+ # @!attribute [r] link_karma
21
+ # @return [Integer] Returns the link karma of the user.
22
+ # @!attribute [r] comment_karma
23
+ # @return [Integer] Returns the comment karma of the user.
24
+ class User < Thing
25
+ include Thing::Createable
26
+ include Thing::Refreshable
27
+
28
+ # @!method initialize(client, data)
29
+ # @param client [NeonRAW::Clients::Web/Installed/Script] The client
30
+ # object.
31
+ # @param data [Hash] The object data.
32
+ def initialize(client, data)
33
+ @client = client
34
+ data.each do |key, value|
35
+ value = nil if ['', [], {}].include?(value)
36
+ instance_variable_set(:"@#{key}", value)
37
+ next if key == :created || key == :created_utc
38
+ self.class.send(:attr_reader, key)
39
+ end
40
+ class << self
41
+ alias_method :friend?, :is_friend
42
+ alias_method :gold?, :is_gold
43
+ alias_method :moderator?, :is_mod
44
+ alias_method :verified_email?, :has_verified_email
45
+ alias_method :hide_from_robots?, :hide_from_robots
46
+ end
47
+ end
48
+
49
+ # @!group Listings
50
+ # Fetches a listing from a user.
51
+ # @!method overview(params = { limit: 25 })
52
+ # @!method comments(params = { limit: 25 })
53
+ # @!method submitted(params = { limit: 25 })
54
+ # @!method gilded(params = { limit: 25 })
55
+ # @!method upvoted(params = { limit: 25 })
56
+ # @!method downvoted(params = { limit: 25 })
57
+ # @!method hidden(params = { limit: 25 })
58
+ # @!method saved(params = { limit: 25 })
59
+ # @param params [Hash] The parameters for the request.
60
+ # @option params :show [String] Show a listing type [overview, comments,
61
+ # submitted, gilded, upvoted, downvoted, hidden, saved]
62
+ # @option params :sort [String] The sorting algorithm [hot, new, top,
63
+ # controversial]
64
+ # @option params :t [String] The time for the relevance sort [hour, day,
65
+ # week, month, year, all]
66
+ # @option params :username [String] The username of an existing user.
67
+ # @option params :after [String] The name of the next data block.
68
+ # @option params :before [String] The name of the previous data block.
69
+ # @option params :count [Integer] The number of items already in the
70
+ # listing.
71
+ # @option params :limit [1..1000] The number of listing items to fetch.
72
+ # @return [NeonRAW::Objects::Listing] Returns the listing object.
73
+ %w(overview comments submitted gilded upvoted downvoted
74
+ hidden saved).each do |type|
75
+ define_method :"#{type}" do |params = { limit: 25 }|
76
+ path = "/user/#{name}/#{type}/.json"
77
+ @client.send(:build_listing, path, params)
78
+ end
79
+ end
80
+ # @!endgroup
81
+
82
+ # Give gold to a user.
83
+ # @!method give_gold(months)
84
+ # @param months [1..36] The number of months worth of gold to give.
85
+ def give_gold(months)
86
+ params = { months: months }
87
+ @client.request_data("/api/v1/gold/give/#{name}", :post, params)
88
+ refresh!
89
+ end
90
+
91
+ # Send a PM to a user.
92
+ # @!method message(subject, text, opts = {})
93
+ # @param subject [String] The subject of the message (100 characters
94
+ # maximum).
95
+ # @param text [String] The text body of the message.
96
+ # @param opts [Hash] Optional parameters.
97
+ # @option opts :from_subreddit [String] The subreddit to send the message
98
+ # from.
99
+ def message(subject, text, opts = {})
100
+ params = { api_type: 'json', from_sr: opts[:from_subreddit], text: text,
101
+ subject: subject, to: name }
102
+ @client.request_data('/api/compose', :post, params)
103
+ end
104
+
105
+ # Fetches the user's multireddits.
106
+ # @!method multireddits
107
+ # @return [Array<NeonRAW::Objects::MultiReddit>] Returns a list of
108
+ # multireddits.
109
+ def multireddits
110
+ data_arr = []
111
+ params = { expand_srs: false }
112
+ data = @client.request_data("/api/multi/user/#{name}", :get, params)
113
+ data.each do |multireddit|
114
+ data_arr << MultiReddit.new(@client, multireddit[:data])
115
+ end
116
+ data_arr
117
+ end
118
+
119
+ # Add the user to your friends list.
120
+ # @!method friend
121
+ def friend
122
+ body = { 'name' => name }.to_json
123
+ @client.request_data("/api/v1/me/friends/#{name}", :put, {}, body)
124
+ end
125
+
126
+ # Remove the user from your friends list.
127
+ # @!method unfriend
128
+ def unfriend
129
+ params = { id: name }
130
+ @client.request_nonjson("/api/v1/me/friends/#{name}", :delete, params)
131
+ end
132
+
133
+ # Fetches the user's trophies.
134
+ # @!method trophies
135
+ # @return [Array<NeonRAW::Objects::Trophy>] Returns a list of trophies.
136
+ def trophies
137
+ data_arr = []
138
+ path = "/api/v1/user/#{name}/trophies"
139
+ data = @client.request_data(path, :get)[:data]
140
+ data[:trophies].each do |trophy|
141
+ data_arr << Trophy.new(trophy[:data])
142
+ end
143
+ data_arr
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,176 @@
1
+ require_relative 'wikipagerevision'
2
+ require_relative 'listing'
3
+
4
+ module NeonRAW
5
+ module Objects
6
+ # The wikipage object.
7
+ # @!attribute [r] revisable?
8
+ # @return [Boolean] Returns whether or not you can revise the wiki page.
9
+ # @!attribute [r] content_html
10
+ # @return [String, nil] Returns the content of the wiki page with HTML or
11
+ # nil if there is none.
12
+ # @!attribute [r] content
13
+ # @return [String, nil] Returns the content of the wiki page or nil if
14
+ # there is none.
15
+ # @!attribute [r] name
16
+ # @return [String] Returns the name of the wiki page.
17
+ # @!attribute [r] subreddit
18
+ # @return [String] Returns the subreddit of the wiki page.
19
+ class WikiPage
20
+ class << self
21
+ public :define_method
22
+ end
23
+
24
+ # @!method initialize(client, data)
25
+ # @param client [NeonRAW::Clients::Web/Installed/Script] The client.
26
+ # @param data [Hash] The object data.
27
+ def initialize(client, data)
28
+ @client = client
29
+ data.each do |key, value|
30
+ value = nil if ['', [], {}].include?(value)
31
+ instance_variable_set(:"@#{key}", value)
32
+ next if key == :revision_date || key == :revision_by
33
+ self.class.send(:attr_reader, key)
34
+ end
35
+ class << self
36
+ alias_method :revisable?, :may_revise
37
+ alias_method :content, :content_md
38
+ end
39
+ end
40
+
41
+ # The user who made the last revision to the wiki page.
42
+ # @!method revised_by
43
+ # @return [String] Returns the username of the user.
44
+ def revised_by
45
+ @revision_by[:data][:name]
46
+ end
47
+
48
+ # The date of the last revision to the wiki page.
49
+ # @!method revision_date
50
+ # @return [Time] Returns the date.
51
+ def revision_date
52
+ Time.at(@revision_date)
53
+ end
54
+
55
+ # @!group Listings
56
+ # Gets the revisions made to the wiki page.
57
+ # @!method revisions(params = { limit: 25 })
58
+ # @param params [Hash] The parameters.
59
+ # @option params :after [String] Fullname of the next data block.
60
+ # @option params :before [String] Fullname of the previous data block.
61
+ # @option params :count [Integer] The number of items already in the
62
+ # listing.
63
+ # @option params :limit [1..1000] The number of listing items to fetch.
64
+ # @option params :show [String] Literally the string 'all'.
65
+ # @return [NeonRAW::Objects::Listing] Returns the list of revisions.
66
+ def revisions(params = { limit: 25 })
67
+ data_arr = []
68
+ path = "/r/#{subreddit}/wiki/revisions/#{name}"
69
+ until data_arr.length == params[:limit]
70
+ data = @client.request_data(path, :get, params)
71
+ params[:after] = data[:data][:after]
72
+ params[:before] = data[:data][:before]
73
+ data[:data][:children].each do |item|
74
+ item[:subreddit] = subreddit
75
+ data_arr << WikiPageRevision.new(@client, item)
76
+ break if data_arr.length == params[:limit]
77
+ end
78
+ break if params[:after].nil?
79
+ end
80
+ listing = Objects::Listing.new(params[:after], params[:before])
81
+ data_arr.each { |revision| listing << revision }
82
+ listing
83
+ end
84
+
85
+ # Fetches submissions about the wiki page.
86
+ # @!method discussions(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] The 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
+ # @return [NeonRAW::Objects::Listing] Returns a listing with all the
95
+ # submissions.
96
+ def discussions(params = { limit: 25 })
97
+ params[:page] = name
98
+ path = "/r/#{subreddit}/wiki/discussions/#{name}"
99
+ @client.send(:build_listing, path, params)
100
+ end
101
+ # @!endgroup
102
+
103
+ # Change the wiki contributors.
104
+ # @!method add_editor(username)
105
+ # @!method remove_editor(username)
106
+ # @param username [String] The username of the user.
107
+ %w(add remove).each do |type|
108
+ define_method :"#{type}_editor" do |username|
109
+ params = { page: name, username: username }
110
+ type = 'del' if type == 'remove'
111
+ params[:act] = type
112
+ path = "/r/#{subreddit}/api/wiki/alloweditor/#{type}"
113
+ @client.request_data(path, :post, params)
114
+ end
115
+ end
116
+
117
+ # Edit the wiki page.
118
+ # @!method edit!(text, opts = {})
119
+ # @param text [String] The content for the page.
120
+ # @param opts [Hash] Optional parameters.
121
+ # @option opts :reason [String] The reason for the edit (256 characters
122
+ # maximum).
123
+ def edit!(text, opts = {})
124
+ params = { reason: opts[:reason], content: text, page: name }
125
+ path = "/r/#{subreddit}/api/wiki/edit"
126
+ @client.request_data(path, :post, params)
127
+ data = @client.request_data("/r/#{subreddit}/wiki/#{name}", :get)
128
+ data[:data].each do |key, value|
129
+ value = nil if ['', [], {}].include?(value)
130
+ instance_variable_set(:"@#{key}", value)
131
+ end
132
+ end
133
+
134
+ # Reverts the wiki page to this revision.
135
+ # @!method revert!(revision)
136
+ # @param revision [NeonRAW::Objects::WikiPageRevision] The revision you
137
+ # want to revert back to.
138
+ def revert!(revision)
139
+ params = { page: name, revision: revision.id }
140
+ path = "/r/#{subreddit}/api/wiki/revert"
141
+ @client.request_data(path, :post, params)
142
+ path = "/r/#{subreddit}/wiki/#{name}"
143
+ data = @client.request_data(path, :get, page: name)
144
+ data[:data].each do |key, value|
145
+ instance_variable_set(:"@#{key}", value)
146
+ end
147
+ end
148
+
149
+ # Fetches the settings for the wiki.
150
+ # @!method settings
151
+ # @return [Hash<Integer, Array<String>, Boolean>] Returns the wiki
152
+ # page's settings.
153
+ def settings
154
+ path = "/r/#{subreddit}/wiki/settings/#{name}"
155
+ @client.request_data(path, :get, page: name)[:data]
156
+ end
157
+
158
+ # Edits the settings of the wiki.
159
+ # @!method edit_settings(data)
160
+ # @param data [Hash] The parameters.
161
+ # @option data :listed [Boolean] Whether or not the wiki page will be
162
+ # listed on the list of wiki pages.
163
+ # @option data :permlevel [String] Set the permission level needed to
164
+ # edit the wiki [use_subreddit_settings, approved_only, mods_only].
165
+ def edit_settings(data)
166
+ permlevel = { 'use_subreddit_settings' => 0, 'approved_only' => 1,
167
+ 'mods_only' => 2 }
168
+ params = { page: name, permlevel: permlevel[data[:permlevel]],
169
+ listed: data[:listed] }
170
+ params[:page] = name
171
+ path = "/r/#{subreddit}/wiki/settings/#{name}"
172
+ @client.request_data(path, :post, params)[:data]
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,45 @@
1
+ module NeonRAW
2
+ module Objects
3
+ # The wiki page revision object.
4
+ # @!attribute [r] reason
5
+ # @return [String, nil] Returns the reason for the revision.
6
+ # @!attribute [r] page
7
+ # @return [String] Returns the name of the wiki page.
8
+ # @!attribute [r] id
9
+ # @return [String] Returns the ID of the revision.
10
+ class WikiPageRevision
11
+ # @!method initialize(client, data)
12
+ # @param client [NeonRAW::Clients::Web/Installed/Script] The client.
13
+ # @param data [Hash] The object data.
14
+ def initialize(client, data)
15
+ @client = client
16
+ data.each do |key, value|
17
+ value = nil if ['', [], {}].include?(value)
18
+ instance_variable_set(:"@#{key}", value)
19
+ next if key == :timestamp || key == :author
20
+ self.class.send(:attr_reader, key)
21
+ end
22
+ end
23
+
24
+ # @!attribute [r] author
25
+ # @return [String] Returns the user who made the revision.
26
+ def author
27
+ @author[:data][:name]
28
+ end
29
+
30
+ # The time and date when the revision was created.
31
+ # @!method created
32
+ # @return [Time] Returns when the revision was made.
33
+ def created
34
+ Time.at(@timestamp)
35
+ end
36
+
37
+ # The time and date when the revision was created in UTC.
38
+ # @!method created_utc
39
+ # @return [Time] Returns when the revision was made in UTC.
40
+ def created_utc
41
+ Time.at(@timestamp).utc
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module NeonRAW
2
+ VERSION = '0.1.1'.freeze
3
+ end