Class: SICONFI

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_siconfi/siconfi.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSICONFI



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/easy_siconfi/siconfi.rb', line 7

def initialize()
  @webservice_url = "http://apidatalake.tesouro.gov.br/ords/siconfi/tt/"
  @available_no_anexo_rreo = ['RREO-Anexo 01', 'RREO-Anexo 02', 'RREO-Anexo 03', 
                                'RREO-Anexo 04', 'RREO-Anexo 04 - RGPS', 'RREO-Anexo 04 - RPPS', 
                              'RREO-Anexo 04.0 - RGPS', 'RREO-Anexo 04.1', 'RREO-Anexo 04.2', 
                              'RREO-Anexo 04.3 - RGPS', 'RREO-Anexo 05', 'RREO-Anexo 06', 
                              'RREO-Anexo 07', 'RREO-Anexo 09', 'RREO-Anexo 10 - RGPS', 
                              'RREO-Anexo 10 - RPPS', 'RREO-Anexo 11', 'RREO-Anexo 13', 'RREO-Anexo 14']
  @available_no_anexo_rgf = ['RGF-Anexo 01', 'RGF-Anexo 02', 'RGF-Anexo 03', 'RGF-Anexo 04', 'RGF-Anexo 06']

  @available_co_tipo_demonstrativo = ['RREO', 'RREO Simplificado', 'RGF', 'RGF Simplificado']
end

Instance Attribute Details

#available_co_tipo_demonstrativoObject

Returns the value of attribute available_co_tipo_demonstrativo.



5
6
7
# File 'lib/easy_siconfi/siconfi.rb', line 5

def available_co_tipo_demonstrativo
  @available_co_tipo_demonstrativo
end

#available_no_anexo_rgfObject

Returns the value of attribute available_no_anexo_rgf.



5
6
7
# File 'lib/easy_siconfi/siconfi.rb', line 5

def available_no_anexo_rgf
  @available_no_anexo_rgf
end

#available_no_anexo_rreoObject

Returns the value of attribute available_no_anexo_rreo.



5
6
7
# File 'lib/easy_siconfi/siconfi.rb', line 5

def available_no_anexo_rreo
  @available_no_anexo_rreo
end

Instance Method Details

#check_an_exercicio(an_exercicio) ⇒ Object



94
95
96
# File 'lib/easy_siconfi/siconfi.rb', line 94

def check_an_exercicio(an_exercicio)
  an_exercicio != nil && an_exercicio.to_i > 1940 && an_exercicio != nil
end

#check_co_tipo_demonstrativo(co_tipo_demonstrativo) ⇒ Object



86
87
88
# File 'lib/easy_siconfi/siconfi.rb', line 86

def check_co_tipo_demonstrativo(co_tipo_demonstrativo)
  @available_co_tipo_demonstrativo.index(co_tipo_demonstrativo) != nil && co_tipo_demonstrativo != nil
end

#check_id_ente(id_ente) ⇒ Object



98
99
100
# File 'lib/easy_siconfi/siconfi.rb', line 98

def check_id_ente(id_ente)
  id_ente != nil && id_ente.to_i > 0 && id_ente != nil
end

#check_no_anexo(no_anexo) ⇒ Object

this list comes from the documentation @ apidatalake.tesouro.gov.br/docs/siconfi/#/RREO



76
77
78
79
80
81
82
83
84
# File 'lib/easy_siconfi/siconfi.rb', line 76

def check_no_anexo(no_anexo)
  if no_anexo == nil then
    false
  elsif no_anexo.match(/^\D\d+/) then
    (no_anexo.to_i < @available_no_anexo_rreo.size || @available_no_anexo_rgf.size) && no_anexo.to_i >= 0 
  else
    @available_no_anexo_rreo.index(no_anexo) != nil || @available_no_anexo_rgf.index(no_anexo) != nil
  end
end

#check_nr_periodo(nr_periodo) ⇒ Object



90
91
92
# File 'lib/easy_siconfi/siconfi.rb', line 90

def check_nr_periodo(nr_periodo)
  nr_periodo >= 1 && nr_periodo <= 6 && nr_periodo != nil
end

#connected?Boolean



24
25
26
27
28
29
30
31
32
33
# File 'lib/easy_siconfi/siconfi.rb', line 24

def connected?()
  mock_query = "an_exercicio=2019&nr_periodo=1&co_tipo_demonstrativo=RREO&id_ente=3550308"
  response = get_to_server("#{@webservice_url}#{mock_query}")

  if response.to_s.eql? '' then
    false
  else
    true
  end
end

#consume_json(complex_json) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/easy_siconfi/siconfi.rb', line 63

def consume_json(complex_json)
  data_array = []
  output = JSON.parse(complex_json)

  output['items'].each do |hash|
    data_array << SICONFIData.new(hash)
  end

  data_array
end

#get_to_server(str) ⇒ Object



20
21
22
# File 'lib/easy_siconfi/siconfi.rb', line 20

def get_to_server(str)
  Net::HTTP.get(URI(str))
end

#query_data(hash) ⇒ Object



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
# File 'lib/easy_siconfi/siconfi.rb', line 35

def query_data(hash)
  if check_no_anexo(hash[:no_anexo]) && check_co_tipo_demonstrativo(hash[:co_tipo_demonstrativo]) &&  
     check_nr_periodo(hash[:nr_periodo]) &&  check_an_exercicio(hash[:an_exercicio]) &&  
     check_id_ente(hash[:id_ente]) then

    url = @webservice_url

    if hash[:no_anexo].index("RREO") != nil || hash[:no_anexo].match(/^\D\d+/) then
      url = "#{url}rreo?"

    elsif hash[:no_anexo].index("RGF") != nil then
      url = "#{url}rgf?"
      url = "#{url}in_periodicidade=#{hash[:in_periodicidade]}&" 
      url = "#{url}&co_poder=#{hash[:co_poder]}&"
    end

    url = "#{url}an_exercicio=#{hash[:an_exercicio]}&"
    url = "#{url}nr_periodo=#{hash[:nr_periodo]}&"
    url = "#{url}co_tipo_demonstrativo=#{hash[:co_tipo_demonstrativo]}&"
    url = "#{url}no_anexo=#{hash[:no_anexo]}&"
    url = "#{url}id_ente=#{hash[:id_ente]}"

    consume_json(get_to_server(url))
  else
    nil
  end
end