dolar-bna 1.0.9.3 → 1.1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e5232627e8bdd9df550ab809d28b55a862ee219297a7ceb856c90c9efe0249c
4
- data.tar.gz: eac449c68301e01658b7c92881b692541258861bf8d78486552c3175ae1e0eb8
3
+ metadata.gz: b25f6a330144c5665bc6d9913338b627606093ed20c0487779737c045e823341
4
+ data.tar.gz: 65cf5bd0fb7664df8e7cc7f582ec6031acd778d706d6a8f698e465e470af4561
5
5
  SHA512:
6
- metadata.gz: 65299b32995ba7ce7c094af50ed05de14a67005144ee4f0108dcdeccecc8a65b90a181cd29d11c1f1818302fab554ad1f11d225e24fbb202d97b3db0521f4467
7
- data.tar.gz: 99e2bb0a7456fc132582c3f30dfc0eb38d54bafa8253b7cdeb8d7bab94adbaa5f15a4b970e29f5f618141685f22fc633f7c2c8bd9da706f00eebf10dc62dd2b0
6
+ metadata.gz: eb0bb84594ad3677727615fbcb5b992b91921947c9f6e11bf1fc9c001671b8a125ec5b9d7b77fea0d7aee42054491c954eab4b2cf10d4660bf3c9ce1cb6dd562
7
+ data.tar.gz: 96f74f45abb454c713744c4adf130106818de3e24039447d060dab5f0d803c556b182b65db0ead235e4ed029f6b489efadfa7d7bc9dbaf122c028900cc219a40
@@ -2,6 +2,9 @@ module Dolar
2
2
  module Bna
3
3
  class Exchange
4
4
 
5
+ require 'openssl'
6
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
7
+
5
8
  def initialize(fecha=Date.today)
6
9
  @fecha ||= fecha
7
10
  end
@@ -54,7 +57,7 @@ module Dolar
54
57
  private
55
58
 
56
59
  def check_cotization dolar_type, date
57
- query = Dolar::Bna::DolarCotization.where(date: date, dolar_type: dolar_type).first
60
+ query = Dolar::Bna::DolarCotization.where(date: date.to_date, dolar_type: dolar_type).first
58
61
  ddolar = nil
59
62
  if query.nil?
60
63
  if dolar_type == "Divisa"
@@ -63,7 +66,7 @@ module Dolar
63
66
  ddolar = get_dolar()
64
67
  end
65
68
  else
66
- ddolar = {compra: query.dolar_buy, venta: query.dolar_sell, fecha: query.date}
69
+ ddolar = {compra: query.dolar_buy, venta: query.dolar_sell}
67
70
  end
68
71
  return ddolar
69
72
  end
@@ -75,7 +78,7 @@ module Dolar
75
78
  mechanize.user_agent_alias = "Android"
76
79
  begin
77
80
  Timeout.timeout(15) do
78
- url = "http://www.bna.com.ar/Cotizador/HistoricoPrincipales?id=billetes&fecha=#{@fecha.day}%2F#{@fecha.month}%2F#{@fecha.year}&filtroEuro=0&filtroDolar=1"
81
+ url = "https://www.bna.com.ar/Cotizador/HistoricoPrincipales?id=billetes&fecha=#{@fecha.day}%2F#{@fecha.month}%2F#{@fecha.year}&filtroEuro=0&filtroDolar=1"
79
82
  value = obtain_dolar_from_html(url, mechanize, data, "billete")
80
83
  return value
81
84
  end
@@ -92,7 +95,7 @@ module Dolar
92
95
  mechanize.user_agent_alias = "Android"
93
96
  begin
94
97
  Timeout.timeout(15) do
95
- url = "http://www.bna.com.ar/Cotizador/MonedasHistorico"
98
+ url = "https://www.bna.com.ar/Cotizador/MonedasHistorico"
96
99
  value = obtain_dolar_from_html(url, mechanize, data, "billete")
97
100
  return value
98
101
  end
@@ -103,36 +106,25 @@ module Dolar
103
106
  end
104
107
 
105
108
  def obtain_dolar_from_html(url, mechanize, data, d_type)
106
- dolar_fecha = nil
107
109
  page = mechanize.get(url)
108
110
  doc = Nokogiri::HTML(page.body, "UTF-8")
109
111
  doc.xpath("//td").each_with_index do |node, index|
110
112
  data[index] = node.text
111
113
  end
112
- if d_type == "divisa"
113
- divs_data = {}
114
- doc.xpath("//div").each_with_index do |node, index|
115
- divs_data[index] = node.text
116
- end
117
- dolar_fecha = divs_data[1]
118
- end
119
114
  correct_date = "#{@fecha.day.to_i}/#{@fecha.month.to_i}/#{@fecha.year.to_i}"
120
115
  i = data.key(correct_date)
121
116
  if !i.nil?
122
- dolar_fecha = data[i - 3]
123
117
  dolar_compra = BigDecimal(data[i - 2].tr(",", ".")).truncate(3).to_f
124
118
  dolar_venta = BigDecimal(data[i - 1].tr(",", ".")).truncate(3).to_f
125
119
  else
126
- dolar_fecha = dolar_fecha.nil? ? data[3] : dolar_fecha
127
120
  dolar_compra = BigDecimal(data[1].tr(",", ".")).truncate(3).to_f
128
121
  dolar_venta = BigDecimal(data[2].tr(",", ".")).truncate(3).to_f
129
122
  end
130
- return {compra: dolar_compra, venta: dolar_venta, fecha: dolar_fecha}
123
+ return {compra: dolar_compra, venta: dolar_venta}
131
124
  end
132
125
 
133
126
  def save_in_db data, dolar_type
134
- date = data[:fecha].nil? ? @fecha : data[:fecha].to_date
135
- dr = Dolar::Bna::DolarCotization.where(date: date, dolar_type: dolar_type, dolar_buy: data[:compra], dolar_sell: data[:venta]).first_or_initialize
127
+ dr = Dolar::Bna::DolarCotization.where(date: @fecha.to_date, dolar_type: dolar_type, dolar_buy: data[:compra], dolar_sell: data[:venta]).first_or_initialize
136
128
  if dr.save
137
129
  pp "todo ok"
138
130
  else
@@ -140,6 +132,11 @@ module Dolar
140
132
  end
141
133
  end
142
134
 
135
+ # def get_last_dolar dolar_type
136
+ # last_usd = Dolar::Bna::DolarCotization.where(dolar_type: dolar_type).last
137
+ # return last_usd
138
+ # end
139
+
143
140
  end
144
141
  end
145
142
  end
@@ -1,5 +1,5 @@
1
1
  module Dolar
2
2
  module Bna
3
- VERSION = "1.0.9.3"
3
+ VERSION = "1.1.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dolar-bna
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9.3
4
+ version: 1.1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LITECODE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-17 00:00:00.000000000 Z
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot
@@ -130,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  requirements: []
133
- rubyforge_project:
134
- rubygems_version: 2.7.8
133
+ rubygems_version: 3.0.3
135
134
  signing_key:
136
135
  specification_version: 4
137
136
  summary: Cotizador de USD/ARS