Floppy-amee 0.4.10 → 0.4.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README +19 -1
- data/lib/amee/connection.rb +17 -2
- data/lib/amee/profile_category.rb +10 -1
- data/lib/amee/version.rb +1 -1
- data/rails/init.rb +5 -1
- metadata +3 -2
data/README
CHANGED
@@ -61,4 +61,22 @@ Once that is all set up, you can use AMEE objects within Rails anywhere you like
|
|
61
61
|
There is a persistent AMEE connection available called $amee, which you can pass
|
62
62
|
into the other objects to fetch data. For instance:
|
63
63
|
|
64
|
-
data = AMEE::Data::Category.root($amee)
|
64
|
+
data = AMEE::Data::Category.root($amee)
|
65
|
+
|
66
|
+
There is a helper for ActiveRecord models which should be linked to an AMEE profile.
|
67
|
+
By adding:
|
68
|
+
|
69
|
+
has_amee_profile
|
70
|
+
|
71
|
+
to your model, and by adding an amee_profile:string field to the model in the
|
72
|
+
database, an AMEE profile will be automatically created and destroyed with your
|
73
|
+
model. By overriding the function amee_save in your model, you can store data in
|
74
|
+
AMEE when your model is saved.
|
75
|
+
|
76
|
+
== CACHING
|
77
|
+
|
78
|
+
The AMEE::Connection object implements an optional cache for GET requests. This is
|
79
|
+
currently a versy simple implementation which caches the result of all GET requests
|
80
|
+
until a POST, PUT, or DELETE is executed, at which point the cache is cleared. To
|
81
|
+
enable caching, set the enable_caching parameter of AMEE::Connection.new to true.
|
82
|
+
Caching is disabled by default.
|
data/lib/amee/connection.rb
CHANGED
@@ -3,7 +3,7 @@ require 'net/http'
|
|
3
3
|
module AMEE
|
4
4
|
class Connection
|
5
5
|
|
6
|
-
def initialize(server, username = nil, password = nil, use_json_if_available = true)
|
6
|
+
def initialize(server, username = nil, password = nil, use_json_if_available = true, enable_caching = false)
|
7
7
|
@server = server
|
8
8
|
@username = username
|
9
9
|
@password = password
|
@@ -12,6 +12,10 @@ module AMEE
|
|
12
12
|
if (@username || @password) && !valid?
|
13
13
|
raise "Must specify both username and password for authenticated access"
|
14
14
|
end
|
15
|
+
@enable_caching = enable_caching
|
16
|
+
if @enable_caching
|
17
|
+
$cache ||= {}
|
18
|
+
end
|
15
19
|
# Make connection to server
|
16
20
|
@http = Net::HTTP.new(@server)
|
17
21
|
#@http.set_debug_output($stdout)
|
@@ -39,10 +43,13 @@ module AMEE
|
|
39
43
|
path += "?#{params.join('&')}"
|
40
44
|
end
|
41
45
|
# Send request
|
42
|
-
|
46
|
+
return $cache[path] if @enable_caching and $cache[path]
|
47
|
+
response = do_request Net::HTTP::Get.new(path)
|
48
|
+
$cache[path] = response if @enable_caching
|
43
49
|
end
|
44
50
|
|
45
51
|
def post(path, data = {})
|
52
|
+
clear_cache
|
46
53
|
# Create POST request
|
47
54
|
post = Net::HTTP::Post.new(path)
|
48
55
|
body = []
|
@@ -55,6 +62,7 @@ module AMEE
|
|
55
62
|
end
|
56
63
|
|
57
64
|
def put(path, data = {})
|
65
|
+
clear_cache
|
58
66
|
# Create PUT request
|
59
67
|
put = Net::HTTP::Put.new(path)
|
60
68
|
body = []
|
@@ -67,6 +75,7 @@ module AMEE
|
|
67
75
|
end
|
68
76
|
|
69
77
|
def delete(path)
|
78
|
+
clear_cache
|
70
79
|
# Create DELETE request
|
71
80
|
delete = Net::HTTP::Delete.new(path)
|
72
81
|
# Send request
|
@@ -136,5 +145,11 @@ module AMEE
|
|
136
145
|
response
|
137
146
|
end
|
138
147
|
|
148
|
+
def clear_cache
|
149
|
+
if @enable_caching
|
150
|
+
$cache = {}
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
139
154
|
end
|
140
155
|
end
|
@@ -114,7 +114,16 @@ module AMEE
|
|
114
114
|
history = []
|
115
115
|
num_months.times do
|
116
116
|
date = Date.new(year, month)
|
117
|
-
|
117
|
+
data = self.get(connection, path, date)
|
118
|
+
# If we get no data items back, there is no data at all before this date, so don't bother fetching it
|
119
|
+
if data.items.empty?
|
120
|
+
(num_months - history.size).times do
|
121
|
+
history << Category.new(:children => [], :items => [])
|
122
|
+
end
|
123
|
+
break
|
124
|
+
else
|
125
|
+
history << data
|
126
|
+
end
|
118
127
|
month -= 1
|
119
128
|
if (month == 0)
|
120
129
|
year -= 1
|
data/lib/amee/version.rb
CHANGED
data/rails/init.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'amee'
|
2
|
+
require 'amee/rails'
|
2
3
|
|
3
4
|
# Load config/amee.yml
|
4
5
|
amee_config = "#{RAILS_ROOT}/config/amee.yml"
|
@@ -20,4 +21,7 @@ else
|
|
20
21
|
end
|
21
22
|
# Inform the user that we've written a file for them
|
22
23
|
raise AMEE::ConnectionFailed.new("config/amee.yml doesn't exist. I've created one for you - please add your API keys to it.")
|
23
|
-
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Add AMEE extensions into ActiveRecord::Base
|
27
|
+
ActiveRecord::Base.class_eval { include AMEE::Rails }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Floppy-amee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Smith
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-10-
|
12
|
+
date: 2008-10-03 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/amee/object.rb
|
40
40
|
- lib/amee/shell.rb
|
41
41
|
- lib/amee/drill_down.rb
|
42
|
+
- lib/rails.rb
|
42
43
|
- bin/ameesh
|
43
44
|
- examples/list_profiles.rb
|
44
45
|
- examples/create_profile.rb
|