class Login
Public Instance Methods
do(name, password)
click to toggle source
# File lib/canzea/commands/login.rb, line 14 def do(name, password) credFile = "#{Dir.home}/.canzearc" uri = URI(Canzea::config[:canzea_platform_uri] + "/api/x/user/login") req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') req.body = {name: name, password: password}.to_json https = Net::HTTP.new(uri.hostname,uri.port) https.use_ssl = uri.instance_of? URI::HTTPS res = https.request(req) case res when Net::HTTPSuccess, Net::HTTPRedirection token = JSON.parse(res.body) File.open(credFile, 'w') { |file| file.write(token['token']) } puts "Login successful. Authorization cached." else puts res.body end end
get()
click to toggle source
# File lib/canzea/commands/login.rb, line 45 def get() credFile = "#{Dir.home}/.canzearc" token = File.read(credFile) return token end
logout()
click to toggle source
# File lib/canzea/commands/login.rb, line 39 def logout() credFile = "#{Dir.home}/.canzearc" File.delete(credFile) puts "Authorization cache cleared." end