stockcruncher 1.1.0 → 1.1.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: 51887b6440cf8d3958f52c05d5daa9e77c0bada0e385445ec6bcb6553fe9c16d
4
- data.tar.gz: 66ade1c3623130c5e5588ceca005bddb201b176d1d81ffbb0cabd41568b1692c
3
+ metadata.gz: 1beb20ef59441b6227bd56d52cb1db85970c50be5cb909d3f631a97539897602
4
+ data.tar.gz: 96722ce534f031f40435958d4068a6212b0d4dd583840077423132d7b7349654
5
5
  SHA512:
6
- metadata.gz: 0bbdd83e653eadf37c57b6cf5e2bf3234c94ccf74d59ffcd21f995d74260a7673da8a79564f37b4b69715fb5f295d0e1bcf2465fee119a84965cbcc333d0f0bc
7
- data.tar.gz: 979223a1ee0cba78f9d482d22f3025c17fb0506c487d237b94b5855a7843ef3eca610fd89fcbd0a41c66325a1f9e86786e0b56703d666fbca8d5417dd3906321
6
+ metadata.gz: 45ff2b03c7d1233717dd60a4030d376a56ac5eb59d01c89dd6600b77b886cabc79a250686c013ed74463bd4c357a056b75684395bf3bb66b89d2b3c49aeb04f7
7
+ data.tar.gz: c7945f2f156aae5f7140165bbeda8794ea9b8f72b56bd810e110ce93ebe0ce21f80cab80b516bcd9c73c4dcbeca6d6bd023581b57a01deff682b922c56a4aa55
@@ -10,6 +10,9 @@ module StockCruncher
10
10
 
11
11
  def start(args = ARGV)
12
12
  StockCruncher::CLI.start(args)
13
+ rescue StandardError => e
14
+ warn e.message
15
+ exit 1
13
16
  end
14
17
  end
15
18
  end
@@ -60,8 +60,8 @@ module StockCruncher
60
60
  config = YAML.load_file(opts['config'])
61
61
  cruncher = StockCruncher::AlphaVantage.new(config, opts['insecure'])
62
62
  raw_data = cruncher.crunch_quote(symbol)
63
- puts raw_data unless opts['quiet']
64
63
  StockCruncher::InfluxDB.new(config).export_last_day(raw_data)
64
+ puts raw_data unless opts['quiet']
65
65
  end
66
66
  end
67
67
  end
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'date'
4
5
  require 'net/http'
5
6
 
6
7
  module StockCruncher
@@ -12,10 +13,16 @@ module StockCruncher
12
13
  @insecure = insecure
13
14
  end
14
15
 
16
+ # Method to create a new hash from two arrays of keys and values
17
+ def create_hash(descriptions, values)
18
+ descriptions.split(',').zip(values.split(',')).to_h
19
+ end
20
+
15
21
  # Method to export latest data to database
16
22
  def export_last_day(raw)
17
- (desc, line) = raw.split("\r\n")
18
- values = desc.split(',').zip(line.split(',')).to_h
23
+ raise StandardError, 'No data to export' if raw.match?(/{}/)
24
+
25
+ values = create_hash(*raw.split("\r\n"))
19
26
  values['close'] = values.delete('price')
20
27
  values['changePercent'] = values['changePercent'].delete('%')
21
28
  tags = { 'symbol' => values.delete('symbol') }
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module StockCruncher
5
- VERSION = '1.1.0'
5
+ VERSION = '1.1.1'
6
6
  end
@@ -6,7 +6,7 @@ quote = 'symbol,open,high,low,price,volume,latestDay,previousClose,change,ch' \
6
6
  "angePercent\r\nSYM,100.0000,100.1000,99.9000,100.0000,4,2020-07-30," \
7
7
  "100.0000,0.0000,0.0000%\r\n"
8
8
 
9
- describe StockCruncher::CLI do
9
+ describe StockCruncher::CLI do # rubocop:disable Metrics/BlockLength
10
10
  context 'version' do
11
11
  it 'prints the version.' do
12
12
  out = "StockCruncher version #{StockCruncher::VERSION}\n"
@@ -20,6 +20,12 @@ describe StockCruncher::CLI do
20
20
  end
21
21
  end
22
22
 
23
+ context 'quote NODATA -c spec/files/stockcruncher.yml' do
24
+ it 'Should not get any data and should fail.' do
25
+ expect { start(self) }.to raise_error(SystemExit)
26
+ end
27
+ end
28
+
23
29
  context 'quote SYM -c spec/files/stockcruncher.yml' do
24
30
  it 'Get the quote for SYM.' do
25
31
  expect { start(self) }.to output(quote).to_stdout
@@ -9,6 +9,9 @@ quote = 'symbol,open,high,low,price,volume,latestDay,previousClose,change,ch' \
9
9
  RSpec.configure do |config|
10
10
  config.before(:each) do
11
11
  # requests an API without extra arguments
12
+ stub_request(:get, 'https://www.alphavantage.co/query?' \
13
+ 'function=GLOBAL_QUOTE&symbol=NODATA&apikey=demo&datatype=csv')
14
+ .to_return('status' => 200, 'body' => '{}', 'headers' => {})
12
15
  stub_request(:get, 'https://www.alphavantage.co/query?' \
13
16
  'function=GLOBAL_QUOTE&symbol=SYM&apikey=demo&datatype=csv')
14
17
  .to_return('status' => 200, 'body' => quote, 'headers' => {})
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.1.0
4
+ version: 1.1.1
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-31 00:00:00.000000000 Z
11
+ date: 2020-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler