task_helper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/lib/task_helper/api/cache.rb +3 -2
- data/lib/task_helper/api/call.rb +1 -1
- data/lib/task_helper/version.rb +1 -1
- data/spec/lib/task_helper/api/call_spec.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f0bec83e9bd57e8829c3c5a0193de45677cb253
|
4
|
+
data.tar.gz: ac45b04ad8a57b31affe767dc0816f3784bf6e2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1967e11fb7593c068839c5e0574fd5653b65dd7aa2df5b38f346a4070a1227722b6c022aa54ba50800ead687ca829352d4c4cd914aa0c693488034ef4a5c10e
|
7
|
+
data.tar.gz: 79f758cb137743cc4a957f471986fec6516562dbd7ab30ae045661cf1f96d2e2fc5eea851fd7770c0675a43d44c5be926bf00fd5b3be93a2c167499838a35608
|
data/README.md
CHANGED
@@ -40,6 +40,27 @@ an ActiveRecord like fashion. Each class contains methods for fetching
|
|
40
40
|
objects from the API, readers for attributes of retrieved objects,
|
41
41
|
and methods to navigate between related resources.
|
42
42
|
|
43
|
+
### Caching
|
44
|
+
|
45
|
+
Each model manages a cache of calls to the API that it makes.
|
46
|
+
The model's cache has a limit (the number of responses to be cached)
|
47
|
+
and a timeout (the number of seconds until an individual response expires).
|
48
|
+
By default, limit and timeout are set to zero (no caching). This can be
|
49
|
+
changed for each model using `Model::set_cache`.
|
50
|
+
|
51
|
+
For example
|
52
|
+
|
53
|
+
TaskHelper::Database.set_cache(limit: 5, timeout: 60)
|
54
|
+
|
55
|
+
will cache up to five responses from the API's database resource, for
|
56
|
+
up to 60 seconds each. This means, if you call `TashHelper::Database.all`
|
57
|
+
10 times in 60 seconds, the gem will only contact the API once. After 60
|
58
|
+
seconds, if you ask for all databases again, the cache will be refreshed.
|
59
|
+
|
60
|
+
Changing the cache settings for one model does not affect the others.
|
61
|
+
So, to cache all responses, each model must be individually configured
|
62
|
+
to cache its responses.
|
63
|
+
|
43
64
|
#### Database
|
44
65
|
|
45
66
|
This class offers functionality to retrieve and interact with databases
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module TaskHelper
|
2
2
|
module API
|
3
3
|
class Cache
|
4
|
-
def initialize(limit:
|
4
|
+
def initialize(limit: 0, **call_defaults)
|
5
5
|
@limit = limit
|
6
|
+
@call_defaults = call_defaults
|
6
7
|
@calls = []
|
7
8
|
end
|
8
9
|
|
9
10
|
def get(**args)
|
10
|
-
new_call = Call.new(args)
|
11
|
+
new_call = Call.new(@call_defaults.merge(args))
|
11
12
|
cached_call = @calls.find { |call| call == new_call }
|
12
13
|
if cached_call
|
13
14
|
cached_call.run
|
data/lib/task_helper/api/call.rb
CHANGED
@@ -6,7 +6,7 @@ module TaskHelper
|
|
6
6
|
attr_reader :route, :params, :time
|
7
7
|
protected :route, :params
|
8
8
|
|
9
|
-
def initialize(route:, params: {}, timeout:
|
9
|
+
def initialize(route:, params: {}, timeout: 0, time: Time.now)
|
10
10
|
@params = { rest_api_key: API.rest_api_key }.merge(params)
|
11
11
|
if @params[:rest_api_key].nil?
|
12
12
|
raise MissingAPIKey, "Rest API key not provided. " \
|
data/lib/task_helper/version.rb
CHANGED
@@ -73,8 +73,9 @@ describe TaskHelper::API::Call do
|
|
73
73
|
context 'request has been cached' do
|
74
74
|
it 'should return the cached response' do
|
75
75
|
expect(HTTParty).to receive(:get).once.and_return(response)
|
76
|
-
|
77
|
-
|
76
|
+
call = described_class.new(route: 'hello', timeout: 314)
|
77
|
+
result = call.run
|
78
|
+
expect(call.run).to eq(result)
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: task_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JC Wilcox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|