Class: FE::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/facturacr/cli.rb,
lib/facturacr/cli/generate.rb

Defined Under Namespace

Classes: Generate

Instance Method Summary collapse

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(options[: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
84
85
86
# File 'lib/facturacr/cli.rb', line 66

def send_document(path)
  FE::Utils.configure(options[:config_file])
  xml_document = FE::XmlDocument.new(path)
  document = xml_document.document
  if document.is_a?(FE::ReceptionMessage)
    document.receiver_id_type = "02"
  end
  signed_document = FE::SignedDocument.new(document,path)
  api = FE::Api.new
  if api.send_document(signed_document.payload)
    puts "Document Sent".green
    puts "KEY: #{document.key}"
    puts "Wait 5 seconds before check..."
    sleep 5
    invoke :check, [document.key], :config_file=>options[:config_file]
  else
    puts "ERROR".red
    ap api.errors
    raise "Sending Document Error" 
  end  
end

#setup(path) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/facturacr/cli.rb', line 90

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 "#{FE.root}/resources/data.yml", "#{path}/tmp/data.yml"
    FileUtils.cp "#{FE.root}/config/config.yml", "#{path}/tmp/config.yml"
    say "Done.", :green
  else
    say "Ok. Bye", :green
  end
end

#sign(xml_in, xml_out) ⇒ Object



58
59
60
61
62
# File 'lib/facturacr/cli.rb', line 58

def sign(xml_in, xml_out)
  FE::Utils.configure(options[:config_file])
  signer = FE::JavaSigner.new FE.configuration.key_path, FE.configuration.key_password, xml_in, xml_out
  signer.sign
end