currency_quote 0.1.9 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc4814120128afe37b38292105c3440ea4c6e99238acf18308a95136df72bbd3
4
- data.tar.gz: 3360ae9c8b53711d3c0441c904819e70b851d6b5a351e43b04fa2d56c9ffd1b2
3
+ metadata.gz: e68345a1c2ec9e49d8a1f9f5e8406b4e4ebfa7f10eb1c968624c45ffff61fb66
4
+ data.tar.gz: e9c4b067a69e1761a9cc519ab38204eaacb6b62cc2a5e3336ed468d2e76278ed
5
5
  SHA512:
6
- metadata.gz: 1b0a41373d31330d6a7d3e78e3a275d2d9cddf94ad5fc3f01121d49e396bba314d0155f9029773b871ecf4e5a2910ba37def74a80433ec577c18a2f27c71a32c
7
- data.tar.gz: dfdd244d4c187b482b07b8d1d0d742a810b4d28216f700e092d9c5eca846e452979ccaa6a689f0b252175a6bccb655bb1edbfa3d203503c88d08cbe2cff36cc8
6
+ metadata.gz: 62e4ec0c632282736ae6d9c9f608a4430cc9331d68e05fd18fb8bf3dd487c594c10a9e12b687d0fba90550cadb944b9945e987472cdc7ce01d8694daee4b8baf
7
+ data.tar.gz: d16b1582a75cf18aa48d4703f13bd2b03be5d9c3a6b3917ada9163906c5039930ab77fe9016e3aa486315491627386a79b3b565984a8a805da004775769b3f7b
data/Gemfile CHANGED
@@ -9,3 +9,6 @@ gem "rspec", "~> 3.0"
9
9
  gem "nokogiri", "~> 1.10"
10
10
 
11
11
  gem "addressable", "~> 2.7"
12
+
13
+
14
+ gem "httparty", "~> 0.18.1"
@@ -1,7 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- currency_quote (0.1.8)
4
+ currency_quote (0.2.3)
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)
@@ -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.7.1")
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
 
@@ -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
- return get_dolar_quotation
19
- else
20
- get_dolar_quotation
21
- make_get_to_bcra
22
- get_currency_quotation
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( URI.open(url) )
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
- quote = data[index + 1].gsub(",", ".").to_f
43
- quote = 1.0 if quote == 0
44
- @sell = (dolar.sell * quote).to_f
45
- @buy = (dolar.buy * quote).to_f
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
@@ -13,8 +13,12 @@ class CurrencyQuote::Dolar
13
13
  end
14
14
 
15
15
  def get_quotation
16
- make_get_to_bna
17
- extract_data
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( URI.open(url) )
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
- @date = data[data.size - 1]
39
- @sell = data[data.size - 2].gsub(",", ".").to_f
40
- @buy = data[data.size - 3].gsub(",", ".").to_f
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
@@ -1,3 +1,3 @@
1
1
  module CurrencyQuote
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.4"
3
3
  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.1.9
4
+ version: 0.2.4
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-17 00:00:00.000000000 Z
11
+ date: 2020-12-01 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:
@@ -76,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
77
  requirements:
77
78
  - - ">="
78
79
  - !ruby/object:Gem::Version
79
- version: 2.7.1
80
+ version: 2.4.0
80
81
  required_rubygems_version: !ruby/object:Gem::Requirement
81
82
  requirements:
82
83
  - - ">="