hookercookerman-amee 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.rdoc +8 -1
- data/lib/amee.rb +1 -1
- data/lib/amee/data_api/data_category.rb +1 -6
- data/lib/amee/profile_api/profile_category.rb +11 -1
- data/lib/amee/session.rb +11 -4
- metadata +11 -1
data/README.rdoc
CHANGED
@@ -25,7 +25,14 @@
|
|
25
25
|
will populated the fridge category automagically;
|
26
26
|
|
27
27
|
Cache - Simple to Start (using Moneta)
|
28
|
-
Therefore if u wish you can choose your cache store even memcache via leveraging Moneta
|
28
|
+
Therefore if u wish you can choose your cache store even memcache via leveraging Moneta
|
29
|
+
|
30
|
+
Pagination on data_items
|
31
|
+
|
32
|
+
@data_category = session.get_data_category("/data/whatever_path", :query => {:itemsPerPage => 30, :page => 1})
|
33
|
+
@data_items = @data_category.paginate_data_items(:per_page => 30,:page => params[:page])
|
34
|
+
|
35
|
+
You know have a pagintated data_items
|
29
36
|
|
30
37
|
= TODOS
|
31
38
|
|
data/lib/amee.rb
CHANGED
@@ -41,12 +41,7 @@ module Amee
|
|
41
41
|
options[:per_page] || 10,
|
42
42
|
options[:total] || self.pager["items"]
|
43
43
|
) do |pager|
|
44
|
-
|
45
|
-
:query => {:itemsPerPage => pager.per_page, :page => pager.current_page}
|
46
|
-
) do |response|
|
47
|
-
populate_from_hash!(response)
|
48
|
-
end
|
49
|
-
pager.replace(result.data_items)
|
44
|
+
pager.replace(self.data_items || [])
|
50
45
|
end
|
51
46
|
end
|
52
47
|
|
@@ -7,7 +7,7 @@ module Amee
|
|
7
7
|
self.path_prefix = "/profiles"
|
8
8
|
|
9
9
|
|
10
|
-
attr_accessor :profile, :total_amount_per_month, :total_amount
|
10
|
+
attr_accessor :profile, :total_amount_per_month, :total_amount, :pager
|
11
11
|
|
12
12
|
list_populators :profile_items => {:class => Amee::ProfileApi::ProfileItem},
|
13
13
|
:profile_categories => {:class => Amee::ProfileApi::ProfileCategory}
|
@@ -37,6 +37,16 @@ module Amee
|
|
37
37
|
"#{self.class.path_prefix}/#{profile_uid}" + resource_path
|
38
38
|
end
|
39
39
|
|
40
|
+
def paginate_profile_items(options = {})
|
41
|
+
profile_items = WillPaginate::Collection.create(
|
42
|
+
options[:page] || 1,
|
43
|
+
options[:per_page] || 10,
|
44
|
+
options[:total] || self.pager["items"]
|
45
|
+
) do |pager|
|
46
|
+
pager.replace(self.profile_items || [])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
40
50
|
end
|
41
51
|
|
42
52
|
end
|
data/lib/amee/session.rb
CHANGED
@@ -65,7 +65,7 @@ module Amee
|
|
65
65
|
def api_call_without_logging(method, parser_name, path, options, use_auth_token =true, &proc)
|
66
66
|
result = service.send(method, parser_name, path, options)
|
67
67
|
result = yield result if block_given?
|
68
|
-
store_resource(path,result, options
|
68
|
+
store_resource(path,result, options||{}) if method == :get && caching?
|
69
69
|
result
|
70
70
|
end
|
71
71
|
|
@@ -74,7 +74,7 @@ module Amee
|
|
74
74
|
# or actually call the amee api; if the session has expired we will try
|
75
75
|
# to get a new one
|
76
76
|
def api_call(method, parser_name, path, options ={}, use_auth_token =true, &proc)
|
77
|
-
if (cache = @cache[path]) && caching?
|
77
|
+
if (cache = @cache[cache_key(path, options[:query] || {})]) && caching?
|
78
78
|
return cache
|
79
79
|
else
|
80
80
|
attempts = 0
|
@@ -214,8 +214,15 @@ module Amee
|
|
214
214
|
|
215
215
|
# @param [String] path the path of the resource
|
216
216
|
# @param [Hash] cache_options this is the cache options
|
217
|
-
def store_resource(path, result,
|
218
|
-
|
217
|
+
def store_resource(path, result, options = {})
|
218
|
+
key = cache_key(path, options[:query] ||{})
|
219
|
+
cache_options = options[:cache] || {}
|
220
|
+
@cache.store(key, result, :expires_in => cache_options[:expires_in] || Amee::Config[:expires_in])
|
221
|
+
end
|
222
|
+
|
223
|
+
protected
|
224
|
+
def cache_key(path, params = {})
|
225
|
+
path + params.map { |key,value| "#{key}=#{value}" }.join('/')
|
219
226
|
end
|
220
227
|
|
221
228
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hookercookerman-amee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Hooker
|
@@ -62,6 +62,16 @@ dependencies:
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: "0"
|
64
64
|
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: mislav-will_paginate
|
67
|
+
type: :runtime
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 2.2.3
|
74
|
+
version:
|
65
75
|
description: Its a gem to interact with the amee api
|
66
76
|
email:
|
67
77
|
- richard.hooker@dynamic50.com
|