class SkypeCheck::Username
Public Class Methods
is_available?(username)
click to toggle source
when it comes to web services it's better to be explicit with semantic meanings of http return codes, it's better than calling !is_taken?(username) here.
# File lib/skype_check/username.rb, line 26 def is_available?(username) query(username)["status"] == 200 end
is_taken?(username)
click to toggle source
# File lib/skype_check/username.rb, line 21 def is_taken?(username) query(username)["status"] == 406 end
query(username)
click to toggle source
# File lib/skype_check/username.rb, line 11 def query(username) raise SkypeCheck::UsernameValidationError, "Input username is nil!" if username.nil? raise SkypeCheck::UsernameValidationError, "Input username is too long!" if username.size > 32 raise SkypeCheck::UsernameValidationError, "Input username is too short!" if username.size < 6 raise SkypeCheck::UsernameValidationError, "Input username should not start with a number!" if username.match(/\A\d/) resp_body = SkypeCheck::HTTPService.http_query(username).body JSON.parse(resp_body) end