From 2f687da30f70ed4b6bf91c45c35d7988b3ced55e Mon Sep 17 00:00:00 2001 From: elifoster Date: Sat, 3 Oct 2015 18:22:37 -0700 Subject: [PATCH] Those returns and shit make it much more readable. --- lib/mediawiki/butt.rb | 8 ++++---- lib/mediawiki/edit.rb | 12 ++++++------ lib/mediawiki/query.rb | 33 +++++++++++++++++---------------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/mediawiki/butt.rb b/lib/mediawiki/butt.rb index 5992da3..a6b9c1f 100644 --- a/lib/mediawiki/butt.rb +++ b/lib/mediawiki/butt.rb @@ -43,9 +43,9 @@ def post(params, autoparse = true, header = nil) res = header.nil? ? @client.post(@uri, params) : @client.post(@uri, params, header) if autoparse - JSON.parse(res.body) + return JSON.parse(res.body) else - res + return res end end @@ -56,9 +56,9 @@ def is_user_bot?(*username) groups = defined? username ? get_usergroups(username) : get_usergroups if groups != false - groups.include?("bot") + return groups.include?("bot") else - false + return false end end end diff --git a/lib/mediawiki/edit.rb b/lib/mediawiki/edit.rb index 8f3ba56..2b75255 100644 --- a/lib/mediawiki/edit.rb +++ b/lib/mediawiki/edit.rb @@ -26,9 +26,9 @@ def edit(title, text, minor = false, bot = true, *summary) response = post(params) if response["edit"]["result"] == "Success" - response["edit"]["newrevid"] + return response["edit"]["newrevid"] else - response["error"]["code"] + return response["error"]["code"] end end @@ -56,9 +56,9 @@ def create_page(title, text, summary = "New page", bot = true) response = post(params) if response["edit"]["result"] == "Success" - response["edit"]["pageid"] + return response["edit"]["pageid"] else - response["error"]["code"] + return response["error"]["code"] end end @@ -82,10 +82,10 @@ def upload(url, *filename) response = post(params) if response["upload"]["result"] == "Success" - true + return true elsif response["upload"]["result"] == "Warning" warnings = response["upload"]["warnings"] - warnings.keys[0] + return warnings.keys[0] end end end diff --git a/lib/mediawiki/query.rb b/lib/mediawiki/query.rb index ef4522f..01f9d70 100644 --- a/lib/mediawiki/query.rb +++ b/lib/mediawiki/query.rb @@ -23,7 +23,7 @@ def get_filerepo_names result["query"]["repos"].each do |repo| ret.push(repo["name"]) end - ret + return ret end # Gets meta information for the currently logged in user. @@ -38,9 +38,9 @@ def get_current_user_meta(prop) format: 'json' } - response = post(params) + return response = post(params) else - false + return false end end end @@ -65,9 +65,9 @@ def get_text(title) end if response["query"]["pages"][$revid]["missing"] == "" - nil + return nil else - response["query"]["pages"][$revid]["revisions"][0]["*"] + return response["query"]["pages"][$revid]["revisions"][0]["*"] end end @@ -112,9 +112,9 @@ def get_edit_token(page_name) end # URL encoding is not needed for some reason. - response["query"]["pages"][$revid]["edittoken"] + return response["query"]["pages"][$revid]["edittoken"] else - "+\\" + return "+\\" end end end @@ -152,7 +152,7 @@ def what_links_here(title, limit = 500) response["query"]["backlinks"].each do |bl| ret.push(bl["title"]) end - ret + return ret end # Returns an array of all page titles that belong to a given category. @@ -231,7 +231,7 @@ def get_random_pages(number_of_pages = 1, namespace = 0) responce["query"]["random"].each do |a| ret.push(a["title"]) end - ret + return ret end # Gets user information. This method should rarely be used by normal users. @@ -257,7 +257,7 @@ def get_userlists(prop, username = nil) response = post(params) end - response + return response end # Gets an array of all the user's groups. @@ -283,7 +283,7 @@ def get_usergroups(username = nil) end end - ret + return ret end # Gets the user rights for the user. @@ -309,7 +309,7 @@ def get_userrights(username = nil) end end - ret + return ret end # Gets contribution count for the user. @@ -336,7 +336,7 @@ def get_contrib_count(username = nil, autoparse = true) countstring = count.to_s.separate return countstring end - count + return count end # Gets when the user registered. @@ -374,7 +374,7 @@ def get_user_gender(username) gender = i["gender"] end - gender + return gender end # Gets the amount of results for the search value. @@ -397,7 +397,7 @@ def get_search_result_amount(search_value, namespace = 0) response = post(params) - response["query"]["searchinfo"]["totalhits"] + return response["query"]["searchinfo"]["totalhits"] end # Gets an array containing page titles that matched the search. @@ -424,7 +424,8 @@ def get_search_results(search_value, namespace = 0) response["query"]["search"].each do |search| ret.push(search["title"]) end - ret + + return ret end end end