rwikibot 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/lib/rwikibot.rb +71 -33
- metadata +5 -5
- data/config.yaml +0 -5
data/CHANGELOG
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
RWikiBot ChangeLog
|
2
|
+
|
3
|
+
1.0.1
|
4
|
+
- Added very basic error handing around the MAKE_REQUEST method since MediaWiki returns invalid YAML
|
5
|
+
- Fixed login method to accept domain value
|
6
|
+
- Check for domain being present and set in config.yaml
|
7
|
+
- Added redirect? method to return true/false if title is a redirect page
|
8
|
+
- Changed from "framework" to "library"
|
9
|
+
|
10
|
+
1.0.0 - Initial Version
|
data/lib/rwikibot.rb
CHANGED
@@ -65,6 +65,9 @@ class RWikiBot
|
|
65
65
|
|
66
66
|
@wikibotlogger.debug("LOGIN - Preparing login information...")
|
67
67
|
post_me = {'lgname'=>@config.fetch('username'),'lgpassword'=>@config.fetch('password')}
|
68
|
+
if @config.has_key?('domain') && (@config.fetch('domain') != nil)
|
69
|
+
post_me['lgdomain'] = @config.fetch('domain')
|
70
|
+
end
|
68
71
|
|
69
72
|
@wikibotlogger.debug("LOGIN - Asking make_request to perform login...")
|
70
73
|
login_result = make_request('login', post_me)
|
@@ -221,6 +224,31 @@ class RWikiBot
|
|
221
224
|
end
|
222
225
|
|
223
226
|
|
227
|
+
# Query
|
228
|
+
#
|
229
|
+
# This is a lot like REDIRECTS method, except its just a true/false to validate whether or not an article is a redirect. We could write the logic into the final bot app, but we're awesome and we include a quicky method.
|
230
|
+
#
|
231
|
+
# INPUT:: Title (please, just one!)
|
232
|
+
# OUTPUT:: True/False
|
233
|
+
def redirect? (title)
|
234
|
+
|
235
|
+
# Prepare the request
|
236
|
+
@wikibotlogger.debug "REDIRECT? - Preparing request information..."
|
237
|
+
post_me = {'titles' => title, 'redirects'=>'', 'prop' => 'info'}
|
238
|
+
|
239
|
+
|
240
|
+
#Make the request
|
241
|
+
@wikibotlogger.debug "REDIRECT? - Asking make_request find redirects..."
|
242
|
+
redirects_result = make_request('query', post_me)
|
243
|
+
@wikibotlogger.debug "REDIRECT? - We should have a result now..."
|
244
|
+
|
245
|
+
@wikibotlogger.debug "REDIRECT? - Processing result..."
|
246
|
+
|
247
|
+
|
248
|
+
return redirects_result.has_key?('redirects')
|
249
|
+
|
250
|
+
end
|
251
|
+
|
224
252
|
|
225
253
|
# Query
|
226
254
|
#
|
@@ -412,41 +440,51 @@ class RWikiBot
|
|
412
440
|
|
413
441
|
# Make Request is a method that actually handles making the request to the API. Since the API is somewhat standardized, this method is able to accept the action and a hash of variables, and it handles all the fun things MediaWiki likes to be weird over, like cookies and limits and actions. Its very solid, but I didn't want it public because it also does some post processing, and that's not very OO.
|
414
442
|
def make_request (action, post_this)
|
415
|
-
|
416
|
-
#Housekeeping. We need to add format and action to the request hash
|
417
|
-
post_this['format'] = 'yaml'
|
418
|
-
post_this['action'] = action
|
419
|
-
|
420
|
-
#change - preparing a POST string instead of hash.
|
421
|
-
post_string = ''
|
422
|
-
post_this.each_pair do |key, value|
|
423
|
-
post_string << "#{key}=#{value}&"
|
424
|
-
end
|
425
|
-
@wikibotlogger.info("MAKE REQUEST - Post String is: #{post_string}")
|
426
|
-
@wikibotlogger.debug "MAKE REQUEST - Sending request to: #{@config.fetch('uri')}"
|
427
|
-
|
428
|
-
#Send the actual request
|
429
|
-
@wikibotlogger.debug "MAKE REQUEST - Sending request..."
|
430
|
-
resp = @http.post( @config.fetch('uri').path , post_string , {'User-agent' => 'RWikiBot/0.1','Cookie' => bake(@config.fetch('cookie'))})
|
431
|
-
@wikibotlogger.info "MAKE REQUEST - Response: "
|
432
|
-
@wikibotlogger.info resp.body
|
433
|
-
@wikibotlogger.debug "MAKE REQUEST - End Response "
|
434
|
-
result = YAML.load(resp.body)
|
435
|
-
|
436
|
-
#Process response
|
437
|
-
@wikibotlogger.debug "MAKE REQUEST - Response received. Processing..."
|
438
|
-
return_result = result.fetch(action)
|
439
|
-
|
440
|
-
# A small check to make sure we don't need to save cookie data. Because usually, we don't
|
441
|
-
if @config.fetch('logged_in') == FALSE
|
442
|
-
@config['cookie'] = resp.header['set-cookie']
|
443
|
-
@wikibotlogger.debug "MAKE REQUEST - Received login cookie. Cookie is: #{resp.header['set-cookie']}"
|
444
|
-
end
|
445
443
|
|
446
|
-
#
|
447
|
-
|
448
|
-
|
444
|
+
# Now, we do error handling. We're big like that.
|
445
|
+
begin
|
446
|
+
|
447
|
+
#Housekeeping. We need to add format and action to the request hash
|
448
|
+
post_this['format'] = 'yaml'
|
449
|
+
post_this['action'] = action
|
450
|
+
|
451
|
+
#change - preparing a POST string instead of hash.
|
452
|
+
post_string = ''
|
453
|
+
post_this.each_pair do |key, value|
|
454
|
+
post_string << "#{key}=#{value}&"
|
455
|
+
end
|
456
|
+
@wikibotlogger.info("MAKE REQUEST - Post String is: #{post_string}")
|
457
|
+
@wikibotlogger.debug "MAKE REQUEST - Sending request to: #{@config.fetch('uri')}"
|
458
|
+
|
459
|
+
#Send the actual request
|
460
|
+
@wikibotlogger.debug "MAKE REQUEST - Sending request..."
|
461
|
+
resp = @http.post( @config.fetch('uri').path , post_string , {'User-agent' => 'RWikiBot/0.1','Cookie' => bake(@config.fetch('cookie'))})
|
462
|
+
@wikibotlogger.info "MAKE REQUEST - Response: "
|
463
|
+
@wikibotlogger.info resp.body
|
464
|
+
@wikibotlogger.debug "MAKE REQUEST - End Response "
|
465
|
+
result = YAML.load(resp.body)
|
466
|
+
|
467
|
+
#Process response
|
468
|
+
@wikibotlogger.debug "MAKE REQUEST - Response received. Processing..."
|
469
|
+
return_result = result.fetch(action)
|
470
|
+
|
471
|
+
# A small check to make sure we don't need to save cookie data. Because usually, we don't
|
472
|
+
if @config.fetch('logged_in') == FALSE
|
473
|
+
@config['cookie'] = resp.header['set-cookie']
|
474
|
+
@wikibotlogger.debug "MAKE REQUEST - Received login cookie. Cookie is: #{resp.header['set-cookie']}"
|
475
|
+
end
|
476
|
+
|
477
|
+
#Return the response
|
478
|
+
@wikibotlogger.debug "MAKE REQUEST - Response cleaned. Returning result."
|
479
|
+
return return_result
|
449
480
|
|
481
|
+
# The short form is that the API's error message causes an ArgumentError, so we gotta handle that. I notified MediaWiki
|
482
|
+
rescue ArgumentError
|
483
|
+
@wikibotlogger.error "MAKE REQUEST - The request has failed."
|
484
|
+
@wikibotlogger.error "MAKE REQUEST - Error is: #{$!}"
|
485
|
+
|
486
|
+
raise ArgumentError, "Problem processing returned YAML result"
|
487
|
+
end
|
450
488
|
end
|
451
489
|
|
452
490
|
# For some odd reason, MediaWiki sends back three cookies the first time you establis a session. For some even more odd, Net::HTTP doesn't treat the set-cookie headers individually the way that normal borowsers do. So, I have this processing method to handle cookie logic - when to send, when to set, etc. And it bakes cookies. Get it? Bake.
|
metadata
CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rwikibot
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date: 2007-02-
|
8
|
-
summary: A
|
6
|
+
version: 1.0.1
|
7
|
+
date: 2007-02-26 00:00:00 -06:00
|
8
|
+
summary: A library for creating MediaWiki bots.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: eddieroger @nospam@ gmail.com
|
@@ -30,14 +30,14 @@ authors:
|
|
30
30
|
files:
|
31
31
|
- lib/rwikibot.rb
|
32
32
|
- README
|
33
|
-
-
|
33
|
+
- CHANGELOG
|
34
34
|
test_files: []
|
35
35
|
|
36
36
|
rdoc_options:
|
37
37
|
- --inline-source
|
38
38
|
extra_rdoc_files:
|
39
39
|
- README
|
40
|
-
-
|
40
|
+
- CHANGELOG
|
41
41
|
executables: []
|
42
42
|
|
43
43
|
extensions: []
|