Skip to content

Commit

Permalink
Case. Update Ruby requirement. Update changelog.
Browse files Browse the repository at this point in the history
  • Loading branch information
elifoster committed Oct 4, 2015
1 parent 26cea7b commit a45675f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
## Version 0
### Version 0.4.1
* check_login and check_create now use case/when statements instead of elsifs.
* check_create no longer returns anything.
* Update minimum Ruby version to 2.1, for refinements.
* Fix $namespaces hash syntax.
* Generally improved if statement syntax.
* Generally shortened a lot of code by using better syntax.
Expand Down
51 changes: 26 additions & 25 deletions lib/mediawiki/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,47 @@ module Auth
# @param secondtry [Boolean] Whether this login is the first or second try. False for first, true for second.
# @return [Boolean] true if successful, else false.
def check_login(result, secondtry)
if result == "Success"
case result
when "Success"
@logged_in = true
elsif result == "NeedToken" && secondtry == true
raise MediaWiki::Butt::NeedTokenMoreThanOnceError
false
elsif result == "NoName"
return true
when "NeedToken"
if secondtry == true
raise MediaWiki::Butt::NeedTokenMoreThanOnceError
return false
end
when "NoName"
raise MediaWiki::Butt::NoNameError
false
elsif result == "Illegal"
return false
when "Illegal"
raise MediaWiki::Butt::IllegalUsernameError
false
elsif result == "NotExists"
return false
when "NotExists"
raise MediaWiki::Butt::UsernameNotExistsError
false
elsif result == "EmptyPass"
return false
when "EmptyPass"
raise MediaWiki::Butt::EmptyPassError
false
elsif result == "WrongPass"
return false
when "WrongPass"
raise MediaWiki::Butt::WrongPassError
false
elsif result == "WrongPluginPass"
return false
when "WrongPluginPass"
raise MediaWiki::Butt::WrongPluginPassError
false
elsif result == "CreateBlocked"
return false
when "CreateBlocked"
raise MediaWiki::Butt::CreateBlockedError
false
elsif result == "Throttled"
return false
when "Throttled"
raise MediaWiki::Butt::ThrottledError
false
elsif result == "Blocked"
return false
when "Blocked"
raise MediaWiki::Butt::BlockedError
false
return false
end
end

# Checks the account creation result's error and raises the corresponding error.
# @param error [String] The parsed error "code" string
# @return [Boolean] Always false
def check_create(error)
case error
when "noname"
Expand Down Expand Up @@ -75,8 +78,6 @@ def check_create(error)
when "createaccount-hook-aborted"
raise MediaWiki::Butt::HookAbortedError
end

false #Apperently we always return false? What is the point of returning anything at all?
end

# Logs the user into the wiki. This is generally required for editing and getting restricted data. Will return the result of #check_login
Expand Down
2 changes: 1 addition & 1 deletion mediawiki-butt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|
'issue_tracker' => 'https://github.com/ftb-gamepedia/mediawiki-butt-ruby/issues'
}
s.post_install_message = 'ONE OF US! ONE OF US!'
s.required_ruby_version = '>= 2.0'
s.required_ruby_version = '>= 2.1'
s.files = [
"lib/mediawiki-butt.rb",
"lib/mediawiki/butt.rb",
Expand Down

0 comments on commit a45675f

Please sign in to comment.