stock_quote_cli 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +16 -1
- data/README.md +10 -5
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/stock_quote_cli/cli.rb +17 -18
- data/lib/stock_quote_cli/history.rb +5 -7
- data/spec/stock_quote_cli_spec.rb +16 -1
- data/stock_quote_cli.gemspec +81 -0
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6562f8db3194028525dae8aaf90d8b5cdce0179
|
4
|
+
data.tar.gz: e157fcc6fdad3097511cf1944839b31896da5b16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55bc67f5b77c749ab1e8d9d9cf0084238f1d872cfc0b1ec29eeb0a9cb65ad299b0c99d245b3a3eb81782453d13de77c0901e0cf79059aabfe44fc585aeacc677
|
7
|
+
data.tar.gz: d467ae56c3d4dce9368327e84ea5328b484ecdb27a8d57c42938be0cca102a2b8e08d872d24d8c67a7cf209cf092d53a739d09ea10de728e7bb1769937c4e9a4
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
activesupport (4.0.0)
|
5
|
+
i18n (~> 0.6, >= 0.6.4)
|
6
|
+
minitest (~> 4.2)
|
7
|
+
multi_json (~> 1.3)
|
8
|
+
thread_safe (~> 0.1)
|
9
|
+
tzinfo (~> 0.3.37)
|
4
10
|
addressable (2.3.5)
|
11
|
+
atomic (1.1.14)
|
5
12
|
builder (3.2.2)
|
6
13
|
diff-lcs (1.1.3)
|
7
14
|
faraday (0.8.8)
|
@@ -18,6 +25,7 @@ GEM
|
|
18
25
|
highline (1.6.20)
|
19
26
|
hpricot (0.8.6)
|
20
27
|
httpauth (0.2.0)
|
28
|
+
i18n (0.6.5)
|
21
29
|
jeweler (1.8.8)
|
22
30
|
builder
|
23
31
|
bundler (~> 1.0)
|
@@ -31,6 +39,7 @@ GEM
|
|
31
39
|
jwt (0.1.8)
|
32
40
|
multi_json (>= 1.5)
|
33
41
|
mime-types (1.25)
|
42
|
+
minitest (4.7.5)
|
34
43
|
multi_json (1.8.2)
|
35
44
|
multi_xml (0.5.5)
|
36
45
|
multipart-post (1.2.0)
|
@@ -43,7 +52,7 @@ GEM
|
|
43
52
|
multi_xml (~> 0.5)
|
44
53
|
rack (~> 1.2)
|
45
54
|
rack (1.5.2)
|
46
|
-
rake (10.1.
|
55
|
+
rake (10.1.1)
|
47
56
|
rdoc (3.12.2)
|
48
57
|
json (~> 1.4)
|
49
58
|
rest-client (1.6.7)
|
@@ -56,10 +65,15 @@ GEM
|
|
56
65
|
rspec-expectations (2.8.0)
|
57
66
|
diff-lcs (~> 1.1.2)
|
58
67
|
rspec-mocks (2.8.0)
|
68
|
+
shoulda-matchers (2.3.0)
|
69
|
+
activesupport (>= 3.0.0)
|
59
70
|
stock_quote (1.0.3)
|
60
71
|
hpricot
|
61
72
|
rest-client
|
62
73
|
thor (0.18.1)
|
74
|
+
thread_safe (0.1.3)
|
75
|
+
atomic
|
76
|
+
tzinfo (0.3.37)
|
63
77
|
|
64
78
|
PLATFORMS
|
65
79
|
ruby
|
@@ -69,5 +83,6 @@ DEPENDENCIES
|
|
69
83
|
jeweler (~> 1.8.7)
|
70
84
|
rdoc (~> 3.12)
|
71
85
|
rspec (~> 2.8.0)
|
86
|
+
shoulda-matchers
|
72
87
|
stock_quote
|
73
88
|
thor
|
data/README.md
CHANGED
@@ -5,11 +5,16 @@ Stock Quote CLI
|
|
5
5
|
|
6
6
|
### Description
|
7
7
|
|
8
|
-
Stock Quote CLI is a Ruby gem that provides a command-line interface for fetching stock information from
|
8
|
+
Stock Quote CLI is a Ruby gem that provides a command-line interface for fetching stock information from Yahoo!. It relies on the [stock_quote gem](https://github.com/tyrauber/stock_quote) for fetching real-time and historical data.
|
9
|
+
|
10
|
+
Update: Due to Google's sunsetting of iGoogle (and the associated endpoint from
|
11
|
+
which the stock_quote gem once fetched its data), the stock_quote gem has moved
|
12
|
+
to using the Yahoo! Finance API. This CLI gem has been updated to accommodate
|
13
|
+
the awesomely quick changes.
|
9
14
|
|
10
15
|
### Installation
|
11
16
|
|
12
|
-
|
17
|
+
Build passes with `ruby-2.0.0-p247`. With Ruby installed, run the following:
|
13
18
|
|
14
19
|
gem install stock_quote_cli
|
15
20
|
|
@@ -29,7 +34,7 @@ Get the opening price for the specified stock(s) on the current day (or last tra
|
|
29
34
|
|
30
35
|
stock open znga
|
31
36
|
|
32
|
-
####
|
37
|
+
#### Previous Closing Price
|
33
38
|
|
34
39
|
Get the closing price for the specified stock(s) on the previous trading day.
|
35
40
|
|
@@ -49,7 +54,7 @@ Get the low price for the specified stock(s) on the current day (or last trading
|
|
49
54
|
|
50
55
|
#### Historical Data
|
51
56
|
|
52
|
-
Get historical data for a single stock. The default range is
|
57
|
+
Get historical data for a single stock. The default range is 14 days. The default value is the closing price. These can be specified using the `range` (aliased to `-r`) and `value` (aliased to `-v`) options, respectively.
|
53
58
|
|
54
59
|
stock history fb
|
55
60
|
|
@@ -71,7 +76,7 @@ Below, we fetch the high price for the Facebook stock for the past 15 days.
|
|
71
76
|
|
72
77
|
### License
|
73
78
|
|
74
|
-
Copyright (c)
|
79
|
+
Copyright (c) 2014 Travis Loncar
|
75
80
|
|
76
81
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
|
77
82
|
in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ Jeweler::Tasks.new do |gem|
|
|
23
23
|
gem.authors = ["Travis Loncar"]
|
24
24
|
# dependencies defined in Gemfile
|
25
25
|
gem.add_dependency "thor", "~> 0.18.1"
|
26
|
-
gem.add_dependency "stock_quote", "~> 1.0
|
26
|
+
gem.add_dependency "stock_quote", "~> 1.1.0"
|
27
27
|
end
|
28
28
|
Jeweler::RubygemsDotOrgTasks.new
|
29
29
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.0.0
|
data/lib/stock_quote_cli/cli.rb
CHANGED
@@ -8,44 +8,44 @@ module StockQuoteCLI
|
|
8
8
|
include StockQuoteCLI::Quote
|
9
9
|
include StockQuoteCLI::History
|
10
10
|
|
11
|
-
DEFAULT_RANGE =
|
11
|
+
DEFAULT_RANGE = 14 # days
|
12
12
|
DEFAULT_VALUE = "close"
|
13
13
|
VALUE_OPTIONS = ["open", "high", "low", "close", "volume"]
|
14
14
|
|
15
|
-
desc "last SYMBOL [SYMBOL...]", "get LAST stock price for SYMBOL"
|
15
|
+
desc "last SYMBOL [SYMBOL...]", "get day's LAST stock price for SYMBOL"
|
16
16
|
def last(symbol, *symbols)
|
17
17
|
stocks = stocks(symbol, symbols)
|
18
|
-
output_quote_messages(stocks, :
|
18
|
+
output_quote_messages(stocks, :last_trade_price_only)
|
19
19
|
end
|
20
20
|
|
21
|
-
desc "high SYMBOL [SYMBOL...]", "get HIGH stock price for SYMBOL"
|
21
|
+
desc "high SYMBOL [SYMBOL...]", "get day's HIGH stock price for SYMBOL"
|
22
22
|
def high(symbol, *symbols)
|
23
23
|
stocks = stocks(symbol, symbols)
|
24
|
-
output_quote_messages(stocks, :
|
24
|
+
output_quote_messages(stocks, :days_high)
|
25
25
|
end
|
26
26
|
|
27
|
-
desc "low SYMBOL [SYMBOL...]", "get LOW stock price for SYMBOL"
|
27
|
+
desc "low SYMBOL [SYMBOL...]", "get day's LOW stock price for SYMBOL"
|
28
28
|
def low(symbol, *symbols)
|
29
29
|
stocks = stocks(symbol, symbols)
|
30
|
-
output_quote_messages(stocks, :
|
30
|
+
output_quote_messages(stocks, :days_low)
|
31
31
|
end
|
32
32
|
|
33
|
-
desc "change SYMBOL [SYMBOL...]", "get CHANGE in stock price for SYMBOL"
|
33
|
+
desc "change SYMBOL [SYMBOL...]", "get day's CHANGE in stock price for SYMBOL"
|
34
34
|
def change(symbol, *symbols)
|
35
35
|
stocks = stocks(symbol, symbols)
|
36
36
|
output_quote_messages(stocks, :change)
|
37
37
|
end
|
38
38
|
|
39
|
-
desc "open SYMBOL [SYMBOL...]", "get OPEN stock price for SYMBOL"
|
39
|
+
desc "open SYMBOL [SYMBOL...]", "get day's OPEN stock price for SYMBOL"
|
40
40
|
def open(symbol, *symbols)
|
41
41
|
stocks = stocks(symbol, symbols)
|
42
42
|
output_quote_messages(stocks, :open)
|
43
43
|
end
|
44
44
|
|
45
|
-
desc "
|
46
|
-
def
|
45
|
+
desc "pclose SYMBOL [SYMBOL...]", "get previous closing (PCLOSE) stock price for SYMBOL"
|
46
|
+
def pclose(symbol, *symbols)
|
47
47
|
stocks = stocks(symbol, symbols)
|
48
|
-
output_quote_messages(stocks, :
|
48
|
+
output_quote_messages(stocks, :previous_close)
|
49
49
|
end
|
50
50
|
|
51
51
|
desc "volume SYMBOL [SYMBOL...]", "get share VOLUME for SYMBOL"
|
@@ -58,10 +58,9 @@ module StockQuoteCLI
|
|
58
58
|
method_option "range", aliases: "-r", type: :numeric, default: DEFAULT_RANGE, desc: "Specify the number of trading days for which to return stock price information."
|
59
59
|
method_option "value", aliases: "-v", type: :string, default: DEFAULT_VALUE, desc: "Specify the stock price value to retrieve for each date."
|
60
60
|
def history(symbol)
|
61
|
-
stock_history = get_stock_history(symbol)
|
62
|
-
trimmed_stock_history = trim_stock_history(stock_history, options['range'])
|
61
|
+
stock_history = get_stock_history(symbol, options['range'])
|
63
62
|
value = options['value']
|
64
|
-
output_history_messages(
|
63
|
+
output_history_messages(stock_history, value, VALUE_OPTIONS, symbol)
|
65
64
|
end
|
66
65
|
|
67
66
|
private
|
@@ -70,12 +69,12 @@ module StockQuoteCLI
|
|
70
69
|
puts
|
71
70
|
stocks.each do |stock|
|
72
71
|
if stock.response_code == 200
|
73
|
-
company = format_company(stock.
|
72
|
+
company = format_company(stock.name)
|
74
73
|
unless method_name == :volume
|
75
74
|
price = format_price(stock.send(method_name))
|
76
75
|
puts "#{company}: #{price}"
|
77
76
|
else
|
78
|
-
volume = format_volume(stock.
|
77
|
+
volume = format_volume(stock.volume)
|
79
78
|
puts "#{company}: #{volume}"
|
80
79
|
end
|
81
80
|
else
|
@@ -123,7 +122,7 @@ module StockQuoteCLI
|
|
123
122
|
end
|
124
123
|
|
125
124
|
def format_date(date)
|
126
|
-
date.
|
125
|
+
date.green.rjust(40)
|
127
126
|
end
|
128
127
|
|
129
128
|
def format_price(price)
|
@@ -2,12 +2,10 @@ module StockQuoteCLI
|
|
2
2
|
module History
|
3
3
|
private
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
stock_history[0...range]
|
11
|
-
end
|
5
|
+
def get_stock_history(symbol, range)
|
6
|
+
end_date = Date.today
|
7
|
+
start_date = end_date - range
|
8
|
+
StockQuote::Stock.history(symbol, start_date, end_date)
|
9
|
+
end
|
12
10
|
end
|
13
11
|
end
|
@@ -1 +1,16 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
module StockQuoteCLI
|
5
|
+
describe CLI do
|
6
|
+
it 'should exist' do
|
7
|
+
subject.should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'last method called' do
|
11
|
+
it 'should accept one argument' do
|
12
|
+
subject.stub(:last) { nil }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "stock_quote_cli"
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Travis Loncar"]
|
12
|
+
s.date = "2014-01-25"
|
13
|
+
s.description = "A Ruby gem that provides a command-line interface for fetching stock information."
|
14
|
+
s.email = "loncar.travis@gmail.com"
|
15
|
+
s.executables = ["stock"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
".travis.yml",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.md",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"bin/stock",
|
31
|
+
"lib/stock_quote_cli.rb",
|
32
|
+
"lib/stock_quote_cli/cli.rb",
|
33
|
+
"lib/stock_quote_cli/history.rb",
|
34
|
+
"lib/stock_quote_cli/quote.rb",
|
35
|
+
"spec/spec_helper.rb",
|
36
|
+
"spec/stock_quote_cli_spec.rb",
|
37
|
+
"stock_quote_cli.gemspec"
|
38
|
+
]
|
39
|
+
s.homepage = "http://github.com/tbloncar/stock_quote_cli"
|
40
|
+
s.licenses = ["MIT"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = "2.0.6"
|
43
|
+
s.summary = "A Ruby gem that provides a command-line interface for fetching stock information."
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 4
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<thor>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<stock_quote>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
52
|
+
s.add_development_dependency(%q<shoulda-matchers>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
|
56
|
+
s.add_runtime_dependency(%q<thor>, ["~> 0.18.1"])
|
57
|
+
s.add_runtime_dependency(%q<stock_quote>, ["~> 1.1.0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
60
|
+
s.add_dependency(%q<stock_quote>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
62
|
+
s.add_dependency(%q<shoulda-matchers>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
66
|
+
s.add_dependency(%q<thor>, ["~> 0.18.1"])
|
67
|
+
s.add_dependency(%q<stock_quote>, ["~> 1.1.0"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
71
|
+
s.add_dependency(%q<stock_quote>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
73
|
+
s.add_dependency(%q<shoulda-matchers>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
75
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
77
|
+
s.add_dependency(%q<thor>, ["~> 0.18.1"])
|
78
|
+
s.add_dependency(%q<stock_quote>, ["~> 1.1.0"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stock_quote_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Loncar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.8.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: shoulda-matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rdoc
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +128,14 @@ dependencies:
|
|
114
128
|
requirements:
|
115
129
|
- - ~>
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.0
|
131
|
+
version: 1.1.0
|
118
132
|
type: :runtime
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - ~>
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: 1.0
|
138
|
+
version: 1.1.0
|
125
139
|
description: A Ruby gem that provides a command-line interface for fetching stock
|
126
140
|
information.
|
127
141
|
email: loncar.travis@gmail.com
|
@@ -148,6 +162,7 @@ files:
|
|
148
162
|
- lib/stock_quote_cli/quote.rb
|
149
163
|
- spec/spec_helper.rb
|
150
164
|
- spec/stock_quote_cli_spec.rb
|
165
|
+
- stock_quote_cli.gemspec
|
151
166
|
homepage: http://github.com/tbloncar/stock_quote_cli
|
152
167
|
licenses:
|
153
168
|
- MIT
|
@@ -168,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
183
|
version: '0'
|
169
184
|
requirements: []
|
170
185
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.0.
|
186
|
+
rubygems_version: 2.0.6
|
172
187
|
signing_key:
|
173
188
|
specification_version: 4
|
174
189
|
summary: A Ruby gem that provides a command-line interface for fetching stock information.
|