stockcruncher 1.0.1 → 1.0.2

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: 82cc9e3595d2f91bded92cbbf001fc8fb76ff3bd0d4604361c24f78c3ef6da01
4
- data.tar.gz: 510435224f9e7362f51f692c3b6634d7372adae0db724d9d9545f3d869b53bfa
3
+ metadata.gz: c1fe544c0ab3e0bb05c2cca11cb4363bce698cf88b565d897098420b3b8206ac
4
+ data.tar.gz: bc0de76838cf286f9c5400ddc368da33ee2bd748f0a5a29ebed653010e183d8a
5
5
  SHA512:
6
- metadata.gz: 4a4e42a9068eabbbd9b5da44212d39c98aebce85c2b36add25f5da51853bbb00117cd9d6783d5f3cb2b35789eba7c917fe9020198de54e9bd9c45eff49221a0c
7
- data.tar.gz: 191d02a244a4fe2b575a7252824c2c510140072b56f1ea9791ddd62b94da5fda784046f246a812c4feb141e66196c711bfdfa71c951f0c8cac33409c4dacea31
6
+ metadata.gz: b69c6d91c2160e1e70a339ea68616b27012839b105dcfd0cef5ccf7a9643e3a08fb88738d794cf98e3d4de03e505c32db4a827d45a296d734f7e10d2334eb287
7
+ data.tar.gz: 44ecc54323e85117c04bb0aa8b9c2ab54421020a2614b01356988700f610264e1e82a07e88d5fd62f62945c1469c508699b3a78c2dad52a73b988e508ce2264d
@@ -10,9 +10,6 @@ module StockCruncher
10
10
 
11
11
  def start(args = ARGV)
12
12
  StockCruncher::CLI.start(args)
13
- rescue NotImplementedError => e
14
- warn e.message
15
- exit(3)
16
13
  end
17
14
  end
18
15
  end
@@ -7,32 +7,34 @@ module StockCruncher
7
7
  # This is an data cruncher class for AlphaVantage API.
8
8
  class AlphaVantage < Cruncher
9
9
  API_URL = 'https://www.alphavantage.co/query?'
10
- SERIE = {
11
- 'daily' => 'TIME_SERIES_DAILY',
12
- 'quote_endpoint' => 'GLOBAL_QUOTE'
13
- }.freeze
14
10
 
15
11
  # Main method to crunch data.
16
- def crunch(symbol, serie, opts)
17
- err_msg = "#{serie} does not exist."
18
- raise NotImplementedError, err_msg unless SERIE.key?(serie)
12
+ def crunch_daily(symbol, opts)
13
+ url = API_URL + parameters(symbol, 'TIME_SERIES_DAILY') + options_d(opts)
14
+ res = request(url)
15
+ puts res.body
16
+ end
19
17
 
20
- url = API_URL + parameters(symbol, serie) + options(serie, opts)
18
+ # Main method to crunch data.
19
+ def crunch_quote(symbol, opts)
20
+ url = API_URL + parameters(symbol, 'GLOBAL_QUOTE') + options_q(opts)
21
21
  res = request(url)
22
22
  puts res.body
23
23
  end
24
24
 
25
- def options(serie, opts)
25
+ def options_d(opts)
26
+ o = '&datatype=' + (opts['json'] ? 'json' : 'csv')
27
+ o += '&outputsize=' + (opts['full'] ? 'full' : 'compact')
28
+ o
29
+ end
30
+
31
+ def options_q(opts)
26
32
  o = '&datatype=' + (opts['json'] ? 'json' : 'csv')
27
- if serie == 'daily'
28
- o += '&outputsize='
29
- o += opts['full'] ? 'full' : 'compact'
30
- end
31
33
  o
32
34
  end
33
35
 
34
36
  def parameters(symbol, serie)
35
- p = 'function=' + SERIE[serie]
37
+ p = 'function=' + serie
36
38
  p += '&symbol=' + symbol
37
39
  p += '&apikey=' + @config[self.class.name.split('::').last]['apikey']
38
40
  p
@@ -11,9 +11,8 @@ module StockCruncher
11
11
  puts "StockCruncher version #{StockCruncher::VERSION}"
12
12
  end
13
13
 
14
- desc('crunch SYMBOL TIMESERIES [options]',
15
- 'Crunch SYMBOL stock market data for time series.' \
16
- 'Possible timeseries: daily, quote_endpoint.')
14
+ desc('daily SYMBOL [options]',
15
+ 'Crunch SYMBOL stock market data for daily time series.')
17
16
  option(
18
17
  :config,
19
18
  aliases: ['-c'],
@@ -36,10 +35,33 @@ module StockCruncher
36
35
  default: false,
37
36
  desc: 'Full data size.'
38
37
  )
39
- def crunch(symbol, timeserie)
38
+ def daily(symbol)
40
39
  opts = options.dup
41
40
  cruncher = StockCruncher::AlphaVantage.new(opts['config'])
42
- cruncher.crunch(symbol, timeserie, opts)
41
+ cruncher.crunch_daily(symbol, opts)
42
+ end
43
+
44
+ desc('quote SYMBOL [options]',
45
+ 'Crunch SYMBOL stock market data for last day quote.')
46
+ option(
47
+ :config,
48
+ aliases: ['-c'],
49
+ type: :string,
50
+ default: '/etc/stockcruncher/stockcruncher.yml',
51
+ desc: 'Yaml formatted config file to load ' \
52
+ '(default to /etc/stockcruncher/stockcruncher.yml).'
53
+ )
54
+ option(
55
+ :json,
56
+ aliases: ['-j'],
57
+ type: :boolean,
58
+ default: false,
59
+ desc: 'Json format data (default to csv).'
60
+ )
61
+ def quote(symbol)
62
+ opts = options.dup
63
+ cruncher = StockCruncher::AlphaVantage.new(opts['config'])
64
+ cruncher.crunch_quote(symbol, opts)
43
65
  end
44
66
  end
45
67
  end
@@ -7,7 +7,7 @@ require 'yaml'
7
7
  module StockCruncher
8
8
  # This is an data cruncher abstract class.
9
9
  class Cruncher
10
- # Class abstract constructor method
10
+ # Class constructor method
11
11
  def initialize(file)
12
12
  @config = load_conf(file)
13
13
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module StockCruncher
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.2'
6
6
  end
@@ -3,14 +3,14 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe StockCruncher::AlphaVantage do
6
- context 'crunch SYM daily -c spec/files/stockcruncher.yml' do
7
- it 'requests a source and get the result.' do
6
+ context 'daily SYM -c spec/files/stockcruncher.yml' do
7
+ it 'requests a daily time serie.' do
8
8
  expect { start(self) }.to output("{}\n").to_stdout
9
9
  end
10
10
  end
11
- context 'crunch SYM weekly -c spec/files/stockcruncher.yml' do
12
- it 'requests a not implemented time serie.' do
13
- expect { start(self) }.to raise_error(SystemExit)
11
+ context 'quote SYM -c spec/files/stockcruncher.yml' do
12
+ it 'requests a quote endpoint.' do
13
+ expect { start(self) }.to output("{}\n").to_stdout
14
14
  end
15
15
  end
16
16
  end
@@ -10,7 +10,13 @@ describe StockCruncher::CLI do
10
10
  end
11
11
  end
12
12
 
13
- context 'crunch SYM quote_endpoint -c spec/files/stockcruncher.yml' do
13
+ context 'daily SYM -c spec/files/stockcruncher.yml' do
14
+ it 'Get the daily time serie for SYM.' do
15
+ expect { start(self) }.to output("{}\n").to_stdout
16
+ end
17
+ end
18
+
19
+ context 'quote SYM -c spec/files/stockcruncher.yml' do
14
20
  it 'Get the quote for SYM.' do
15
21
  expect { start(self) }.to output("{}\n").to_stdout
16
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stockcruncher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Delaplace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-27 00:00:00.000000000 Z
11
+ date: 2020-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler