yahoo_quote 0.0.4 → 0.0.5
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.
- data/README.markdown +1 -1
- data/lib/yahoo_quote/configuration.rb +5 -5
- data/lib/yahoo_quote/version.rb +1 -1
- data/lib/yahoo_quote.rb +4 -2
- data/test/yahoo_quote_test.rb +35 -3
- data/yahoo_quote.gemspec +1 -0
- metadata +15 -4
data/README.markdown
CHANGED
@@ -2,12 +2,12 @@ module YahooQuote
|
|
2
2
|
class Configuration
|
3
3
|
|
4
4
|
def self.cache_dir=(path)
|
5
|
-
if !path
|
6
|
-
@@cache_dir =
|
5
|
+
if !path || path.to_s.empty?
|
6
|
+
@@cache_dir = nil
|
7
7
|
else
|
8
|
-
|
9
|
-
|
10
|
-
@@cache_dir =
|
8
|
+
path = Pathname.new(path) if path.is_a? String
|
9
|
+
path.mkdir unless path.directory?
|
10
|
+
@@cache_dir = path
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
data/lib/yahoo_quote/version.rb
CHANGED
data/lib/yahoo_quote.rb
CHANGED
@@ -46,8 +46,10 @@ module YahooQuote
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def clear_cache
|
49
|
-
|
50
|
-
|
49
|
+
if cache_response?
|
50
|
+
Pathname.glob(YahooQuote::Configuration.cache_dir.join('*.csv')).each {|f|
|
51
|
+
f.unlink}
|
52
|
+
end
|
51
53
|
end
|
52
54
|
|
53
55
|
def quote_url
|
data/test/yahoo_quote_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'yahoo_quote'
|
2
2
|
require 'minitest/autorun'
|
3
|
+
require 'pathname'
|
3
4
|
require 'fakeweb'
|
4
5
|
|
5
6
|
# TODO test 2 things: make intermediate dirs for cache and permissions
|
@@ -10,7 +11,13 @@ class TestYahooQuote < MiniTest::Unit::TestCase
|
|
10
11
|
FakeWeb.allow_net_connect = false
|
11
12
|
FakeWeb.register_uri(:get, @url_regexp, :response => File.read("test/fakeweb/aapl_good.csv"))
|
12
13
|
|
13
|
-
@cache_dir =
|
14
|
+
@cache_dir = Pathname.new('test/cache')
|
15
|
+
end
|
16
|
+
|
17
|
+
def remove_dir(dir_path)
|
18
|
+
return unless dir_path.exist?
|
19
|
+
dir_path.each_child {|p| p.unlink}
|
20
|
+
dir_path.unlink
|
14
21
|
end
|
15
22
|
|
16
23
|
def test_empty_arguments
|
@@ -66,14 +73,39 @@ class TestYahooQuote < MiniTest::Unit::TestCase
|
|
66
73
|
assert !cached_quote.cache_response?
|
67
74
|
end
|
68
75
|
|
76
|
+
def test_create_cache_dir
|
77
|
+
remove_dir @cache_dir
|
78
|
+
assert !@cache_dir.exist?
|
79
|
+
YahooQuote::Configuration.cache_dir = @cache_dir
|
80
|
+
assert @cache_dir.exist?
|
81
|
+
YahooQuote::Configuration.cache_dir = nil
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_clear_cache_when_no_cache
|
85
|
+
quote = YahooQuote::Quote.new('AAPL', ['Name'])
|
86
|
+
quote.clear_cache
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_clear_cache_when_empty_string
|
90
|
+
YahooQuote::Configuration.cache_dir = ''
|
91
|
+
quote = YahooQuote::Quote.new('AAPL', ['Name'])
|
92
|
+
quote.clear_cache
|
93
|
+
end
|
94
|
+
|
69
95
|
def test_clear_cache
|
70
96
|
YahooQuote::Configuration.cache_dir = @cache_dir
|
71
97
|
quote = YahooQuote::Quote.new('AAPL', ['Name'])
|
72
98
|
assert Dir.glob(File.join(@cache_dir, '*.csv')).size > 0, 'No files stored in cache'
|
73
99
|
quote.clear_cache
|
74
100
|
assert_equal 0, Dir.glob(File.join(@cache_dir, '*.csv')).size
|
75
|
-
# We don't want to cache responses for other tests
|
76
101
|
YahooQuote::Configuration.cache_dir = nil
|
77
|
-
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_save_cache_dir_as_pathname
|
105
|
+
dir_string = @cache_dir.to_s
|
106
|
+
assert dir_string.is_a?(String)
|
107
|
+
YahooQuote::Configuration.cache_dir = dir_string
|
108
|
+
assert YahooQuote::Configuration.cache_dir.is_a?(Pathname)
|
109
|
+
YahooQuote::Configuration.cache_dir = nil
|
78
110
|
end
|
79
111
|
end
|
data/yahoo_quote.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yahoo_quote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-22 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fakeweb
|
16
|
-
requirement: &
|
16
|
+
requirement: &2157617700 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,18 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2157617700
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ruby-debug19
|
27
|
+
requirement: &2157617280 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2157617280
|
25
36
|
description: Easy interaction with Yahoo Finance API
|
26
37
|
email:
|
27
38
|
- bcarreno@yahoo.com
|