# frozen_string_literal: true module Meroku # Logic related to Users login, logout etc module User def self.login(email, password) url = 'https://www.meroku.com/login.json' data = { 'email' => email, 'password' => password }.to_json result = RestClient.post url, data, content_type: :json token = JSON.parse(result.body)['token'] IO.write("#{Dir.home}/.meroku_token", token) puts 'Logged in' rescue RestClient::Unauthorized raise Meroku::LoginFailed, 'Login Failed' end def self.logout file = "#{Dir.home}/.meroku_token" File.delete(file) if File.exist?(file) puts 'Logged out' end end end