eba 1.0.2.3 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eba/bcb.rb +54 -39
- data/lib/eba/version.rb +9 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf8749b76c5de0c62ecf47f0a883a2e8f867106f
|
4
|
+
data.tar.gz: 4fb8d1d541e15f620474e6de1f1e04531f4c54bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18b1a068a9c03f6cf7abd8236cd1606da5bbf8ab15f7faac38fdfc686eb86a8ba8d20f47603d87c89d706641a40a8a1bf2e01479d69e6917a863a868064fd344
|
7
|
+
data.tar.gz: fd8d96d343bcf6d1970b4cc064cf015f2dd22e30b3c0ba348a24a277ebaa2636e90872fd3299918e22c9a42c5f6ce587de85c37a3adc896276193cfd8743e328
|
data/lib/eba/bcb.rb
CHANGED
@@ -34,16 +34,31 @@ 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,
|
42
|
-
# useful for expanding the gem
|
42
|
+
# useful for expanding the gem.
|
43
43
|
def list_operations()
|
44
44
|
return @service.operations
|
45
45
|
end
|
46
46
|
|
47
|
+
# Removes all invalid series from an array.
|
48
|
+
#
|
49
|
+
# An invalid series has last value.
|
50
|
+
def purge_invalid_series(array_of_codes)
|
51
|
+
result = []
|
52
|
+
|
53
|
+
array_of_codes.each do |code|
|
54
|
+
if get_last_value(code) != nil
|
55
|
+
result << code
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
return result
|
60
|
+
end
|
61
|
+
|
47
62
|
def get_last_value(series_code)
|
48
63
|
begin
|
49
64
|
response = @service.call(:get_ultimo_valor_xml, message: {in0: "#{series_code}"})
|
@@ -73,57 +88,57 @@ class BCB < Encoder
|
|
73
88
|
|
74
89
|
# Ensure that date is in the format dd/MM/YYY
|
75
90
|
def get_all_data_for_array(array_of_codes, date)
|
76
|
-
|
91
|
+
result = nil
|
77
92
|
codes = Array.new()
|
78
93
|
data_collection = Array.new()
|
79
94
|
|
80
|
-
|
81
|
-
|
95
|
+
# This request has a limit of series he can get at a time, thus
|
96
|
+
# it's way simpler to break a composite requests in various smaller
|
97
|
+
# requests. The Data_bcb class serves as a way to organize such data
|
98
|
+
# and allow the developer to easily identify which series each data
|
99
|
+
# object pertains.
|
100
|
+
array_of_codes.each_slice(50).to_a.each do |array|
|
101
|
+
array = purge_invalid_series(array)
|
82
102
|
|
83
103
|
# Build the message from the start of the historical series
|
84
|
-
message = { in0: {long:
|
104
|
+
message = { in0: {long: array},
|
85
105
|
in1: date,
|
86
106
|
in2: Time.now.strftime('%d/%m/%Y').to_s}
|
87
|
-
|
107
|
+
|
88
108
|
# try and catch, as some series can be discontinued or a code may be broken
|
89
109
|
begin
|
90
|
-
# This request has a limit of series he can get at a time, thus
|
91
|
-
# it's way simpler to break a composite requests in various smaller
|
92
|
-
# requests. The Data_bcb class serves as a way to organize such data
|
93
|
-
# and allow the developer to easily identify which series each data
|
94
|
-
# object pertains.
|
95
110
|
response = @service.call(:get_valores_series_xml, message: message)
|
96
|
-
|
111
|
+
result = Nokogiri::XML(response.to_hash[:get_valores_series_xml_response] \
|
97
112
|
[:get_valores_series_xml_return])
|
98
|
-
|
99
|
-
|
100
|
-
puts "
|
113
|
+
|
114
|
+
rescue Exception => erro
|
115
|
+
puts "Error requesting! #{erro}"
|
101
116
|
end
|
102
117
|
|
103
|
-
|
104
|
-
|
118
|
+
i = 0
|
119
|
+
|
120
|
+
result.css("SERIE").each do |serie|
|
121
|
+
# recover identifying data from the getLastValue method,
|
122
|
+
# as the get_valores_series_xml desn't have identifying data
|
123
|
+
# as series name, periodicity, etc.
|
124
|
+
base_data = get_last_value(array[i])
|
125
|
+
comp = 'name="ID" value="' + array[i].to_s + '"'
|
126
|
+
|
127
|
+
if serie.inspect.include? comp
|
128
|
+
serie.css("ITEM").each do |item|
|
129
|
+
data_collection << Data_bcb.new(encode(base_data.name),
|
130
|
+
array[i],
|
131
|
+
base_data.periodicity,
|
132
|
+
encode(base_data.unit),
|
133
|
+
"1",
|
134
|
+
item.css("DATA").text.split("/")[0],
|
135
|
+
item.css("DATA").text.split("/")[1],
|
136
|
+
item.css("VALOR").text)
|
137
|
+
end
|
138
|
+
end
|
105
139
|
|
106
|
-
|
107
|
-
# recover identifying data from the getLastValue method,
|
108
|
-
# as the get_valores_series_xml desn't have identifying data
|
109
|
-
# as series name, periodicity, etc.
|
110
|
-
base_data = get_last_value(code)
|
111
|
-
|
112
|
-
if result != nil then
|
113
|
-
# Encode enforces data data is being read as UTF-8, as
|
114
|
-
# portuguese uses a huge ammount of special characters and
|
115
|
-
# accentuations.
|
116
|
-
result.css("ITEM").each do |item|
|
117
|
-
data_collection << Data_bcb.new(encode(base_data.name),
|
118
|
-
code,
|
119
|
-
base_data.periodicity,
|
120
|
-
encode(base_data.unit),
|
121
|
-
"1",
|
122
|
-
item.css("DATA").text.split("/")[0],
|
123
|
-
item.css("DATA").text.split("/")[1],
|
124
|
-
item.css("VALOR").text)
|
140
|
+
i = i + 1
|
125
141
|
end
|
126
|
-
end
|
127
142
|
end
|
128
143
|
|
129
144
|
return data_collection
|
data/lib/eba/version.rb
CHANGED
@@ -2,33 +2,35 @@ module Eba
|
|
2
2
|
# For documentation purposes:
|
3
3
|
# VERSION = mm.dd.ff.hh
|
4
4
|
# mm - commits on master
|
5
|
-
# dd - commits on development
|
6
5
|
# ff - commits on feature
|
7
6
|
# hh - commits on hotfix
|
8
7
|
|
9
|
-
VERSION = "1.
|
8
|
+
VERSION = "1.3.3"
|
10
9
|
|
11
|
-
#Version 1.0.
|
10
|
+
#Version 1.0.1
|
12
11
|
#
|
13
12
|
# Updater gemspec.
|
14
13
|
# Added classes Encoder and DataBCB for user.
|
15
14
|
|
16
|
-
#Version 1.
|
15
|
+
#Version 1.1.1
|
17
16
|
# List operations now returns a string instead of printing the methods of the webservice.
|
18
17
|
# get_last_value in BCB will return nil if the supplied code is invalid.
|
19
18
|
# get_all_data_for_array will now return data for an invalid code, but will still prompt an error mesage.
|
20
19
|
# added rspec tests, guarantying consistency
|
21
20
|
# spec/valid_certificate contains a certificate which is valid at this moment (2016-11-22)
|
22
21
|
|
23
|
-
#Version 1.
|
22
|
+
#Version 1.1.2
|
24
23
|
# Now get_all_data_for_array also expects a valid date in the format dd/MM/YYYY.
|
25
24
|
|
26
25
|
|
27
|
-
#Version 1.
|
26
|
+
#Version 1.1.3
|
28
27
|
# Removed the removal of '.' character from value, it was actually losing data.
|
29
28
|
# Changed DataBCB class name to Data_bcb, to keep with the standard snake case.
|
30
29
|
# updated spec tests accordingly.
|
31
30
|
|
32
|
-
#Version 1.
|
31
|
+
#Version 1.2.3
|
33
32
|
# Added HTTP compression to Savon requests.
|
33
|
+
|
34
|
+
#Version 1.3.3
|
35
|
+
# get_all_data_for_array extracts data now as bulk, in order to make better use of the compression.
|
34
36
|
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.
|
4
|
+
version: 1.3.3
|
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: 2016-12-
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|