eba 1.5.6 → 1.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 764378712fdd296f175fff65f704622dc0a9b7e4
4
- data.tar.gz: f67894df06ad96cb905843b0dcfd48a093f103d7
3
+ metadata.gz: 7c7437b7166b2464059e5f0e07851117f01a41c5
4
+ data.tar.gz: 63d4b2dbd88f8f87f62100023cb1b37d3b540bb9
5
5
  SHA512:
6
- metadata.gz: a78bee6636ad03907a120ab33ca379160843195c91e225c3970eddbf5b8ea5efa260971cb80e5a651cc9cfc37e63d73bd114fe4630c0a96a5b7aada68b53bf1b
7
- data.tar.gz: ed3fc2f8783bf2059abef4c7dda98910ce24526e59223354ead18b62115b2d0310eb0121f6bddb52ce216b05cb477f6ad827cf05c2c075b1706556f6df11f6e7
6
+ metadata.gz: 161b14dbffb33ab76d91e20c904207ceeeca55fa8833125a8eff534ababa897463d0f4fbe971b00a543bb77d92bca56c9cbc790022630bac4377b77451cc38b1
7
+ data.tar.gz: a43ef4c0ee3167f42fd80fd53b8865bd38efab45cb048f2ce6b0aed8aee6a5ea138862862898070be73a34c1e8ade9e6261a4a53602476a7db0eef411a76f8ee
@@ -8,21 +8,21 @@ require_relative "data"
8
8
  class BCB < Encoder
9
9
 
10
10
  ################################################################################################
11
- # #
12
- # You MUST supply a valid certificate in order for the connection to work! #
13
- # The certificate you are looking for is located in this webpage: #
14
- # http://www.bcb.gov.br/?CERTDIG #
15
- # #
16
- # It will the most recent one which looks something like: #
17
- # Cadeia de CAs de *.bcb.gov.br (yyyy) #
18
- # #
19
- # You then have to generate a public key from this crt file, #
20
- # you can do so by following this StackOverflow post: #
21
- # http://stackoverflow.com/questions/5244129/use-rsa-private-key-to-generate-public-key #
22
- # #
23
- # With all this done, you will be able to access freely this #
11
+ # #
12
+ # You MUST supply a valid certificate in order for the connection to work! #
13
+ # The certificate you are looking for is located in this webpage: #
14
+ # http://www.bcb.gov.br/?CERTDIG #
15
+ # #
16
+ # It will the most recent one which looks something like: #
17
+ # Cadeia de CAs de *.bcb.gov.br (yyyy) #
18
+ # #
19
+ # You then have to generate a public key from this crt file, #
20
+ # you can do so by following this StackOverflow post: #
21
+ # http://stackoverflow.com/questions/5244129/use-rsa-private-key-to-generate-public-key #
22
+ # #
23
+ # With all this done, you will be able to access freely this #
24
24
  # service, without much hassle. Don't forget to upvote such an useful answer. #
25
- # #
25
+ # #
26
26
  ################################################################################################
27
27
 
28
28
  def initialize(path_to_certificate)
@@ -34,8 +34,8 @@ class BCB < Encoder
34
34
 
35
35
 
36
36
  @service = Savon.client({wsdl: "https://www3.bcb.gov.br/sgspub/JSP/sgsgeral/FachadaWSSGS.wsdl",
37
- ssl_cert_file: @pub_key,
38
- headers: {'Accept-Encoding' => 'gzip, deflate'}})
37
+ ssl_cert_file: @pub_key,
38
+ headers: {'Accept-Encoding' => 'gzip, deflate'}})
39
39
  end
40
40
 
41
41
  # List of all operations available for the webservice,
@@ -76,12 +76,14 @@ class BCB < Encoder
76
76
  return result
77
77
  end
78
78
 
79
- def build_bcb_data(name, code, periodicity, unit, day, month, year, value)
80
- is_unseasoned = name.include? " - com ajuste sazonal"
79
+ def build_bcb_data(name, code, periodicity, unit, day, month, year, value, is_unseasoned)
80
+ if is_unseasoned == nil then
81
+ is_unseasoned = name.include? " - com ajuste sazonal"
81
82
 
82
- if is_unseasoned then
83
- name.slice! " - com ajuste sazonal"
84
- end
83
+ if is_unseasoned then
84
+ name.slice! " - com ajuste sazonal"
85
+ end
86
+ end
85
87
 
86
88
  encoded_name = encode(name)
87
89
  encoded_periodicity = encode(periodicity)
@@ -92,8 +94,8 @@ class BCB < Encoder
92
94
  encoded_value = encode(value)
93
95
 
94
96
  return Data_bcb.new(encoded_name, code, encoded_periodicity,
95
- encoded_unit, encoded_day, encoded_month,
96
- encoded_year, encoded_value, is_unseasoned)
97
+ encoded_unit, encoded_day, encoded_month,
98
+ encoded_year, encoded_value, is_unseasoned)
97
99
  end
98
100
 
99
101
  def get_last_value(series_code)
@@ -102,7 +104,10 @@ class BCB < Encoder
102
104
  rescue
103
105
  return nil
104
106
  end
105
- xmlResult = Nokogiri::XML(response.to_hash[:get_ultimo_valor_xml_response][:get_ultimo_valor_xml_return], nil, 'UTF-8')
107
+
108
+ response = response.to_hash[:get_ultimo_valor_xml_response][:get_ultimo_valor_xml_return].sub("&", "-_1532_-")
109
+
110
+ xmlResult = Nokogiri::XML(response)
106
111
 
107
112
  # As it's a brazillian database it's column identifications are in portuguese,
108
113
  # the translation for the fields, in order, are:
@@ -112,16 +117,16 @@ class BCB < Encoder
112
117
  # DIA = DAY
113
118
  # MES = MONTH
114
119
  # ANO = YEAR
115
- # VALOR = VALUE
116
-
117
- return build_bcb_data(xmlResult.search("NOME").text,
118
- series_code,
119
- xmlResult.search("PERIODICIDADE").text,
120
- xmlResult.search("UNIDADE").text,
121
- xmlResult.search("DIA").text,
122
- xmlResult.search("MES").text,
123
- xmlResult.search("ANO").text,
124
- xmlResult.search("VALOR").text)
120
+ # VALOR = VALUe
121
+
122
+ return build_bcb_data(xmlResult.search("NOME").text.sub("-_1532_-", "&"),
123
+ series_code,
124
+ xmlResult.search("PERIODICIDADE").text,
125
+ xmlResult.search("UNIDADE").text.sub("-_1532_-", "&"),
126
+ xmlResult.search("DIA").text,
127
+ xmlResult.search("MES").text,
128
+ xmlResult.search("ANO").text,
129
+ xmlResult.search("VALOR").text, nil)
125
130
  end
126
131
 
127
132
  # Ensure that date is in the format dd/MM/YYY
@@ -148,8 +153,8 @@ class BCB < Encoder
148
153
 
149
154
  # Build the message from the start of the historical series
150
155
  message = { in0: {long: codes},
151
- in1: date,
152
- in2: Time.now.strftime('%d/%m/%Y').to_s}
156
+ in1: date,
157
+ in2: Time.now.strftime('%d/%m/%Y').to_s}
153
158
 
154
159
  # try and catch, as some series can be discontinued or a code may be broken
155
160
  begin
@@ -159,7 +164,7 @@ class BCB < Encoder
159
164
  puts "\n\nError requesting! #{erro}\n\n"
160
165
  end
161
166
 
162
- i = 0
167
+ i = 0
163
168
 
164
169
  result.css("SERIE").each do |serie|
165
170
  # recover identifying data from the getLastValue method,
@@ -184,12 +189,12 @@ class BCB < Encoder
184
189
  ano = data[1]
185
190
  end
186
191
 
187
- data_collection << build_bcb_data(base_data.name,
188
- array[i],
189
- base_data.periodicity,
190
- base_data.unit,
191
- dia, mes, ano,
192
- item.css("VALOR").text)
192
+ data_collection << build_bcb_data(base_data.name, codes[i],
193
+ base_data.periodicity,
194
+ base_data.unit,
195
+ dia, mes, ano,
196
+ item.css("VALOR").text,
197
+ base_data.seasonally_adjusted)
193
198
  end
194
199
  end
195
200
 
@@ -3,7 +3,7 @@
3
3
  # information.
4
4
  class Data_bcb
5
5
  @name = ""
6
- @periodicity = 0
6
+ @periodicity = ""
7
7
  @unit = ""
8
8
  @date = ""
9
9
  @value = 0.0
@@ -17,7 +17,7 @@ class Data_bcb
17
17
 
18
18
  @name = series_name
19
19
  @pk = series_code
20
- @periodicity = series_periodicity
20
+ @periodicity = series_periodicity.to_s
21
21
  @unit = series_unit
22
22
  @date = standardizes_date(series_day, series_month, series_year)
23
23
  @value = series_value.to_f
@@ -27,8 +27,54 @@ class Data_bcb
27
27
  # Return an "identification key" with data which should
28
28
  # be unique to a series (grouped).
29
29
  def key()
30
- return @name + @periodicity.to_s + @unity
30
+ return @name + @periodicity.to_s + @unit
31
31
  end
32
+
33
+ def is_valid?
34
+
35
+ if @name == nil or @name == '' then
36
+ puts "Found invalid name! Value is '#{@name}'"
37
+ return false
38
+ end
39
+
40
+ if @periodicity == nil or @periodicity == '' or @periodicity.length > 1 then
41
+ puts "Found invalid periodicity! Value is '#{@periodicity}'"
42
+ return false
43
+ end
44
+
45
+ if @unit == nil or @unit == '' then
46
+ puts "Found invalid unit! Value is '#{@unit}'"
47
+ return false
48
+ end
49
+
50
+ if @date == nil or @date == '' then
51
+ puts "Found invalid date! Value is '#{@date}'"
52
+ return false
53
+ else
54
+ if !(DateTime.parse(@date).to_date != nil rescue false) then
55
+ puts "Found invalid date! Value is '#{@date}'"
56
+ return false
57
+ end
58
+ end
59
+
60
+ if @value == nil then
61
+ puts "Found invalid value! Value is '#{@value}'"
62
+ return false
63
+ else
64
+ if !(@value.to_f != nil rescue false) then
65
+ puts "Found invalid value! Value is '#{@value}'"
66
+ return false
67
+ end
68
+ end
69
+
70
+ if @pk == nil or @pk <= 0 then
71
+ puts "Found invalid pk! Value is '#{@pk}'"
72
+ return false
73
+ end
74
+
75
+ return true
76
+ end
77
+
32
78
 
33
79
  # Note that there are no set methods in this class,
34
80
  # I built it in such a way that you are only intended
@@ -5,7 +5,7 @@ module Eba
5
5
  # ff - commits on feature
6
6
  # hh - commits on hotfix
7
7
 
8
- VERSION = "1.5.6"
8
+ VERSION = "1.6.7"
9
9
 
10
10
  #Version 1.0.1
11
11
  #
@@ -49,4 +49,11 @@ module Eba
49
49
 
50
50
  #Version 1.5.6
51
51
  # fixes identification and handling of seazonaly adjusted data points.
52
+
53
+ #Version 1.6.7
54
+ # Treats exception caused by the character '&' on Nokogiri conversion.
55
+ # Correctly identifies and classifies seasonally adjusted data.
56
+ #
57
+ # Adds verifications of validity for data-type.
58
+ # Changes tests in order to incorporate validity detection.
52
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eba
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.6
4
+ version: 1.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Campos Cruz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-06 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement