eddieroger-rwikibot 2.0.3 → 2.0.4

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 (5) hide show
  1. data/CHANGELOG +11 -0
  2. data/lib/pages.rb +28 -2
  3. data/lib/rwikibot.rb +7 -7
  4. data/lib/utilities.rb +10 -4
  5. metadata +1 -1
data/CHANGELOG CHANGED
@@ -1,5 +1,16 @@
1
1
  RWikiBot ChangeLog
2
2
 
3
+ 2.0.4
4
+ - I get it - I just suck at keeping versions consistent. And Github requires incremental gemspecs.
5
+
6
+ 2.0.3
7
+ - Removed an extra puts. Oops.
8
+ - Added Page::protect
9
+ - Reimplemented meets_version_requirement and references to it
10
+
11
+ 2.0.2
12
+ - Random little changes. Forgot to document. Sorry.
13
+
3
14
  2.0.1
4
15
  - Changing gemspec so MAYBE it will be included in github gems.
5
16
 
data/lib/pages.rb CHANGED
@@ -12,7 +12,7 @@ module Pages
12
12
  # Creates a new Page object.
13
13
  def initialize(bot, title='')
14
14
  @bot = bot
15
- puts @bot.config
15
+ #puts @bot.config
16
16
 
17
17
  info = info(title)
18
18
  @title = info['title']
@@ -95,6 +95,8 @@ module Pages
95
95
  # I decided to split this up since I wanted to normalize the bot framework as much as possible, or in other words, make it as easy to use as possible. I think the sacrifice of more methods is worth having more English looking code. Its the Ruby way.
96
96
  # Info will return information about the page, from namespace to normalized title, last touched, etc.
97
97
  def info(titles)
98
+ raise RWBErrors::VersionTooLowError unless @bot.meets_version_requirement(1,9)
99
+
98
100
  post_me = {"prop" => "info", 'titles' => titles}
99
101
  info_result = @bot.make_request('query', post_me)
100
102
  info_result.fetch('pages').fetch('page')
@@ -118,12 +120,34 @@ module Pages
118
120
  post_me['noredirect'] = '' if noredirect
119
121
 
120
122
  @bot.make_request('move', post_me)
121
- end
123
+ end # move
124
+
125
+ # This method is used to protect (and unprotect!) pages. See the API for
126
+ # possible values. By default, it will lock a page to require sysop level
127
+ # privledge and never expire.
128
+ def protect(protections='edit=sysop', expiry='infinite', reason='', cascade=true)
129
+ raise RWBErrors::VersionTooLowError unless @bot.meets_version_requirement(1,12)
130
+ raise RWBErrors::NotLoggedInError unless @bot.logged_in?
131
+
132
+ post_me = {
133
+ 'title' => @title ,
134
+ 'token' => get_token('protect') ,
135
+ 'protections' => protections ,
136
+ 'expiry' => expiry ,
137
+ 'reason' => reason ,
138
+ }
139
+
140
+ post_me['cascade'] = '' if cascade
141
+ @bot.make_request('protect', post_me)
142
+ end # protect
122
143
 
123
144
  # Rollback does what it says - rolls back an article one version in the
124
145
  # wiki. This is a function that requires not only a token, but a previous
125
146
  # user.
126
147
  def rollback(summary="", markbot=true)
148
+ raise RWBErrors::VersionTooLowError unless @bot.meets_version_requirement(1,12)
149
+ raise RWBErrors::NotLoggedInError unless @bot.logged_in?
150
+
127
151
  temp_token = get_token("rollback") # special for rollback. Stupid rollback.
128
152
  post_me = {
129
153
  'title' => @title,
@@ -140,6 +164,8 @@ module Pages
140
164
  # sure you're logged in and got a token (get_token). Options is an array
141
165
  # (or hash) of extra values allowed by the API.
142
166
  def save(content, summary=nil, options=nil)
167
+ raise RWBErrors::VersionTooLowError unless @bot.meets_version_requirement(1,13)
168
+ raise RWBErrors::NotLoggedInError unless @bot.logged_in?
143
169
 
144
170
  post_me = {
145
171
  'text' => "#{content}" ,
data/lib/rwikibot.rb CHANGED
@@ -58,7 +58,7 @@ class RWikiBot
58
58
  # always necessary, but bots need to log in to save changes or retrieve
59
59
  # watchlists.
60
60
  def login
61
- # raise VersionTooLowError unless meets_version_requirement(0,0)
61
+ raise VersionTooLowError unless meets_version_requirement(0,0)
62
62
 
63
63
  post_me = {'lgname'=>@config.fetch('username'),'lgpassword'=>@config.fetch('password')}
64
64
  if @config.has_key?('domain') && (@config.fetch('domain') != nil)
@@ -99,7 +99,7 @@ class RWikiBot
99
99
  # elsewhere. Accepts all parameters from the API in Hash form. Default is
100
100
  # namespace => 0, which is just plain pages. Nothing 'special'.
101
101
  def all_pages(options = nil)
102
- # raise VersionTooLowError unless meets_version_requirement(1,9)
102
+ raise VersionTooLowError unless meets_version_requirement(1,9)
103
103
  # This will get all pages. Limits vary based on user rights of the Bot. Set to bot.
104
104
  post_me = {'list' => 'allpages', 'apnamespace' => '0', 'aplimit' => '5000'}
105
105
  post_me.merge!(options) if options
@@ -112,7 +112,7 @@ class RWikiBot
112
112
  # pages, and would require the bot maintainer to login to the wiki as the
113
113
  # bot to set the watchlist.
114
114
  def watchlist(options=nil)
115
- # raise VersionTooLowError unless meets_version_requirement(1,10)
115
+ raise VersionTooLowError unless meets_version_requirement(1,10)
116
116
  raise NotLoggedInError unless logged_in?
117
117
  post_me = {'list'=>'watchlist'}
118
118
  post_me.merge!(options) if options
@@ -121,7 +121,7 @@ class RWikiBot
121
121
 
122
122
  # This method will return Wiki-wide recent changes, almost as if looking at the Special page Recent Changes. But, in this format, a bot can handle it. Also we're using the API. And bots can't read.
123
123
  def recent_changes(options=nil)
124
- # raise VersionTooLowError unless meets_version_requirement(1,10)
124
+ raise VersionTooLowError unless meets_version_requirement(1,10)
125
125
  post_me = {"list" => "recentchanges", 'rclimit' => '5000'}
126
126
  post_me.merge!(options) if options
127
127
  make_request('query' , post_me).fetch('recentchanges').fetch('rc')
@@ -131,7 +131,7 @@ class RWikiBot
131
131
  # want to validate log events, or even just a notify bot that checks for
132
132
  # events and sends them off.
133
133
  def log_events(options=nil)
134
- # raise VersionTooLowError unless meets_version_requirement(1,11)
134
+ raise VersionTooLowError unless meets_version_requirement(1,11)
135
135
  post_me = {"list" => "logevents"}
136
136
  post_me.merge!(options) if options
137
137
  make_request('query', post_me).fetch('logevents').fetch('item')
@@ -140,7 +140,7 @@ class RWikiBot
140
140
  # This is the only meta method. It will return site information. I chose not
141
141
  # to allow it to specify, and it will only return all known properties.
142
142
  def site_info(siprop='general')
143
- # raise VersionTooLowError unless meets_version_requirement(1,9)
143
+ raise VersionTooLowError unless meets_version_requirement(1,9)
144
144
  post_me = {"meta" => "siteinfo" , "siprop" => siprop}
145
145
  siteinfo_result = make_request('query', post_me)
146
146
  siprop == 'general' ?
@@ -150,7 +150,7 @@ class RWikiBot
150
150
 
151
151
  # Get information about the current user
152
152
  def user_info(uiprop=nil)
153
- # raise VersionTooLowError unless meets_version_requirement(1,11)
153
+ raise VersionTooLowError unless meets_version_requirement(1,11)
154
154
  post_me = {"meta" => "userinfo" }
155
155
  post_me['uiprop'] = uiprop unless uiprop.nil?
156
156
 
data/lib/utilities.rb CHANGED
@@ -1,8 +1,16 @@
1
1
  module RWBUtilities
2
2
 
3
3
 
4
- # is_redirect?
5
- #
4
+ def meets_version_requirement(maj, min)
5
+ major, minor = @config['api_version'].to_s.split('.')
6
+ puts "#{major} > #{maj}"
7
+ if ( major.to_i > maj.to_i ) || ( (major.to_i == maj.to_i) && (minor.to_i > min.to_i) )
8
+ return true
9
+ else
10
+ return false
11
+ end
12
+ end # meets_version_requirement
13
+
6
14
  # Tests to see if a given page title is redirected to another page. Very Ruby.
7
15
  def is_redirect?(title)
8
16
  post_me = {'titles' => title, 'redirects'=>'', 'prop' => 'info'}
@@ -10,8 +18,6 @@ module RWBUtilities
10
18
  (result['result'] == "Success") && result.has_key?("redirects")
11
19
  end
12
20
 
13
- # logged_in?
14
- #
15
21
  # A quick (and public) method of checking whether or not we're logged in, since I don't want @config exposed
16
22
  def logged_in?
17
23
  @config['logged_in']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eddieroger-rwikibot
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddie Roger