Class: FE::CLI
- Inherits:
-
Thor
- Object
- Thor
- FE::CLI
- Defined in:
- lib/facturacr/cli.rb,
lib/facturacr/cli/generate.rb
Defined Under Namespace
Classes: Generate
Instance Method Summary collapse
- #check(key) ⇒ Object
- #send_document(path) ⇒ Object
- #setup(path) ⇒ Object
- #sign_document(xml_in, xml_out) ⇒ Object
- #test_invoice(number, data_path) ⇒ Object
Instance Method Details
#check(key) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/facturacr/cli.rb', line 46 def check(key) FE::Utils.configure([:config_file]) api = FE::Api.new document_status = api.get_document_status(key) ap document_status.to_h end |
#send_document(path) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/facturacr/cli.rb', line 66 def send_document(path) FE::Utils.configure([:config_file]) xml_document = FE::XmlDocument.new(path) invoice = xml_document.document signed_document = FE::SignedDocument.new(invoice,path) api = FE::Api.new if api.send_document(signed_document.payload) puts "Document Sent".green puts "KEY: #{invoice.key}" puts "Wait 5 seconds before check..." sleep 5 invoke :check, [invoice.key], :config_file=>[:config_file] else puts "ERROR".red ap api.errors raise "Sending Document Error" end end |
#setup(path) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/facturacr/cli.rb', line 98 def setup(path) puts "\n\n SETUP FACTURACR \n\n" say "A tmp directory will be created at: #{path}" say "config.yml file will be copied to #{path}" say "data.yml file will be copied to #{path}" answer = ask("Are you sure you want to continue?", :yellow, limited_to: ["y","n"]) if answer.downcase == "y" FileUtils.mkdir_p "#{path}/tmp" FileUtils.cp "resources/data.yml", "#{path}/tmp/data.yml" FileUtils.cp "config/config.yml", "#{path}/tmp/config.yml" say "Done.", :green else say "Ok. Bye", :green end end |
#sign_document(xml_in, xml_out) ⇒ Object
58 59 60 61 62 |
# File 'lib/facturacr/cli.rb', line 58 def sign_document(xml_in, xml_out) FE::Utils.configure([:config_file]) signer = FE::JavaSigner.new FE.configuration.key_path, FE.configuration.key_password, xml_in, xml_out signer.sign end |
#test_invoice(number, data_path) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/facturacr/cli.rb', line 87 def test_invoice(number, data_path) FE::Utils.configure([:config_file]) puts "Generating document ..." invoke :generate_invoice, [data_path,"tmp/unsigned_#{number}.xml"], number: number puts "Signing document ..." invoke :sign_document, ["tmp/unsigned_#{number}.xml","tmp/#{number}.xml"] puts "Sending ..." invoke :send_document, ["tmp/#{number}.xml"] end |