14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# 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
|