lib/tsks/cli.rb in tsks-0.0.5 vs lib/tsks/cli.rb in tsks-0.0.6
- old
+ new
@@ -93,16 +93,16 @@
begin
res = Tsks::Request.post "/register", {email: options[:email],
password: options[:password]}
- if res && res[:status_code] == 201
+ if res && res[:ok] == true
File.write File.join(CLI.setup_folder, "token"), res[:token]
File.write File.join(CLI.setup_folder, "user_id"), res[:user_id]
Tsks::Actions.update_tsks_with_uuid res[:user_id]
puts "Succesfully registered."
- elsif res && res[:status_code] == 409
+ elsif res && res[:ok] == false
puts "This e-mail is already registered."
end
rescue Errno::ECONNREFUSED, SocketError
puts "Failed to connect to the API."
rescue JSON::ParserError
@@ -120,16 +120,16 @@
begin
res = Tsks::Request.post "/login", {email: options[:email],
password: options[:password]}
- if res && res[:status_code] == 200
+ if res && res[:ok] == true
File.write File.join(CLI.setup_folder, "token"), res[:token]
File.write File.join(CLI.setup_folder, "user_id"), res[:user_id]
Tsks::Actions.update_tsks_with_uuid res[:user_id]
puts "Succesfully logged in."
- elsif res && res[:status_code] == 403
+ elsif res && res[:ok] == false
puts "Invalid e-mail or password."
end
rescue Errno::ECONNREFUSED, SocketError
puts "Failed to connect to the API."
rescue JSON::ParserError
@@ -162,10 +162,10 @@
tsk[:created_at] = Time.parse(tsk[:created_at]).strftime "%F %T"
tsk[:updated_at] = Time.parse(tsk[:updated_at]).strftime "%F %T"
remote_tsks.append tsk
end
- if get_res[:status_code] == 200
+ if get_res[:ok] == true
local_tsks_to_post = local_tsks - remote_tsks
if local_tsks_to_post.count > 0
Tsks::Request.post "/tsks", token, {tsks: local_tsks_to_post}
end