Skip to content

Commit

Permalink
Those returns and shit make it much more readable.
Browse files Browse the repository at this point in the history
  • Loading branch information
elifoster committed Oct 4, 2015
1 parent a45675f commit 2f687da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
8 changes: 4 additions & 4 deletions lib/mediawiki/butt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/mediawiki/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
33 changes: 17 additions & 16 deletions lib/mediawiki/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -283,7 +283,7 @@ def get_usergroups(username = nil)
end
end

ret
return ret
end

# Gets the user rights for the user.
Expand All @@ -309,7 +309,7 @@ def get_userrights(username = nil)
end
end

ret
return ret
end

# Gets contribution count for the user.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down

2 comments on commit 2f687da

@xbony2
Copy link
Member

@xbony2 xbony2 commented on 2f687da Oct 4, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really only more readable if you aren't a native ruby programmer...

@elifoster
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just took a read at the Ruby style guide. You're right. Later today I'm going to make a fair amount of syntax and layout changes.

Please sign in to comment.