#!/usr/bin/env ruby require "tty-prompt" require "zup/generator" @prompt = TTY::Prompt.new @header = """ ######################################################################## ######################################################################## ###### ###### ###### Zup Generator v1 ###### ###### ###### ###### Generate code for connect gateway rest. ###### ###### ###### ######################################################################## ######################################################################## """ def login(error = false) system("clear") puts @header puts "Login e senha inválidos.\n\n" if error heart = @prompt.decorate('🍺 ') user = @prompt.ask('Qual o seu e-mail da zup?', default: ENV['USER']) pass = @prompt.mask("Qual sua senha?", mask: heart) @zup = Zup::Generator.new if @zup.login(user, pass) puts "LOGADO" else login(true) end end def load_data system("clear") puts @header puts "Carregando todas as informações necessárias...\n" puts "Isso pode levar alguns minutos...\n\n" @zup.load_data end def choice_api system("clear") puts @header apis = @zup.list_apis selected = @prompt.select("Qual API você quer conectar?", apis.map { |e| e[:name] }) @api = apis.select {|e| e[:name] == selected}.first choice_version end def choice_version versions = @zup.list_versions(@api[:id]) selected = @prompt.select("Qual versão da API?", versions.map { |e| e[:path] }) @version = versions.select {|e| e[:path] == selected}.first choice_action end def choice_action system("clear") puts @header puts """ API SELECIONADA: #{@api[:name]} VERSAO SELECIONADA: #{@version[:path]} """ selected = @prompt.select("Qual ação deseja fazer?", [ "Copiar para Clipboard o YAML", "Gerar pacote de Client", "Selecionar outra API", "Sair", ]) case selected when "Copiar para Clipboard o YAML" copy_yaml when "Selecionar outra API" choice_api when "Sair" sair end end def copy_yaml @zup.pbcopy JSON.parse(@zup.generate_swagger(@api[:id], @version[:id]).to_json).to_yaml choice_action end def sair system("clear") end login load_data choice_api