nanowrimo 0.7.5 → 0.7.7
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/History.txt +7 -0
- data/README.txt +3 -1
- data/lib/nanowrimo.rb +3 -3
- data/lib/nanowrimo/cache.rb +5 -0
- data/lib/nanowrimo/core.rb +13 -4
- data/test/test_cache.rb +9 -3
- data/test/test_nanowrimo.rb +13 -0
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
=== 0.7.7 / 2009-06-11
|
2
|
+
|
3
|
+
* 2 minor enhancements
|
4
|
+
|
5
|
+
* Nanowrimo::Cache::clear_cache - empties out the cache currently in memory.
|
6
|
+
* More caching goodness - Nanowrimo::Core#load and Nanowrimo::Core#load_history now support an options hash, the only option available being the ability to bypass any cached data for a given load and pull from WCAPI instead.
|
7
|
+
|
1
8
|
=== 0.7.5 / 2009-06-02
|
2
9
|
|
3
10
|
* 1 minor enhancement
|
data/README.txt
CHANGED
@@ -18,11 +18,13 @@ Features:
|
|
18
18
|
* API handles generated error messages from the WCAPI
|
19
19
|
* Page scraping place for basic user data from the profile page
|
20
20
|
* Caches data to avoid November bandwidth issues
|
21
|
+
* Caching is somewhat smart, with the ability to bypass it if there's a problem with cached data, and also the ability to completely clear all current cached data.
|
22
|
+
* Errors from the WCAPI are handled gracefully.
|
21
23
|
|
22
24
|
Problems:
|
23
25
|
* The Genres API on Nanowrimo.org is a little broken right now, so there's not much data to be loaded.
|
24
26
|
* Page scraping is dumb and costly. And the data I get is minimal. Submitted request for new API features with Nanowrimo.org crew.
|
25
|
-
* Caching is still fairly immature in this package
|
27
|
+
* Caching is still fairly immature in this package, but getting bettar.
|
26
28
|
|
27
29
|
== SYNOPSIS:
|
28
30
|
|
data/lib/nanowrimo.rb
CHANGED
@@ -23,7 +23,7 @@ require 'nanowrimo/cache'
|
|
23
23
|
|
24
24
|
module Nanowrimo
|
25
25
|
# Current API version
|
26
|
-
VERSION = '0.7.
|
26
|
+
VERSION = '0.7.7'
|
27
27
|
# Current static root WCAPI uri
|
28
28
|
API_URI = 'http://www.nanowrimo.org/wordcount_api'
|
29
29
|
# Current individual user word count goal. For fun!
|
@@ -31,8 +31,8 @@ module Nanowrimo
|
|
31
31
|
Nanowrimo::Cache.load_cache if Nanowrimo::Cache.cache_data == {}
|
32
32
|
|
33
33
|
# Pull requested data from cache or from the WCAPI
|
34
|
-
def self.parse(path, key, attribs)
|
35
|
-
result = data_from_cache(path, key) ||
|
34
|
+
def self.parse(path, key, attribs, options={:force => false})
|
35
|
+
result = options[:force] == true ? data_from_internets(path, key, attribs) : data_from_cache(path, key) ||
|
36
36
|
data_from_internets(path, key, attribs)
|
37
37
|
end
|
38
38
|
|
data/lib/nanowrimo/cache.rb
CHANGED
data/lib/nanowrimo/core.rb
CHANGED
@@ -7,8 +7,13 @@ module Nanowrimo
|
|
7
7
|
attr_accessor :error
|
8
8
|
|
9
9
|
# Returns the values for all attributes for a given WCAPI type
|
10
|
-
|
11
|
-
|
10
|
+
#
|
11
|
+
# Options:
|
12
|
+
#
|
13
|
+
# * :force - if set to true, will force Nanowrimo data to be pulled from the WCAPI and ignore cache data. not really recommended for bandwidth reasons.
|
14
|
+
def load(options={})
|
15
|
+
|
16
|
+
attribs = Nanowrimo.parse(load_field,id,self.class::FIELDS,options).first
|
12
17
|
self.error = attribs[:error]
|
13
18
|
self.class::FIELDS.each do |attrib|
|
14
19
|
self.send(:"#{attrib}=", attribs[attrib.intern])
|
@@ -16,8 +21,12 @@ module Nanowrimo
|
|
16
21
|
end
|
17
22
|
|
18
23
|
# Returns the values for all attributes for a given WCAPI type's history
|
19
|
-
|
20
|
-
|
24
|
+
#
|
25
|
+
# Options:
|
26
|
+
#
|
27
|
+
# * :force - if set to true, will force Nanowrimo data to be pulled from the WCAPI and ignore cache data. not really recommended for bandwidth reasons.
|
28
|
+
def load_history(options={})
|
29
|
+
self.history = Nanowrimo.parse(load_history_field,id,self.class::HISTORY_FIELDS,options)
|
21
30
|
if maybe_error = self.history.first
|
22
31
|
self.error = maybe_error[:error]
|
23
32
|
end
|
data/test/test_cache.rb
CHANGED
@@ -41,9 +41,15 @@ class TestCache < Test::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_find_data_finds_nothing_for_key
|
44
|
-
type="
|
45
|
-
key="
|
44
|
+
type="foo2"
|
45
|
+
key="bar2"
|
46
46
|
actual = Nanowrimo::Cache.find_data(type,key)
|
47
|
-
assert
|
47
|
+
assert actual.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_clear_cache_clears_cache
|
51
|
+
assert Nanowrimo::Cache.find_data("foo","bar")
|
52
|
+
Nanowrimo::Cache.clear_cache
|
53
|
+
assert Nanowrimo::Cache.cache_data.empty?
|
48
54
|
end
|
49
55
|
end
|
data/test/test_nanowrimo.rb
CHANGED
@@ -119,4 +119,17 @@ class TestNanowrimo < Test::Unit::TestCase
|
|
119
119
|
}
|
120
120
|
assert_equal expected, actual
|
121
121
|
end
|
122
|
+
|
123
|
+
def test_nanowrimo_parse_handles_forced_internet_data
|
124
|
+
attribs = %w[uid uname user_wordcount]
|
125
|
+
path = "wc"
|
126
|
+
key = 999999
|
127
|
+
file = "test/fixtures/user_wc_error.xml"
|
128
|
+
FakeWeb.register_uri("#{Nanowrimo::API_URI}/wc/#{key}", :file => file)
|
129
|
+
data = Nanowrimo.parse(path, key, attribs)
|
130
|
+
FakeWeb.clean_registry
|
131
|
+
assert_raise FakeWeb::NetConnectNotAllowedError do
|
132
|
+
Nanowrimo.parse(path, key, attribs, {:force => true})
|
133
|
+
end
|
134
|
+
end
|
122
135
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanowrimo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Clingenpeel
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|