Class: SigepWeb::Models::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/sigep_web/Models/sender.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Sender

Returns a new instance of Sender.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sigep_web/Models/sender.rb', line 4

def initialize(options = {})
  authenticate = SigepWeb.configuration.authenticate

  @card = authenticate.card
  @contract_number = authenticate.contract
  @directorship_number = options[:directorship_number]
  @administrative_code = authenticate.administrative_code
  @name = options[:name]
  @address = options[:address]
  @number = options[:number]
  @complement = options[:complement]
  @neighborhood = options[:neighborhood]
  @zip_code = options[:zip_code]
  @city = options[:city]
  @uf = options[:uf]
  @phone = options[:phone]
  @fax = options[:fax]
  @email = options[:email]
  @payment_form = options[:payment_form]
  @postal_objects = options[:postal_objects]
end

Instance Method Details

#example_xmlObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/sigep_web/Models/sender.rb', line 65

def example_xml
  builder = Nokogiri::XML::Builder.new(encoding: 'ISO-8859-1') do |xml|
    xml.correioslog do
      xml.tipo_arquivo 'Postagem'
      xml.versao_arquivo '2.3'
      xml.plp do
        xml.id_plp
        xml.valor_global
        xml.mcu_unidade_postagem
        xml.nome_unidade_postagem
        xml.cartao_postagem @card
      end

      xml.remetente do
        xml.numero_contrato @contract_number
        xml.numero_diretoria @directorship_number
        xml.codigo_administrativo @administrative_code
        xml.nome_remetente { xml.cdata @name }
        xml.logradouro_remetente { xml.cdata @address }
        xml.numero_remetente @number
        xml.complemento_remetente { xml.cdata @complement }
        xml.bairro_remetente { xml.cdata @neighborhood }
        xml.cep_remetente { xml.cdata @zip_code }
        xml.cidade_remetente { xml.cdata @city }
        xml.uf_remetente @uf
        xml.telefone_remetente { xml.cdata @phone }
        xml.fax_remetente { xml.cdata @fax }
        xml.email_remetente { xml.cdata @email }
      end

      xml.forma_pagamento @payment_form

      XML::PostalObject.new(xml, @postal_objects).build_xml
    end
  end

  builder.to_xml.encode(Encoding::UTF_8)
end

#to_xmlObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sigep_web/Models/sender.rb', line 26

def to_xml
  builder = Nokogiri::XML::Builder.new(encoding: 'ISO-8859-1') do |xml|
    xml.correioslog do
      xml.tipo_arquivo 'Postagem'
      xml.versao_arquivo '2.3'
      xml.plp do
        xml.id_plp
        xml.valor_global
        xml.mcu_unidade_postagem
        xml.nome_unidade_postagem
        xml.cartao_postagem @card
      end

      xml.remetente do
        xml.numero_contrato @contract_number
        xml.numero_diretoria @directorship_number
        xml.codigo_administrativo @administrative_code
        xml.nome_remetente { xml.cdata @name }
        xml.logradouro_remetente { xml.cdata @address }
        xml.numero_remetente @number
        xml.complemento_remetente { xml.cdata @complement }
        xml.bairro_remetente { xml.cdata @neighborhood }
        xml.cep_remetente { xml.cdata @zip_code }
        xml.cidade_remetente { xml.cdata @city }
        xml.uf_remetente @uf
        xml.telefone_remetente { xml.cdata @phone }
        xml.fax_remetente { xml.cdata @fax }
        xml.email_remetente { xml.cdata @email }
      end

      xml.forma_pagamento @payment_form

      XML::PostalObject.new(xml, @postal_objects).build_xml
    end
  end

  builder.to_xml.gsub(/\n/, '').encode(Encoding::UTF_8)
end