Sha256: 67718d908406697fe10cbcd4012abaa5aaa7d7af6c8dc2e849d2de5852d47585
Contents?: true
Size: 1.14 KB
Versions: 11
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true require 'uffizzi' require 'uffizzi/response_helper' require 'uffizzi/clients/api/api_client' module Uffizzi class CLI::Login include ApiClient def initialize(options) @options = options end def run password = ENV['UFFIZZI_PASSWORD'] || IO::console.getpass('Enter Password: ') params = prepare_request_params(password) response = create_session(@options[:hostname], params) if ResponseHelper.created?(response) handle_succeed_response(response) else ResponseHelper.handle_failed_response(response) end end private def prepare_request_params(password) { user: { email: @options[:user], password: password.strip, }, } end def handle_succeed_response(response) account = response[:body][:user][:accounts].first return Uffizzi.ui.say('No account related to this email') unless account_valid?(account) ConfigFile.create(account[:id], response[:headers], @options[:hostname]) end def account_valid?(account) account[:state] == 'active' end end end
Version data entries
11 entries across 11 versions & 1 rubygems