dolar-bna 1.0.5 → 1.0.8

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: fa4f36b6b0ffe105487c7fe8f37383fca3ab0f8ff052673d7585617f33d84aca
4
- data.tar.gz: e164fe66fcaa11cd706951dd5285dfb05e296b31a972f91e37b048a696c618c3
3
+ metadata.gz: 3108e2c21aa48d68b93712bea13b69e2cf1cc4d31bc33632cbb172713f4f4d23
4
+ data.tar.gz: 0e22b4646b52d28a067c6748240c27325ec0c5035fcf252f15f3f4ca5617c395
5
5
  SHA512:
6
- metadata.gz: ed3dc0e601b29285560fe6015a57dc49ba42b32286f7b5fc395c8561d945a72492067e3b04a8c0ac9aba060df0ce2989be966d733f3d0a8ca76ab50696a38648
7
- data.tar.gz: bbe33bb268d58065603daeae9baaad9b864d46a6028e05fca14f3fdc805cd4b19b1020d9ea731799efd78b7c81bf5da9b209187bd3c22c09c8d0c7ff003da185
6
+ metadata.gz: dda16f2ff47129ea8a519dc056dbbf4713aa63c0431985e2dcba9cf290a6d8a0478291ca5d1cdfe6f8ba2d28c4cc2000f8eae9c9d6a31fc4095df2542e5e1d41
7
+ data.tar.gz: 1aa79fb3641655306efaaab1c0ea3cd9cfce63f779b8e94c839d29c64427a48d4341e83b2679e7186d6c26ab65e51de910534493967bd2e5a5a72829bfaa83d4
@@ -6,6 +6,8 @@ module Dolar
6
6
  validates_presence_of :dolar_type, message: 'Indicar tipo de cotizacion'
7
7
  validates_presence_of :dolar_buy, message: 'Indicar cotizacion de compra'
8
8
  validates_presence_of :dolar_sell, message: 'Indicar cotizacion de venta'
9
+ validates_numericality_of :dolar_buy, greater_than: 0, message: 'La cotizacion debe ser mayor a 0'
10
+ validates_numericality_of :dolar_sell, greater_than: 0, message: 'La cotizacion debe ser mayor a 0'
9
11
  validates_uniqueness_of :date, scope: :dolar_type, message: 'Ya existe una cotización de ese tipo para la fecha ingresada'
10
12
  DOLAR_TYPES = ["Divisa", "Billete"]
11
13
 
@@ -7,26 +7,47 @@ module Dolar
7
7
  end
8
8
 
9
9
  def perform_bna_billete
10
- data = check_cotization("Billete", @fecha)
11
- save_in_db(data, "Billete") unless data.blank?
12
- return data
10
+ begin
11
+ Timeout.timeout(15) do
12
+ data = check_cotization("Billete", @fecha)
13
+ save_in_db(data, "Billete") unless data.blank?
14
+ return data
15
+ end
16
+ rescue => ex
17
+ pp ex.message
18
+ return nil
19
+ end
13
20
  end
14
21
 
15
22
  def perform_bna_divisa
16
- data = check_cotization("Divisa", @fecha)
17
- save_in_db(data, "Divisa") unless data.blank?
18
- return data
23
+ begin
24
+ Timeout.timeout(15) do
25
+ data = check_cotization("Divisa", @fecha)
26
+ save_in_db(data, "Divisa") unless data.blank?
27
+ return data
28
+ end
29
+ rescue => ex
30
+ pp ex.message
31
+ return nil
32
+ end
19
33
  end
20
34
 
21
35
  def variation_billete
22
- today_dolar = check_cotization("Billete", @fecha)
23
- yesterday_dolar = check_cotization("Divisa", (@fecha - 1.days))
24
- unless (today_dolar.nil? || yesterday_dolar.nil?)
25
- porcentual_variation = (today_dolar[:venta] - yesterday_dolar[:venta]) / (yesterday_dolar[:venta])
26
- porcentual_variation = "#{porcentual_variation * 100}%"
27
- return porcentual_variation
28
- else
29
- return "0%"
36
+ begin
37
+ Timeout.timeout(15) do
38
+ today_dolar = check_cotization("Billete", @fecha)
39
+ yesterday_dolar = check_cotization("Billete", (@fecha - 1.days))
40
+ unless (today_dolar.nil? || yesterday_dolar.nil?)
41
+ porcentual_variation = ((today_dolar[:venta] - yesterday_dolar[:venta]) / (yesterday_dolar[:venta]))
42
+ porcentual_variation = "#{(porcentual_variation * 100).round(2)}%"
43
+ return porcentual_variation
44
+ else
45
+ return "0%"
46
+ end
47
+ end
48
+ rescue => ex
49
+ pp ex.message
50
+ return nil
30
51
  end
31
52
  end
32
53
 
@@ -53,7 +74,7 @@ module Dolar
53
74
  mechanize = Mechanize.new
54
75
  mechanize.user_agent_alias = "Android"
55
76
  begin
56
- Timeout.timeout(20) do
77
+ Timeout.timeout(15) do
57
78
  url = "http://www.bna.com.ar/Cotizador/HistoricoPrincipales?id=billetes&fecha=#{@fecha.day}%2F#{@fecha.month}%2F#{@fecha.year}&filtroEuro=0&filtroDolar=1"
58
79
  value = obtain_dolar_from_html(url, mechanize, data)
59
80
  return value
@@ -70,7 +91,7 @@ module Dolar
70
91
  mechanize = Mechanize.new
71
92
  mechanize.user_agent_alias = "Android"
72
93
  begin
73
- Timeout.timeout(20) do
94
+ Timeout.timeout(15) do
74
95
  url = "http://www.bna.com.ar/Cotizador/MonedasHistorico"
75
96
  value = obtain_dolar_from_html(url, mechanize, data)
76
97
  return value
@@ -1,5 +1,5 @@
1
1
  module Dolar
2
2
  module Bna
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.8"
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.5
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - LITECODE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-16 00:00:00.000000000 Z
11
+ date: 2019-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot
@@ -92,8 +92,9 @@ dependencies:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
94
  version: '3.0'
95
- description: 'Gema para obtener cotización de dolar divisa y dolar billete desde el
96
- sitio web del Banco Nación de Argentina '
95
+ description: Gema para obtener cotización de dolar divisa y dolar billete, obtener
96
+ variaciones respecto al día anterior y realizar conversiones. Valores obtenidos
97
+ del sitio web del Banco Nación Argentina
97
98
  email:
98
99
  - lorenzoezequiel30@gmail.com
99
100
  executables: []
@@ -108,12 +109,12 @@ files:
108
109
  - lib/dolar/bna/version.rb
109
110
  - lib/generators/dolar/bna/install/install_generator.rb
110
111
  - lib/generators/dolar/bna/install/templates/create_dolar_cotizations.rb
111
- homepage: http://litecode.com.ar/
112
+ homepage: https://github.com/elorenzo368/dolar-bna
112
113
  licenses:
113
114
  - MIT
114
115
  metadata:
115
116
  allowed_push_host: https://rubygems.org
116
- homepage_uri: http://litecode.com.ar/
117
+ homepage_uri: https://github.com/elorenzo368/dolar-bna
117
118
  post_install_message:
118
119
  rdoc_options: []
119
120
  require_paths: