currency_quote 0.2.0 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +9 -1
- data/lib/currency_quote.rb +2 -0
- data/lib/currency_quote/currency.rb +13 -12
- data/lib/currency_quote/dolar.rb +13 -5
- data/lib/currency_quote/invertir_online.rb +46 -0
- data/lib/currency_quote/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1faabc0feffe1d54943addd93fd452607884239c58081c11375e46de4ae3b11c
|
4
|
+
data.tar.gz: c628005d7f335e895128dd59c3c01b5ff0eed8cac5a8815af2176290684ca606
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85af2e02b7785d3ee83cd10c4fbb3d902947c2b39b3cd89fbe848b9988f682bcd430f9661fb8dd7724d00dd3d5f541d5b1792cdc60949958ce3332b2721a6354
|
7
|
+
data.tar.gz: 71cc8163e2aed87f4d5d8bd7bd1af1305db1ad1150f214fee2a5f09574855a39c373f223b8bea5d232a84ef4b1fb70618072bfcc7d6952e767890e00f2170517
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
currency_quote (0.
|
4
|
+
currency_quote (0.2.4)
|
5
5
|
addressable
|
6
6
|
nokogiri
|
7
7
|
|
@@ -11,7 +11,14 @@ GEM
|
|
11
11
|
addressable (2.7.0)
|
12
12
|
public_suffix (>= 2.0.2, < 5.0)
|
13
13
|
diff-lcs (1.4.4)
|
14
|
+
httparty (0.18.1)
|
15
|
+
mime-types (~> 3.0)
|
16
|
+
multi_xml (>= 0.5.2)
|
17
|
+
mime-types (3.3.1)
|
18
|
+
mime-types-data (~> 3.2015)
|
19
|
+
mime-types-data (3.2020.1104)
|
14
20
|
mini_portile2 (2.4.0)
|
21
|
+
multi_xml (0.6.0)
|
15
22
|
nokogiri (1.10.10)
|
16
23
|
mini_portile2 (~> 2.4.0)
|
17
24
|
public_suffix (4.0.6)
|
@@ -36,6 +43,7 @@ PLATFORMS
|
|
36
43
|
DEPENDENCIES
|
37
44
|
addressable (~> 2.7)
|
38
45
|
currency_quote!
|
46
|
+
httparty (~> 0.18.1)
|
39
47
|
nokogiri (~> 1.10)
|
40
48
|
rake (~> 12.0)
|
41
49
|
rspec (~> 3.0)
|
data/lib/currency_quote.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative "currency_quote/version"
|
2
2
|
require_relative "currency_quote/dolar"
|
3
3
|
require_relative "currency_quote/currency"
|
4
|
+
require_relative "currency_quote/invertir_online"
|
4
5
|
|
5
6
|
module CurrencyQuote
|
6
7
|
class Error < StandardError; end
|
@@ -11,6 +12,7 @@ module CurrencyQuote
|
|
11
12
|
|
12
13
|
autoload :Dolar, "currency_quote/dolar"
|
13
14
|
autoload :Currency, "currency_quote/currency"
|
15
|
+
autoload :InvertirOnline, "currency_quote/invertir_online"
|
14
16
|
|
15
17
|
CURRENCIES = [
|
16
18
|
"Bolívar Venezolano",
|
@@ -3,7 +3,7 @@ class CurrencyQuote::Currency
|
|
3
3
|
require 'nokogiri'
|
4
4
|
require 'date'
|
5
5
|
|
6
|
-
attr_accessor :currency, :date, :dolar, :doc, :sell, :buy
|
6
|
+
attr_accessor :currency, :date, :dolar, :doc, :sell, :buy, :quote
|
7
7
|
|
8
8
|
BASE_URL = "https://www.bcra.gob.ar/publicacionesestadisticas/Cotizaciones_por_fecha_2.asp"
|
9
9
|
|
@@ -14,14 +14,14 @@ class CurrencyQuote::Currency
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def get_quotation
|
17
|
-
|
18
|
-
return get_dolar_quotation
|
19
|
-
else
|
17
|
+
begin
|
20
18
|
get_dolar_quotation
|
21
19
|
make_get_to_bcra
|
22
20
|
get_currency_quotation
|
23
|
-
|
21
|
+
rescue Timeout::Error => e
|
22
|
+
@sell = @buy = @quote = 0
|
24
23
|
end
|
24
|
+
return struct
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
@@ -39,17 +39,18 @@ class CurrencyQuote::Currency
|
|
39
39
|
data = @doc.css("td").map(&:text).collect(&:strip!)
|
40
40
|
index = data.index(currency)
|
41
41
|
if index
|
42
|
-
|
43
|
-
quote =
|
44
|
-
|
45
|
-
@
|
42
|
+
pass = data[index + 1].gsub(",", ".").to_f
|
43
|
+
@quote = data[index + 2].gsub(",", ".").to_f
|
44
|
+
pass = 1.0 if pass == 0
|
45
|
+
@sell = (dolar.sell * pass).to_f
|
46
|
+
@buy = (dolar.buy * pass).to_f
|
46
47
|
else
|
47
|
-
@sell = @buy = 0
|
48
|
+
@sell = @buy = @quote = 0
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
52
|
def struct
|
52
|
-
s = Struct.new(:currency, :date, :sell, :buy)
|
53
|
-
s.new(currency, date, sell, buy)
|
53
|
+
s = Struct.new(:currency, :date, :sell, :buy, :quote)
|
54
|
+
s.new(currency, date, sell, buy, quote)
|
54
55
|
end
|
55
56
|
end
|
data/lib/currency_quote/dolar.rb
CHANGED
@@ -13,8 +13,12 @@ class CurrencyQuote::Dolar
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def get_quotation
|
16
|
-
|
17
|
-
|
16
|
+
begin
|
17
|
+
make_get_to_bna
|
18
|
+
extract_data
|
19
|
+
rescue Timeout::Error => e
|
20
|
+
@data = @sell = @buy = 0
|
21
|
+
end
|
18
22
|
return struct
|
19
23
|
end
|
20
24
|
|
@@ -35,9 +39,13 @@ class CurrencyQuote::Dolar
|
|
35
39
|
|
36
40
|
def extract_data
|
37
41
|
data = @doc.css("td").map(&:text)
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
if data.empty?
|
43
|
+
@data = @sell = @buy = 0
|
44
|
+
else
|
45
|
+
@date = data[data.size - 1]
|
46
|
+
@sell = data[data.size - 2].gsub(",", ".").to_f
|
47
|
+
@buy = data[data.size - 3].gsub(",", ".").to_f
|
48
|
+
end
|
41
49
|
end
|
42
50
|
|
43
51
|
def struct
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class CurrencyQuote::InvertirOnline
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
attr_accessor :username, :password, :access_token
|
5
|
+
|
6
|
+
BASE_URL = "https://api.invertironline.com"
|
7
|
+
|
8
|
+
def initialize(username:, password:)
|
9
|
+
@username = username
|
10
|
+
@password = password
|
11
|
+
get_token
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_quote(simbol:, mercado: 'bCBA', plazo: 't1')
|
15
|
+
url = BASE_URL + "/api/v2/#{mercado}/Titulos/#{simbol.upcase}/Cotizacion"
|
16
|
+
HTTParty.get(url,
|
17
|
+
body: {
|
18
|
+
'mercado' => mercado,
|
19
|
+
'simbol' => simbol.upcase,
|
20
|
+
'model.mercado' => mercado,
|
21
|
+
'model.plazo' => plazo
|
22
|
+
},
|
23
|
+
headers: {
|
24
|
+
'Authorization' => "Bearer #{@access_token}",
|
25
|
+
'Accept' => 'application/json'
|
26
|
+
}
|
27
|
+
).parsed_response
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def get_token
|
33
|
+
url = BASE_URL + "/token"
|
34
|
+
@access_token = HTTParty.post(url,
|
35
|
+
body: {
|
36
|
+
username: username,
|
37
|
+
password: password,
|
38
|
+
grant_type: 'password'
|
39
|
+
},
|
40
|
+
headers:{
|
41
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
42
|
+
'Accept' => 'application/json'
|
43
|
+
}
|
44
|
+
)['access_token']
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: currency_quote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Facundo A. Díaz Martínez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/currency_quote.rb
|
62
62
|
- lib/currency_quote/currency.rb
|
63
63
|
- lib/currency_quote/dolar.rb
|
64
|
+
- lib/currency_quote/invertir_online.rb
|
64
65
|
- lib/currency_quote/version.rb
|
65
66
|
homepage: https://www.sesocio.com
|
66
67
|
licenses:
|