httparty_sober 0.1.0 → 0.2.0
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/VERSION +1 -1
- data/lib/httparty/sober.rb +2 -1
- data/test/test_httparty_sober.rb +26 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/httparty/sober.rb
CHANGED
@@ -24,7 +24,8 @@ module HTTParty
|
|
24
24
|
|
25
25
|
def get_with_caching(path, options={})
|
26
26
|
cache_options = (@@cache_options || {}).merge(options[:cache] || {})
|
27
|
-
|
27
|
+
key = "#{path.to_s}#{options[:query].to_s}"
|
28
|
+
APICache.get(key,cache_options) do
|
28
29
|
perform_request(Net::HTTP::Get, path, options)
|
29
30
|
end
|
30
31
|
end
|
data/test/test_httparty_sober.rb
CHANGED
@@ -13,6 +13,32 @@ class TestHttpartySober < Test::Unit::TestCase
|
|
13
13
|
CacheParty.cache :store => "cache_store"
|
14
14
|
end
|
15
15
|
|
16
|
+
should "cache ;)" do
|
17
|
+
class CacheR
|
18
|
+
include HTTParty
|
19
|
+
include HTTParty::Sober
|
20
|
+
end
|
21
|
+
CacheR.cache!
|
22
|
+
CacheR.expects(:perform_request).with(Net::HTTP::Get, "url", :query => {:hallo=> "welt"}).returns("response")
|
23
|
+
|
24
|
+
CacheR.get "url", :query =>{:hallo=> "welt"}
|
25
|
+
# now this must be cached
|
26
|
+
CacheR.get "url", :query =>{:hallo=> "welt"}
|
27
|
+
end
|
28
|
+
|
29
|
+
should "use the path and the query parameters as cache key" do
|
30
|
+
class CacheKey
|
31
|
+
include HTTParty
|
32
|
+
include HTTParty::Sober
|
33
|
+
end
|
34
|
+
CacheKey.cache
|
35
|
+
url = "/params"
|
36
|
+
query = {:hey=> "ho", :lets => "go"}
|
37
|
+
key = "#{url.to_s}#{query.to_s}"
|
38
|
+
APICache.expects(:get).with(key,{})
|
39
|
+
CacheKey.get_with_caching url, {:query => query}
|
40
|
+
end
|
41
|
+
|
16
42
|
should "save and use default caching options" do
|
17
43
|
options = {:cache =>123, :valid => 123}
|
18
44
|
CacheParty.cache options
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httparty_sober
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bumann
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-03-20 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|