basic_yahoo_finance 0.2.0 → 0.3.1

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: 814a795de1eab60580b58d3e297d75495cd1b2b253e0282d031be4415304717b
4
- data.tar.gz: 3b6262e836778a3400063c03789258506a4d298f54a81bd7c45234b6a430f397
3
+ metadata.gz: ac312bb23f04ce23b3bdf59b54edd1a089176e8da0e9eeb5a70279f78ffefbd9
4
+ data.tar.gz: 7922787606b7eebf744419dfbdc6f014c2cecb5b9d94909b3e2741a0f58b0970
5
5
  SHA512:
6
- metadata.gz: 0c51ebf8d46280e517e6525a66be84ef83a8378defcff07de647a1e3dc6fbfd188dbf95412eac2a731bd3273f8aa92482a30ea366e6f20d2fd70fb73f57a1010
7
- data.tar.gz: e69d09f901a017af01221054cf2cfa5f374bf2c4d2b35b6232995778b75bafe87c81fe566547e7a40ec1c7b149bb5007c8b8456191b57133c5cb6b3f37d1ea33
6
+ metadata.gz: 9db7de6026fce85ca08de9f9ddfdebc8022deb1f10141df12181c857196532b8b83c68523edc97e729048cc1c601743b29addf1fd2238a8ea9f6c4299aa31733
7
+ data.tar.gz: 2dc8dc4c07184cf22de1678d1edbe08aa4b7b6214ed092f1e5504180f1a4f467e33567f17e9673efd89f35586ab21b584978b91c53c92e88ae5fe54fe153130d
data/CHANGELOG.md CHANGED
@@ -5,14 +5,36 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## 0.2.0 - 2021-02-05
8
+ ## [0.3.1] - 2023-02-12
9
+
10
+ ### Changed
11
+
12
+ - Comment out not yet implemented use of redis dependency by [@svoop](https://github.com/svoop)
13
+ - Update gem dependencies and Ruby version
14
+
15
+ ## [0.3.0] - 2022-05-06
16
+
17
+ ### Added
18
+
19
+ - Initial setup for redis caching
20
+ - Utility class with symbols generator used in currency queries
21
+ - Foreign exchange symbol generator and finder
22
+ - Rubygems MFA requirement
23
+
24
+ ### Changed
25
+
26
+ - Fix format of returned symbol for FX symbol finder
27
+ - Update gems
28
+ - Parse URI before opening request to API
29
+
30
+ ## [0.2.0] - 2021-02-05
9
31
 
10
32
  ### Changed
11
33
 
12
34
  - User-Agent header in API requests to announce as "BYF" instead of default "Ruby"
13
35
  - Invalid ticker test to new behaviour of the API when the ticker does not exist
14
36
 
15
- ## 0.1.0 - 2021-01-29
37
+ ## [0.1.0] - 2021-01-29
16
38
 
17
39
  ### Added
18
40
 
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "redis"
4
+
5
+ module BasicYahooFinance
6
+ class Cache
7
+ # TODO: implement later
8
+ end
9
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BasicYahooFinance
4
+ # Small useful utility methods
5
+ class Util
6
+ # Find correct FX symbol in quotes as the symbol format can vary
7
+ def self.find_fx_symbol(quotes, currency1, currency2)
8
+ # Exception for USDCHF=X symbol as it is sometimes returned as CHF=X
9
+ if currency1 == "USD" && currency2 == "CHF"
10
+ quotes["USDCHF=X"].nil? ? "CHF=X" : "#{currency1}CHF=X"
11
+ else
12
+ "#{currency1}#{currency2}=X"
13
+ end
14
+ end
15
+
16
+ # Generate currency symbols based on array of currencies and base currency
17
+ def self.generate_currency_symbols(currencies, base_currency)
18
+ currency_symbols = []
19
+ currencies.each do |currency|
20
+ next if currency == base_currency
21
+
22
+ currency_symbols.push("#{currency}#{base_currency}=X")
23
+ end
24
+ currency_symbols.join(",")
25
+ end
26
+
27
+ # Generate symobol for foreign exchange rate lookup
28
+ def self.generate_fx_symbol(currency1, currency2)
29
+ # Exception for USD against CHF which is formatted as 'CHF=X'
30
+ if currency1 == "USD" && currency2 == "CHF"
31
+ "#{currency2}=X"
32
+ else
33
+ "#{currency1}/#{currency2}"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BasicYahooFinance
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "json"
4
4
  require "open-uri"
5
+ # require_relative "basic_yahoo_finance/cache"
6
+ require_relative "basic_yahoo_finance/util"
5
7
  require_relative "basic_yahoo_finance/version"
6
8
 
7
9
  module BasicYahooFinance
@@ -9,11 +11,15 @@ module BasicYahooFinance
9
11
  class Query
10
12
  API_URL = "https://query1.finance.yahoo.com"
11
13
 
14
+ def initialize(cache_url = nil)
15
+ @cache_url = cache_url
16
+ end
17
+
12
18
  def quotes(symbols)
13
19
  symbols_value = generate_symbols_value(symbols)
14
20
  begin
15
- uri = URI.open("#{API_URL}/v7/finance/quote?symbols=#{symbols_value}",
16
- "User-Agent" => "BYF/#{BasicYahooFinance::VERSION}")
21
+ url = URI.parse("#{API_URL}/v7/finance/quote?symbols=#{symbols_value}")
22
+ uri = URI.open(url, "User-Agent" => "BYF/#{BasicYahooFinance::VERSION}")
17
23
  process_output(JSON.parse(uri.read))
18
24
  rescue OpenURI::HTTPError
19
25
  empty_symbols_hash(symbols)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basic_yahoo_finance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2023-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest-emoji
@@ -35,6 +35,8 @@ files:
35
35
  - LICENSE
36
36
  - README.md
37
37
  - lib/basic_yahoo_finance.rb
38
+ - lib/basic_yahoo_finance/cache.rb
39
+ - lib/basic_yahoo_finance/util.rb
38
40
  - lib/basic_yahoo_finance/version.rb
39
41
  homepage: https://towards.ch
40
42
  licenses:
@@ -45,8 +47,9 @@ metadata:
45
47
  changelog_uri: https://github.com/towards/basic_yahoo_finance/blob/master/CHANGELOG.md
46
48
  documentation_uri: https://www.rubydoc.info/gems/basic_yahoo_finance
47
49
  homepage_uri: https://towards.ch
50
+ rubygems_mfa_required: 'true'
48
51
  source_code_uri: https://github.com/towards/basic_yahoo_finance
49
- post_install_message:
52
+ post_install_message:
50
53
  rdoc_options: []
51
54
  require_paths:
52
55
  - lib
@@ -54,15 +57,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
57
  requirements:
55
58
  - - ">="
56
59
  - !ruby/object:Gem::Version
57
- version: 2.5.0
60
+ version: 2.7.0
58
61
  required_rubygems_version: !ruby/object:Gem::Requirement
59
62
  requirements:
60
63
  - - ">="
61
64
  - !ruby/object:Gem::Version
62
65
  version: '0'
63
66
  requirements: []
64
- rubygems_version: 3.2.3
65
- signing_key:
67
+ rubygems_version: 3.4.6
68
+ signing_key:
66
69
  specification_version: 4
67
70
  summary: Basic Yahoo Finance API to query stock prices
68
71
  test_files: []