sbif-rails 1.0.4

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 409b27d70170c37272efff91361e7afc81c266d7255a671bd75dd12ff9166418
4
+ data.tar.gz: 0fff0c1c192400c778b407b75da97d6412724ad3068d70c839c4950fcc50c959
5
+ SHA512:
6
+ metadata.gz: d60b5d6abcf43bb826ad7fe407d3c16a915252963666f3ccb62e6dee63926e9a51b9c6dc1b4d9cd2ce219ee1208dc3b2077ca44b2e887bd3650fcb25d37e8c20
7
+ data.tar.gz: 28b3f9c15b6a9127108510a6c9671199c98088364145f22495e13be20f8902b370afcfb4614218d2cd6cc3445afe5e5941b3c721d3f64fa8a2cde61687b29466
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea/
16
+ sbif-rails.iml
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sbif-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Paulo Tarud
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # SbifRails
2
+
3
+ ## Description
4
+
5
+ SBIF-Rails helps to consume the API SBIF in a Ruby on Rails application from http://api.sbif.cl/ in order to get values on different dates of several index:
6
+
7
+ * Dollar
8
+ * Euro
9
+ * IPC
10
+ * UF
11
+ * UTM
12
+
13
+ ## Installation
14
+
15
+ Add this line in your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'sbif-rails'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install sbif-rails
28
+
29
+ ### Config API KEY
30
+
31
+ First you must to generate the configuration file.
32
+
33
+ $ rails g sbif:config
34
+
35
+ This will add a file in config/initializer/sbif_rails.rb and then you have to edit the api key from this file.
36
+
37
+ ## Usage
38
+
39
+ ### Dollar
40
+
41
+ This method gets the current value of Dollar, it return a Currency object that have two attributes,
42
+ value of type float and date of type date.
43
+
44
+ ```ruby
45
+ SbifRails::Dollar.get_current
46
+ ```
47
+ This method gets all values of Dollar given a specific day, it needs three arguments of type integer, year, month and day,
48
+ it return an Array of Currency objects that its have two attributes, value of type float and date of type date.
49
+
50
+ ```ruby
51
+ SbifRails::Dollar.get_by_day(year,month,day)
52
+ ```
53
+
54
+ This method gets all values of Dollar given a particular month, it needs two arguments of type integer, year and month day,
55
+ it return an Array of Currency objects that its have two attributes, value of type float and date of type date.
56
+
57
+ ```ruby
58
+ SbifRails::Dollar.get_by_month(year,month)
59
+ ```
60
+
61
+ This method gets all values of Dollar given a specific day, it needs one argument of type integer, year,
62
+ it return Array of Currency objects that its have two attributes, value of type float and date of type date.
63
+
64
+ ```ruby
65
+ SbifRails::Dollar.get_by_year(year)
66
+ ```
67
+
68
+ ### Euro
69
+
70
+ This method gets the current value of Euro, it return a Currency object that have two attributes,
71
+ value of type float and date of type date.
72
+
73
+ ```ruby
74
+ SbifRails::Euro.get_current
75
+ ```
76
+ This method gets all values of Euro given a specific day, it needs three arguments of type integer, year,month and day,
77
+ it return an Array of Currency objects that its have two attributes, value of type float and date of type date.
78
+
79
+ ```ruby
80
+ SbifRails::Euro.get_by_day(year,month,day)
81
+ ```
82
+
83
+ This method gets all values of Euro given a specific month, it needs two arguments of type integer, year and month day,
84
+ it return an Array of Currency objects that its have two attributes, value of type float and date of type date.
85
+
86
+ ```ruby
87
+ SbifRails::Euro.get_by_month(year,month)
88
+ ```
89
+
90
+ This method gets all values of Euro given a specific year, it needs one argument of type integer, year,
91
+ it return Array of Currency objects that its have two attributes, value of type float and date of type date.
92
+
93
+ ```ruby
94
+ SbifRails::Euro.get_by_year(year)
95
+ ```
96
+
97
+ ### UF
98
+
99
+ This method gets the current value of Uf, it return a Currency object that have two attributes,
100
+ value of type float and date of type date.
101
+
102
+ ```ruby
103
+ SbifRails::Uf.get_current
104
+ ```
105
+ This method gets all values of Uf given a specific day, it needs three arguments of type integer, year,month and day,
106
+ it return an Array of Currency objects that its have two attributes, value of type float and date of type date.
107
+
108
+ ```ruby
109
+ SbifRails::Uf.get_by_day(year,month,day)
110
+ ```
111
+
112
+ This method gets all values of Uf given a specific month, it needs one argument of type integer, year,
113
+ it return an Array of Currency objects that its have two attributes, value of type float and date of type date.
114
+
115
+ ```ruby
116
+ SbifRails::Uf.get_by_month(year,month)
117
+ ```
118
+
119
+ This method gets all values of Uf given a specific year, it needs one argument of type integer, year,
120
+ it return Array of Currency objects that its have two attributes, value of type float and date of type date.
121
+
122
+ ```ruby
123
+ SbifRails::Uf.get_by_year(year)
124
+ ```
125
+
126
+ ### IPC
127
+
128
+ This method gets all values of IPC given a specific day, it needs two arguments of type integer, year and month day,
129
+ it return an Array of Currency objects that its have two attributes, value of type float and date of type date.
130
+
131
+ ```ruby
132
+ SbifRails::Uf.get_by_month(year,month)
133
+ ```
134
+
135
+ This method gets all values of IPC given a specific year, it needs one argument of type integer, year,
136
+ it return Array of Currency objects that its have two attributes, value of type float and date of type date.
137
+
138
+ ```ruby
139
+ SbifRails::Uf.get_by_year(year)
140
+ ```
141
+
142
+ ### UTM
143
+
144
+ This method gets all values of UTM given a specific day, it needs two arguments of type integer, year and month day,
145
+ it return an Array of Currency objects that its have two attributes, value of type float and date of type date.
146
+
147
+ ```ruby
148
+ SbifRails::Uf.get_by_month(year,month)
149
+ ```
150
+
151
+ This method gets all values of UTM given a specific day, it needs one argument of type integer, year,
152
+ it return Array of Currency objects that its have two attributes, value of type float and date of type date.
153
+
154
+ ```ruby
155
+ SbifRails::Uf.get_by_year(year)
156
+ ```
157
+
158
+ ## Author
159
+ Paulo Tarud
160
+ CTO
161
+ RISE TECHNOLOGY SPA
162
+
163
+ ## Contributing
164
+
165
+ 1. Fork it (https://github.com/RiseTechnologySpA/sbif-rails/fork)
166
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
167
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
168
+ 4. Push to the branch (`git push origin my-new-feature`)
169
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,16 @@
1
+ require 'rails/generators'
2
+
3
+ module Sbif
4
+ module Generators
5
+ class ConfigGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
7
+ desc <<DESC
8
+ Description:
9
+ Creates an initializer file for Sbif API KEY configuration at config/initializers.
10
+ DESC
11
+ def copy_config_file
12
+ template 'sbif_api_key_config.rb', 'config/initializers/sbif_rails.rb'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ SbifRails.configure do |config|
2
+ config.api_key = 'your-api-key-here'
3
+ end
data/lib/sbif-rails.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'sbif-rails/version'
2
+ require 'sbif-rails/base'
3
+ require 'sbif-rails/config'
4
+ require 'sbif-rails/currency'
5
+ require 'sbif-rails/dollar'
6
+ require 'sbif-rails/euro'
7
+ require 'sbif-rails/ipc'
8
+ require 'sbif-rails/uf'
9
+ require 'sbif-rails/utm'
10
+
11
+ module SbifRails
12
+ end
@@ -0,0 +1,63 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'date'
4
+
5
+ module SbifRails
6
+ module Base
7
+ URL = 'http://api.sbif.cl/api-sbifv3/recursos_api'
8
+
9
+ def api_key
10
+ @api_key ||= SbifRails.config.api_key
11
+ end
12
+
13
+ def get_by_month(year, month)
14
+ url = "#{URL}/#{name}/#{year.to_s}/#{month.to_s}?apikey=#{api_key}&formato=json"
15
+ uri = URI(url)
16
+ response = Net::HTTP.get uri
17
+ currencies_response = JSON.parse response
18
+ currencies = Array.new
19
+ currencies_response["#{plural_name}"].each do |currency|
20
+ currency_date = currency['Fecha'].to_s.split('-')
21
+ date = Date.new(currency_date[0].to_i, currency_date[1].to_i, currency_date[2].to_i)
22
+ currencies << Currency.new(date, currency['Valor'].gsub('.', '').gsub(',', '.').to_f)
23
+ end
24
+ currencies
25
+ end
26
+
27
+ def get_by_year(year)
28
+ url = "#{URL}/#{name}/#{year.to_s}?apikey=#{api_key}&formato=json"
29
+ uri = URI(url)
30
+ response = Net::HTTP.get uri
31
+ currencies_response = JSON.parse response
32
+ currencies = Array.new
33
+ currencies_response["#{plural_name}"].each do |currency|
34
+ currency_date = currency['Fecha'].to_s.split('-')
35
+ date = Date.new(currency_date[0].to_i, currency_date[1].to_i, currency_date[2].to_i)
36
+ currencies << Currency.new(date, currency['Valor'].gsub('.', '').gsub(',', '.').to_f)
37
+ end
38
+ currencies
39
+ end
40
+
41
+ module GetByDayMethods
42
+ def get_current
43
+ today = Date.today
44
+ get_by_day(today.year, today.month, today.day)
45
+ end
46
+
47
+ def get_by_day(year, month, day)
48
+ date = Date.new(year, month, day)
49
+ currencies_response = Array.new
50
+ # looking for business day
51
+ loop do
52
+ url = "#{URL}/#{name}/#{date.year.to_s}/#{date.month.to_s}/dias/#{date.day}?apikey=#{api_key}&formato=json"
53
+ uri = URI(url)
54
+ response = Net::HTTP.get uri
55
+ currencies_response = JSON.parse response
56
+ break if currencies_response["#{plural_name}"]
57
+ date -= 1
58
+ end
59
+ Currency.new(date, currencies_response["#{plural_name}"][0]['Valor'].gsub('.', '').gsub(',', '.').to_f)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,17 @@
1
+ require 'active_support/configurable'
2
+
3
+ module SbifRails
4
+ def self.configure
5
+ yield @config ||= SbifRails::Configuration.new
6
+ end
7
+
8
+ def self.config
9
+ @config ||= SbifRails::Configuration.new
10
+ end
11
+
12
+ class Configuration
13
+ include ActiveSupport::Configurable
14
+
15
+ config_accessor(:api_key) { '' }
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module SbifRails
2
+ class Currency
3
+ attr_accessor :date, :value
4
+
5
+ def initialize(date, value)
6
+ @date = date
7
+ @value = value
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module SbifRails
2
+ module Dollar
3
+ extend SbifRails::Base
4
+ extend SbifRails::Base::GetByDayMethods
5
+
6
+ def self.name
7
+ "dolar"
8
+ end
9
+
10
+ def self.plural_name
11
+ "Dolares"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module SbifRails
2
+ module Euro
3
+ extend SbifRails::Base
4
+ extend SbifRails::Base::GetByDayMethods
5
+
6
+ def self.name
7
+ "euro"
8
+ end
9
+
10
+ def self.plural_name
11
+ "Euros"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module SbifRails
2
+ module Ipc
3
+ extend SbifRails::Base
4
+
5
+ def self.name
6
+ "ipc"
7
+ end
8
+
9
+ def self.plural_name
10
+ "IPCs"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module SbifRails
2
+ module Uf
3
+ extend SbifRails::Base
4
+ extend SbifRails::Base::GetByDayMethods
5
+
6
+ def self.name
7
+ "uf"
8
+ end
9
+
10
+ def self.plural_name
11
+ "UFs"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module SbifRails
2
+ module Utm
3
+ extend SbifRails::Base
4
+
5
+ def self.name
6
+ "utm"
7
+ end
8
+
9
+ def self.plural_name
10
+ "UTMs"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module SbifRails
2
+ VERSION = "1.0.4"
3
+ end
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ </component>
9
+ </module>
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sbif-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sbif-rails"
8
+ spec.version = SbifRails::VERSION
9
+ spec.authors = ["Paulo Tarud"]
10
+ spec.email = ["paulo@divisafe.com"]
11
+ spec.summary = %q{API Client for Chile SBIF}
12
+ spec.description = %q{API Client for Chile SBIF}
13
+ spec.homepage = "https://github.com/RiseTechnologySpA/sbif-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/RiseTechnologySpA/sbif-rails"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sbif-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Paulo Tarud
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: API Client for Chile SBIF
42
+ email:
43
+ - paulo@divisafe.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/generators/sbif/config_generator.rb
54
+ - lib/generators/sbif/templates/sbif_api_key_config.rb
55
+ - lib/sbif-rails.rb
56
+ - lib/sbif-rails/base.rb
57
+ - lib/sbif-rails/config.rb
58
+ - lib/sbif-rails/currency.rb
59
+ - lib/sbif-rails/dollar.rb
60
+ - lib/sbif-rails/euro.rb
61
+ - lib/sbif-rails/ipc.rb
62
+ - lib/sbif-rails/uf.rb
63
+ - lib/sbif-rails/utm.rb
64
+ - lib/sbif-rails/version.rb
65
+ - sbif-rails-bkp.iml
66
+ - sbif-rails.gemspec
67
+ homepage: https://github.com/RiseTechnologySpA/sbif-rails
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ homepage_uri: https://github.com/RiseTechnologySpA/sbif-rails
72
+ source_code_uri: https://github.com/RiseTechnologySpA/sbif-rails
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.1.4
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: API Client for Chile SBIF
92
+ test_files: []