currency_quote 0.1.8 → 0.2.3
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 +11 -1
- data/currency_quote.gemspec +3 -1
- data/lib/currency_quote.rb +2 -0
- data/lib/currency_quote/currency.rb +17 -14
- data/lib/currency_quote/dolar.rb +14 -6
- data/lib/currency_quote/invertir_online.rb +46 -0
- data/lib/currency_quote/version.rb +1 -1
- metadata +33 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bf88a3fc8a7d35ce9f4cba45330f8e59c9bf2efbb731adc1e0570367ef7bbaa
|
4
|
+
data.tar.gz: ade76e76c90775f8c7f6b58f9d6eb79aea43ca451f7b3522813d8f73222c1113
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e231b50836f599f20f107c63108dd142b52a8cfe2092f0563401515d2a1dc377b4fc457d6f7d43186e80b9d8f502599bba0b2f07e94ec4910547627def5d97
|
7
|
+
data.tar.gz: 47446653b727e1ff5b78c3136e5f13f486c005edfbf4fff36fb88b0e66ec50c3f9561c7418e8bae832640a20713ca805425030c38b4fbfe2d8af04e435339c54
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
currency_quote (0.1
|
4
|
+
currency_quote (0.2.1)
|
5
|
+
addressable
|
6
|
+
nokogiri
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: https://rubygems.org/
|
@@ -9,7 +11,14 @@ GEM
|
|
9
11
|
addressable (2.7.0)
|
10
12
|
public_suffix (>= 2.0.2, < 5.0)
|
11
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)
|
12
20
|
mini_portile2 (2.4.0)
|
21
|
+
multi_xml (0.6.0)
|
13
22
|
nokogiri (1.10.10)
|
14
23
|
mini_portile2 (~> 2.4.0)
|
15
24
|
public_suffix (4.0.6)
|
@@ -34,6 +43,7 @@ PLATFORMS
|
|
34
43
|
DEPENDENCIES
|
35
44
|
addressable (~> 2.7)
|
36
45
|
currency_quote!
|
46
|
+
httparty (~> 0.18.1)
|
37
47
|
nokogiri (~> 1.10)
|
38
48
|
rake (~> 12.0)
|
39
49
|
rspec (~> 3.0)
|
data/currency_quote.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
#spec.description = %q{TODO: Write a longer description or delete this line.}
|
11
11
|
spec.homepage = "https://www.sesocio.com"
|
12
12
|
spec.license = "MIT"
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
14
14
|
|
15
15
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
16
|
|
@@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.bindir = "exe"
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
|
+
spec.add_dependency 'nokogiri'
|
30
|
+
spec.add_dependency 'addressable'
|
29
31
|
end
|
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
|
|
@@ -15,11 +15,13 @@ class CurrencyQuote::Currency
|
|
15
15
|
|
16
16
|
def get_quotation
|
17
17
|
if currency == "Dolar Estadounidense"
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
begin
|
19
|
+
get_dolar_quotation
|
20
|
+
make_get_to_bcra
|
21
|
+
get_currency_quotation
|
22
|
+
rescue Timeout::Error => e
|
23
|
+
@sell = @buy = @quote = 0
|
24
|
+
end
|
23
25
|
return struct
|
24
26
|
end
|
25
27
|
end
|
@@ -32,24 +34,25 @@ class CurrencyQuote::Currency
|
|
32
34
|
|
33
35
|
def make_get_to_bcra
|
34
36
|
url = "#{BASE_URL}?date2=#{date}"
|
35
|
-
@doc = Nokogiri::HTML(
|
37
|
+
@doc = Nokogiri::HTML( open(url) )
|
36
38
|
end
|
37
39
|
|
38
40
|
def get_currency_quotation
|
39
41
|
data = @doc.css("td").map(&:text).collect(&:strip!)
|
40
42
|
index = data.index(currency)
|
41
43
|
if index
|
42
|
-
|
43
|
-
quote =
|
44
|
-
|
45
|
-
@
|
44
|
+
pass = data[index + 1].gsub(",", ".").to_f
|
45
|
+
@quote = data[index + 2].gsub(",", ".").to_f
|
46
|
+
pass = 1.0 if pass == 0
|
47
|
+
@sell = (dolar.sell * pass).to_f
|
48
|
+
@buy = (dolar.buy * pass).to_f
|
46
49
|
else
|
47
|
-
@sell = @buy = 0
|
50
|
+
@sell = @buy = @quote = 0
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
51
54
|
def struct
|
52
|
-
s = Struct.new(:currency, :date, :sell, :buy)
|
53
|
-
s.new(currency, date, sell, buy)
|
55
|
+
s = Struct.new(:currency, :date, :sell, :buy, :quote)
|
56
|
+
s.new(currency, date, sell, buy, quote)
|
54
57
|
end
|
55
58
|
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
|
|
@@ -30,14 +34,18 @@ class CurrencyQuote::Dolar
|
|
30
34
|
}
|
31
35
|
url = "#{BASE_URL}?#{params.query}"
|
32
36
|
|
33
|
-
@doc = Nokogiri::HTML(
|
37
|
+
@doc = Nokogiri::HTML( open(url) )
|
34
38
|
end
|
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/#{currency.upcase}/Cotizacion"
|
16
|
+
HTTParty.get(url,
|
17
|
+
body: {
|
18
|
+
'mercado' => mercado,
|
19
|
+
'simbol' => currency.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,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: currency_quote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2020-12-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: addressable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description:
|
14
42
|
email:
|
15
43
|
- facundo.martinez@sesocio.com
|
@@ -33,6 +61,7 @@ files:
|
|
33
61
|
- lib/currency_quote.rb
|
34
62
|
- lib/currency_quote/currency.rb
|
35
63
|
- lib/currency_quote/dolar.rb
|
64
|
+
- lib/currency_quote/invertir_online.rb
|
36
65
|
- lib/currency_quote/version.rb
|
37
66
|
homepage: https://www.sesocio.com
|
38
67
|
licenses:
|
@@ -48,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
77
|
requirements:
|
49
78
|
- - ">="
|
50
79
|
- !ruby/object:Gem::Version
|
51
|
-
version: 2.
|
80
|
+
version: 2.4.0
|
52
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
82
|
requirements:
|
54
83
|
- - ">="
|