sbif 0.1.1 → 0.2

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.
Files changed (4) hide show
  1. data/History.txt +5 -0
  2. data/README.txt +3 -3
  3. data/lib/sbif.rb +22 -10
  4. metadata +2 -2
@@ -3,3 +3,8 @@
3
3
  * First Release
4
4
 
5
5
 
6
+ === 0.2 / 2011-11-12
7
+
8
+ * Various fixes and improvements
9
+ * Basic functionality as it should be
10
+
data/README.txt CHANGED
@@ -27,9 +27,9 @@ Befor you can start using this wrapper you need to get an API Key. You can ask f
27
27
  require 'sbif'
28
28
  sbif = SBIF.new(:api_key => "fff9cd0d852f6bb3330fc7c55978761603cbcb10")
29
29
 
30
- uf = sbif.euro(:year => 2011, :month => 9) # Array of Hashes (Dates and Values)
30
+ uf = sbif.euro(:year => 2011, :month => 9) # Hash => Date:Value
31
31
 
32
- dolar = sbif.dolar() # Value for today
32
+ dolar = sbif.dolar # Value for today
33
33
 
34
34
  utm = sbif.utm(:month => 9) # As we can not known for which year, we return the value for today
35
35
 
@@ -42,7 +42,7 @@ That is for now
42
42
 
43
43
  == INSTALL:
44
44
 
45
- * gem install sbif_wrapper
45
+ * gem install sbif
46
46
 
47
47
 
48
48
  == LICENSE:
@@ -4,7 +4,7 @@ require 'date'
4
4
 
5
5
  class SBIF
6
6
 
7
- VERSION = "0.1.1"
7
+ VERSION = "0.2"
8
8
  SITE = "http://api.sbif.cl/api-sbif/recursos"
9
9
  INDICATORS = %w(uf utm dolar euro)
10
10
 
@@ -14,20 +14,28 @@ class SBIF
14
14
  @api_key = params[:api_key]
15
15
  end
16
16
 
17
- INDICATORS.each do |indicator|
18
- method_name = indicator.to_sym
19
- define_method(method_name) do |date|
20
- get_data(:currency => indicator, :date => date)
17
+ INDICATORS.each do |currency|
18
+ method_name = currency.to_sym
19
+ define_method(method_name) do |date = {}|
20
+ get_data(currency, date)
21
21
  end
22
22
  end
23
23
 
24
24
  private
25
- def get_data(info = {})
26
- params = info[:date]
27
- date = format_date(:year => params[:year], :month => params[:month], :day => params[:day])
28
- content = open("#{SITE}/#{info[:currency]}/#{date}?apikey=#{self.api_key}&formato=json")
25
+ def get_data(currency, date)
26
+ date = format_date(:year => date[:year], :month => date[:month], :day => date[:day])
27
+ content = open("#{SITE}/#{currency}/#{date}?apikey=#{self.api_key}&formato=json")
29
28
  result = parse_server_response(content)
30
- JSON.parse(result)
29
+ values = JSON.parse(result).values[0]
30
+ if values.size == 1
31
+ to_float(values[0]["Valor"])
32
+ else
33
+ results = {}
34
+ values.each do |v|
35
+ results[v["Fecha"]] = to_float(v["Valor"])
36
+ end
37
+ results
38
+ end
31
39
  end
32
40
 
33
41
  def parse_server_response(content)
@@ -47,5 +55,9 @@ class SBIF
47
55
  end
48
56
  date = date.join("/")
49
57
  end
58
+
59
+ def to_float(string)
60
+ string.gsub(".","").gsub(",",".").to_f
61
+ end
50
62
 
51
63
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sbif
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: "0.2"
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-11 00:00:00 Z
13
+ date: 2011-11-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hoe