brazilian_financial_indexes 0.0.1 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4e53d68b92eee07da54f805ab60a5f59362ca70
4
- data.tar.gz: 8903213a5184d4e405f701f82235e02dcf3ff7b1
3
+ metadata.gz: 1e8633d0ad5f9923f232d7c3ac6b273524c26518
4
+ data.tar.gz: 44645337734fe36296cea66717274eef1c487674
5
5
  SHA512:
6
- metadata.gz: b3942a4246278ed0bc023947e78d0a8d1844fa068e31281b001b34ef2f929ebb1df2c4879b82aef1388d5e6abebc75175b915e70187d59ace172b776e873e5e8
7
- data.tar.gz: 77fe69803427d5c5cea293c7eaa67aac2e31ad7dceca15f70b6100d9843d7020d0a80820a9e9aaa7e6e98fafb82ab0d0e1fc85337d8b1f3f21080f0dc8e54829
6
+ metadata.gz: b163a6bfb6a1c965f887d98b36030019ffcd13e06e0eab23cb34960af2fd3cffa6cd16794442618be04e28a61dcb966ed07fa86747e44b7086daa118e3ce6659
7
+ data.tar.gz: 5d5e3644635ccaab4a43f68d0a45c483e4a452a0b26d81f460020372f6628dcb7f03269e6ab39d01dc482a545ea8eacfd5f06034b6e83c0360fd3c2dd98eecff
@@ -1,5 +1,10 @@
1
1
  require "bigdecimal"
2
2
  require "ostruct"
3
3
  require "pry"
4
+ require "yaml"
5
+ require "json"
6
+ require "net/http"
4
7
 
8
+ require "brazilian_financial_indexes/input"
9
+ require "brazilian_financial_indexes/api"
5
10
  require "brazilian_financial_indexes/application"
@@ -0,0 +1,20 @@
1
+ module BrazilianFinancialIndexes
2
+ class API
3
+ def initialize(config)
4
+ @config = config
5
+ uri = URI("#{config["url"]}/login")
6
+ response = Net::HTTP.post_form(uri,
7
+ "email" => config["login"],
8
+ "password" => config["password"])
9
+ attrs = JSON.parse(response.body)
10
+ @auth_token = attrs["auth_token"]
11
+ end
12
+
13
+ def post(collection)
14
+ uri = URI("#{@config["url"]}/#{@config["post_path"]}")
15
+ response = Net::HTTP.post_form(
16
+ uri, auth_token: @auth_token, values: collection.to_json)
17
+ JSON.parse(response.body)
18
+ end
19
+ end
20
+ end
@@ -4,32 +4,11 @@ module BrazilianFinancialIndexes
4
4
 
5
5
  class Application
6
6
  def self.run
7
- create_file
8
- parse_file
9
- end
10
-
11
- private
12
- def self.create_file
13
- prefix = RUBY_PLATFORM.match(/linux/) ? "wine" : ""
14
- File.delete(OUTPUT) if File.exists?(OUTPUT)
15
- system("#{prefix} #{INDEX_DOWNLOADER_BIN}")
16
- end
17
-
18
- def self.parse_file
19
- lines = File.readlines(OUTPUT).map do |line|
20
- date = Date.parse(line[11..18])
21
- value = parse_value(line)
22
- OpenStruct.new(
23
- id: line[0..5], complement: line[6..8], type: line[9..10],
24
- date: date, group: line[19..20], code: line[21..45].strip,
25
- value: value)
26
- end.compact
27
- end
28
-
29
- def self.parse_value(line)
30
- value = BigDecimal.new(line[46..70])
31
- precision = line[71..72].to_i
32
- parsed_value = (value / (10 ** precision)).to_f
7
+ config = YAML.load_file("config.yml")
8
+ Input.create_file
9
+ values = Input.parse_file
10
+ api = API.new(config["brazilian_financial_indexes"])
11
+ api.post(values)
33
12
  end
34
13
  end
35
14
  end
@@ -0,0 +1,27 @@
1
+ module BrazilianFinancialIndexes
2
+ class Input
3
+ INDEX_DOWNLOADER_BIN = Pathname("bin/Download_Indices.exe").to_s
4
+ OUTPUT = "Indic.txt"
5
+
6
+ def self.create_file
7
+ prefix = RUBY_PLATFORM.match(/linux/) ? "wine" : ""
8
+ File.delete(OUTPUT) if File.exists?(OUTPUT)
9
+ system("#{prefix} #{INDEX_DOWNLOADER_BIN}")
10
+ end
11
+
12
+ def self.parse_file
13
+ lines = File.readlines(OUTPUT).map do |line|
14
+ date = Date.parse(line[11..18])
15
+ value = parse_value(line)
16
+ { date: date, importing_code: line[19..45].strip, value: value }
17
+ end.compact
18
+ end
19
+
20
+ private
21
+ def self.parse_value(line)
22
+ value = BigDecimal.new(line[46..70])
23
+ precision = line[71..72].to_i
24
+ parsed_value = (value / (10 ** precision)).to_f
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module BrazilianFinancialIndexes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brazilian_financial_indexes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adriano Bacha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-10 00:00:00.000000000 Z
11
+ date: 2014-09-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parses financial indicators from BMFBovespa
14
14
  email:
@@ -23,7 +23,9 @@ files:
23
23
  - bin/Indica.exe
24
24
  - bin/brazilian_financial_indexes
25
25
  - lib/brazilian_financial_indexes.rb
26
+ - lib/brazilian_financial_indexes/api.rb
26
27
  - lib/brazilian_financial_indexes/application.rb
28
+ - lib/brazilian_financial_indexes/input.rb
27
29
  - lib/brazilian_financial_indexes/version.rb
28
30
  homepage: http://github.com/simplific/brazilian_financial_indexes
29
31
  licenses: []