sbif 0.2.1 → 0.2.3
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.
- data/History.txt +8 -0
- data/lib/sbif.rb +25 -12
- metadata +2 -2
data/History.txt
CHANGED
data/lib/sbif.rb
CHANGED
@@ -4,7 +4,7 @@ require 'date'
|
|
4
4
|
|
5
5
|
class SBIF
|
6
6
|
|
7
|
-
VERSION = "0.2.
|
7
|
+
VERSION = "0.2.3"
|
8
8
|
SITE = "http://api.sbif.cl/api-sbif/recursos"
|
9
9
|
INDICATORS = %w(uf utm dolar euro)
|
10
10
|
|
@@ -25,11 +25,20 @@ class SBIF
|
|
25
25
|
private
|
26
26
|
def get_data(currency, date)
|
27
27
|
date = format_date(:year => date[:year], :month => date[:month], :day => date[:day])
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
begin
|
29
|
+
content = open("#{SITE}/#{currency}/#{date}?apikey=#{self.api_key}&formato=json")
|
30
|
+
rescue
|
31
|
+
content = ""
|
32
|
+
end
|
33
|
+
values = parse_server_response(content)
|
34
|
+
if values.size < 1
|
35
|
+
nil
|
36
|
+
elsif values.size == 1
|
37
|
+
begin
|
38
|
+
to_float(values[0]["Valor"])
|
39
|
+
rescue
|
40
|
+
nil
|
41
|
+
end
|
33
42
|
else
|
34
43
|
results = {}
|
35
44
|
values.each do |v|
|
@@ -40,12 +49,16 @@ class SBIF
|
|
40
49
|
end
|
41
50
|
|
42
51
|
def parse_server_response(content)
|
43
|
-
|
44
|
-
|
45
|
-
|
52
|
+
result = ""
|
53
|
+
case
|
54
|
+
when content.kind_of?(StringIO)
|
55
|
+
result = content.string
|
46
56
|
when content.kind_of?(Tempfile)
|
47
|
-
content.read
|
57
|
+
result = content.read
|
58
|
+
else
|
59
|
+
result = JSON.generate({"Fecha" => "", "Valor" => "0"})
|
48
60
|
end
|
61
|
+
JSON.parse(result).values[0]
|
49
62
|
end
|
50
63
|
|
51
64
|
def format_date(params = {})
|
@@ -56,9 +69,9 @@ class SBIF
|
|
56
69
|
end
|
57
70
|
date = date.join("/")
|
58
71
|
end
|
59
|
-
|
72
|
+
|
60
73
|
def to_float(string)
|
61
74
|
string.gsub(".","").gsub(",",".").to_f
|
62
75
|
end
|
63
76
|
|
64
|
-
end
|
77
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sbif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Patricio Bruna
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-15 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hoe
|