sbif 0.1

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.
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
File without changes
@@ -0,0 +1,5 @@
1
+ === 0.1 / 2011-11-10
2
+
3
+ * First Release
4
+
5
+
@@ -0,0 +1,7 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/sbif.rb
7
+ test/test_sbif.rb
@@ -0,0 +1,71 @@
1
+ = SBIF
2
+
3
+ * https://github.com/pbruna/sbif_wrapper
4
+
5
+ == DESCRIPTION:
6
+
7
+ A Ruby library for working with the SBIF API (Superintendencia de Bancos e Instituciones Financieras de Chile).
8
+ You can find more information of the SBIF API here: http://api.sbif.cl/documentacion/
9
+
10
+
11
+ == SYNOPSIS:
12
+ At the moment you can query for the following currencys:
13
+
14
+ * Dolar
15
+ * Euro
16
+ * UF
17
+ * UTM
18
+
19
+ For each of this you can get the value for:
20
+
21
+ * a specific date,
22
+ * a month in a given year,
23
+ * a year
24
+
25
+ Befor you can start using this wrapper you need to get an API Key. You can ask for one here: http://api.sbif.cl/uso-de-api-key.html
26
+
27
+ require 'sbif'
28
+ sbif = SBIF.new(:api_key => "fff9cd0d852f6bb3330fc7c55978761603cbcb10")
29
+
30
+ uf = sbif.euro(:year => 2011, :month => 9) # Array of Hashes (Dates and Values)
31
+
32
+ dolar = sbif.dolar() # Value for today
33
+
34
+ utm = sbif.utm(:month => 9) # As we can not known for which year, we return the value for today
35
+
36
+ That is for now
37
+
38
+ == REQUIREMENTS:
39
+
40
+ * JSON
41
+ * OpenURI
42
+
43
+ == INSTALL:
44
+
45
+ * gem install sbif_wrapper
46
+
47
+
48
+ == LICENSE:
49
+
50
+ (The MIT License)
51
+
52
+ Copyright (c) 2011 Patricio Bruna
53
+
54
+ Permission is hereby granted, free of charge, to any person obtaining
55
+ a copy of this software and associated documentation files (the
56
+ 'Software'), to deal in the Software without restriction, including
57
+ without limitation the rights to use, copy, modify, merge, publish,
58
+ distribute, sublicense, and/or sell copies of the Software, and to
59
+ permit persons to whom the Software is furnished to do so, subject to
60
+ the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be
63
+ included in all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
66
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
67
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
68
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
69
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
70
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
71
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ # Hoe.plugin :compiler
7
+ # Hoe.plugin :gem_prelude_sucks
8
+ # Hoe.plugin :inline
9
+ # Hoe.plugin :racc
10
+ # Hoe.plugin :rubyforge
11
+
12
+ Hoe.spec 'sbif' do
13
+ # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
14
+ # you'll never have to touch them again!
15
+ # (delete this comment too, of course)
16
+
17
+ developer('Patricio Bruna', 'pbruna@itlinux.cl')
18
+
19
+ self.rubyforge_name = 'sbif_wrapper' # if different than 'sbif'
20
+ end
21
+
22
+ # vim: syntax=ruby
@@ -0,0 +1,51 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+ require 'date'
4
+
5
+ class SBIF
6
+
7
+ VERSION = "0.1"
8
+ SITE = "http://api.sbif.cl/api-sbif/recursos"
9
+ INDICATORS = %w(uf utm dolar euro)
10
+
11
+ attr_reader :api_key
12
+
13
+ def initialize(params)
14
+ @api_key = params[:api_key]
15
+ end
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)
21
+ end
22
+ end
23
+
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")
29
+ result = parse_server_response(content)
30
+ JSON.parse(result)
31
+ end
32
+
33
+ def parse_server_response(content)
34
+ case
35
+ when content.kind_of?(StringIO)
36
+ content.string
37
+ when content.kind_of?(Tempfile)
38
+ content.read
39
+ end
40
+ end
41
+
42
+ def format_date(params = {})
43
+ date = []
44
+ [params[:year], params[:month], params[:day]].each do |e|
45
+ break if e.nil?
46
+ date << e
47
+ end
48
+ date = date.join("/")
49
+ end
50
+
51
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require "sbif"
3
+
4
+ class TestSbif < Test::Unit::TestCase
5
+ def test_sanity
6
+ flunk "write tests or I will kneecap you"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sbif
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.1"
6
+ platform: ruby
7
+ authors:
8
+ - Patricio Bruna
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-11-10 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "2.12"
24
+ type: :development
25
+ version_requirements: *id001
26
+ description: |-
27
+ A Ruby library for working with the SBIF API (Superintendencia de Bancos e Instituciones Financieras de Chile).
28
+ You can find more information of the SBIF API here: http://api.sbif.cl/documentacion/
29
+ email:
30
+ - pbruna@itlinux.cl
31
+ executables: []
32
+
33
+ extensions: []
34
+
35
+ extra_rdoc_files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ files:
40
+ - .autotest
41
+ - History.txt
42
+ - Manifest.txt
43
+ - README.txt
44
+ - Rakefile
45
+ - lib/sbif.rb
46
+ - test/test_sbif.rb
47
+ - .gemtest
48
+ homepage: https://github.com/pbruna/sbif_wrapper
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --main
54
+ - README.txt
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project: sbif_wrapper
72
+ rubygems_version: 1.8.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: A Ruby library for working with the SBIF API (Superintendencia de Bancos e Instituciones Financieras de Chile)
76
+ test_files:
77
+ - test/test_sbif.rb