nanowrimo 0.7.5 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -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. Need to tune it further before November hits.
27
+ * Caching is still fairly immature in this package, but getting bettar.
26
28
 
27
29
  == SYNOPSIS:
28
30
 
@@ -23,7 +23,7 @@ require 'nanowrimo/cache'
23
23
 
24
24
  module Nanowrimo
25
25
  # Current API version
26
- VERSION = '0.7.5'
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
 
@@ -48,5 +48,10 @@ module Nanowrimo
48
48
  @@cache_data["#{type}"] = {"#{key}" => Hash[:data, data, :created_at, Time.now]}
49
49
  }
50
50
  end
51
+
52
+ # Clears all cache from memory, will of course write that out to disk
53
+ def self.clear_cache
54
+ @@cache_data.clear
55
+ end
51
56
  end
52
57
  end
@@ -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
- def load
11
- attribs = Nanowrimo.parse(load_field,id,self.class::FIELDS).first
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
- def load_history
20
- self.history = Nanowrimo.parse(load_history_field,id,self.class::HISTORY_FIELDS)
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
@@ -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="foo"
45
- key="bar"
44
+ type="foo2"
45
+ key="bar2"
46
46
  actual = Nanowrimo::Cache.find_data(type,key)
47
- assert !actual.nil?
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
@@ -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.5
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-02 00:00:00 -07:00
12
+ date: 2009-06-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency