IPC.cr API updates.

ipc07
Luka Vandervelden 2019-06-06 01:16:52 +02:00
parent 8c8b55c7fd
commit 66e2eaad48
1 changed files with 8 additions and 7 deletions

View File

@ -72,7 +72,7 @@ module AuthD
initialize "auth" initialize "auth"
end end
def get_token?(login : String, password : String) def get_token?(login : String, password : String) : String?
send RequestTypes::GetToken, { send RequestTypes::GetToken, {
:login => login, :login => login,
:password => password :password => password
@ -81,13 +81,13 @@ module AuthD
response = read response = read
if response.type == ResponseTypes::Ok.value.to_u8 if response.type == ResponseTypes::Ok.value.to_u8
response.payload String.new response.payload
else else
nil nil
end end
end end
def get_user?(login : String, password : String) def get_user?(login : String, password : String) : User?
send RequestTypes::GetUserByCredentials, { send RequestTypes::GetUserByCredentials, {
:login => login, :login => login,
:password => password :password => password
@ -96,7 +96,7 @@ module AuthD
response = read response = read
if response.type == ResponseTypes::Ok.value.to_u8 if response.type == ResponseTypes::Ok.value.to_u8
User.from_json response.payload User.from_json String.new response.payload
else else
nil nil
end end
@ -136,11 +136,12 @@ module AuthD
response = read response = read
pp! response.type pp! response.type
payload = String.new response.payload
case ResponseTypes.new response.type.to_i case ResponseTypes.new response.type.to_i
when ResponseTypes::Ok when ResponseTypes::Ok
AuthD::User.from_json response.payload AuthD::User.from_json payload
else else
Exception.new response.payload Exception.new payload
end end
end end
@ -164,7 +165,7 @@ module AuthD
when ResponseTypes::Ok when ResponseTypes::Ok
true true
else else
Exception.new response.payload Exception.new String.new response.payload
end end
end end
end end