Floppy-amee 2.0.17 → 2.0.18
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/lib/amee/data_category.rb +3 -3
- data/lib/amee/data_item.rb +3 -3
- data/lib/amee/data_item_value.rb +3 -3
- data/lib/amee/drill_down.rb +3 -3
- data/lib/amee/profile_category.rb +58 -19
- data/lib/amee/profile_item.rb +1 -1
- data/lib/amee/rails.rb +7 -0
- data/lib/amee/version.rb +1 -1
- data/rails/init.rb +1 -3
- metadata +2 -2
data/lib/amee/data_category.rb
CHANGED
@@ -43,7 +43,7 @@ module AMEE
|
|
43
43
|
# Create object
|
44
44
|
Category.new(data)
|
45
45
|
rescue
|
46
|
-
raise AMEE::BadData.new("Couldn't load DataCategory from JSON data. Check that your URL is correct
|
46
|
+
raise AMEE::BadData.new("Couldn't load DataCategory from JSON data. Check that your URL is correct.\n#{json}")
|
47
47
|
end
|
48
48
|
|
49
49
|
def self.from_xml(xml)
|
@@ -78,7 +78,7 @@ module AMEE
|
|
78
78
|
# Create object
|
79
79
|
Category.new(data)
|
80
80
|
rescue
|
81
|
-
raise AMEE::BadData.new("Couldn't load DataCategory from XML data. Check that your URL is correct
|
81
|
+
raise AMEE::BadData.new("Couldn't load DataCategory from XML data. Check that your URL is correct.\n#{xml}")
|
82
82
|
end
|
83
83
|
|
84
84
|
def self.get(connection, path, items_per_page = 10)
|
@@ -95,7 +95,7 @@ module AMEE
|
|
95
95
|
# Done
|
96
96
|
return cat
|
97
97
|
rescue
|
98
|
-
raise AMEE::BadData.new("Couldn't load DataCategory. Check that your URL is correct
|
98
|
+
raise AMEE::BadData.new("Couldn't load DataCategory. Check that your URL is correct.\n#{response}")
|
99
99
|
end
|
100
100
|
|
101
101
|
def self.root(connection)
|
data/lib/amee/data_item.rb
CHANGED
@@ -59,7 +59,7 @@ module AMEE
|
|
59
59
|
# Create object
|
60
60
|
Item.new(data)
|
61
61
|
rescue
|
62
|
-
raise AMEE::BadData.new("Couldn't load DataItem from JSON. Check that your URL is correct
|
62
|
+
raise AMEE::BadData.new("Couldn't load DataItem from JSON. Check that your URL is correct.\n#{json}")
|
63
63
|
end
|
64
64
|
|
65
65
|
def self.from_xml(xml)
|
@@ -102,7 +102,7 @@ module AMEE
|
|
102
102
|
# Create object
|
103
103
|
Item.new(data)
|
104
104
|
rescue
|
105
|
-
raise AMEE::BadData.new("Couldn't load DataItem from XML. Check that your URL is correct
|
105
|
+
raise AMEE::BadData.new("Couldn't load DataItem from XML. Check that your URL is correct.\n#{xml}")
|
106
106
|
end
|
107
107
|
|
108
108
|
|
@@ -120,7 +120,7 @@ module AMEE
|
|
120
120
|
# Done
|
121
121
|
return item
|
122
122
|
rescue
|
123
|
-
raise AMEE::BadData.new("Couldn't load DataItem. Check that your URL is correct
|
123
|
+
raise AMEE::BadData.new("Couldn't load DataItem. Check that your URL is correct.\n#{response}")
|
124
124
|
end
|
125
125
|
|
126
126
|
def self.create_batch_without_category(connection, category_path, items, options = {})
|
data/lib/amee/data_item_value.rb
CHANGED
@@ -47,7 +47,7 @@ module AMEE
|
|
47
47
|
# Create object
|
48
48
|
ItemValue.new(data)
|
49
49
|
rescue
|
50
|
-
raise AMEE::BadData.new("Couldn't load DataItemValue from JSON. Check that your URL is correct
|
50
|
+
raise AMEE::BadData.new("Couldn't load DataItemValue from JSON. Check that your URL is correct.\n#{json}")
|
51
51
|
end
|
52
52
|
|
53
53
|
def self.from_xml(xml, path)
|
@@ -66,7 +66,7 @@ module AMEE
|
|
66
66
|
# Create object
|
67
67
|
ItemValue.new(data)
|
68
68
|
rescue
|
69
|
-
raise AMEE::BadData.new("Couldn't load DataItemValue from XML. Check that your URL is correct
|
69
|
+
raise AMEE::BadData.new("Couldn't load DataItemValue from XML. Check that your URL is correct.\n#{xml}")
|
70
70
|
end
|
71
71
|
|
72
72
|
def self.get(connection, path)
|
@@ -84,7 +84,7 @@ module AMEE
|
|
84
84
|
# Done
|
85
85
|
return value
|
86
86
|
rescue
|
87
|
-
raise AMEE::BadData.new("Couldn't load DataItemValue. Check that your URL is correct
|
87
|
+
raise AMEE::BadData.new("Couldn't load DataItemValue. Check that your URL is correct.\n#{response}")
|
88
88
|
end
|
89
89
|
|
90
90
|
def save!
|
data/lib/amee/drill_down.rb
CHANGED
@@ -52,7 +52,7 @@ module AMEE
|
|
52
52
|
# Create object
|
53
53
|
DrillDown.new(data)
|
54
54
|
rescue
|
55
|
-
raise AMEE::BadData.new("Couldn't load DrillDown resource from JSON data. Check that your URL is correct
|
55
|
+
raise AMEE::BadData.new("Couldn't load DrillDown resource from JSON data. Check that your URL is correct.\n#{json}")
|
56
56
|
end
|
57
57
|
|
58
58
|
def self.from_xml(xml)
|
@@ -75,7 +75,7 @@ module AMEE
|
|
75
75
|
# Create object
|
76
76
|
DrillDown.new(data)
|
77
77
|
rescue
|
78
|
-
raise AMEE::BadData.new("Couldn't load DrillDown resource from XML data. Check that your URL is correct
|
78
|
+
raise AMEE::BadData.new("Couldn't load DrillDown resource from XML data. Check that your URL is correct.\n#{xml}")
|
79
79
|
end
|
80
80
|
|
81
81
|
def self.get(connection, path)
|
@@ -94,7 +94,7 @@ module AMEE
|
|
94
94
|
# Done
|
95
95
|
return drill
|
96
96
|
rescue
|
97
|
-
raise AMEE::BadData.new("Couldn't load DrillDown resource. Check that your URL is correct (#{path})
|
97
|
+
raise AMEE::BadData.new("Couldn't load DrillDown resource. Check that your URL is correct (#{path}).\n#{response}")
|
98
98
|
end
|
99
99
|
|
100
100
|
end
|
@@ -89,7 +89,7 @@ module AMEE
|
|
89
89
|
return category_data
|
90
90
|
end
|
91
91
|
|
92
|
-
def self.from_json(json)
|
92
|
+
def self.from_json(json, options)
|
93
93
|
# Parse json
|
94
94
|
doc = JSON.parse(json)
|
95
95
|
data = {}
|
@@ -118,12 +118,12 @@ module AMEE
|
|
118
118
|
raise AMEE::BadData.new("Couldn't load ProfileCategory from JSON data. Check that your URL is correct.")
|
119
119
|
end
|
120
120
|
|
121
|
-
def self.from_v2_json(json)
|
121
|
+
def self.from_v2_json(json, options)
|
122
122
|
# Parse json
|
123
123
|
doc = JSON.parse(json)
|
124
124
|
data = {}
|
125
125
|
data[:profile_uid] = doc['profile']['uid']
|
126
|
-
|
126
|
+
data[:profile_date] = options[:start_date]
|
127
127
|
data[:name] = doc['dataCategory']['name']
|
128
128
|
data[:path] = doc['path']
|
129
129
|
data[:total_amount] = doc['totalAmount']['value'].to_f rescue nil
|
@@ -146,7 +146,7 @@ module AMEE
|
|
146
146
|
rescue
|
147
147
|
raise AMEE::BadData.new("Couldn't load ProfileCategory from V2 JSON data. Check that your URL is correct.")
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
def self.parse_xml_profile_item(item)
|
151
151
|
item_data = {}
|
152
152
|
item_data[:values] = {}
|
@@ -175,6 +175,22 @@ module AMEE
|
|
175
175
|
return item_data
|
176
176
|
end
|
177
177
|
|
178
|
+
def self.from_v2_batch_json(json)
|
179
|
+
# Parse JSON
|
180
|
+
doc = JSON.parse(json)
|
181
|
+
data = {}
|
182
|
+
data[:profileItems] = []
|
183
|
+
doc['profileItems'].each do |child|
|
184
|
+
profile_item = {}
|
185
|
+
profile_item[:uri] = child['uri'].to_s
|
186
|
+
profile_item[:uid] = child['uid'].to_s
|
187
|
+
data[:profileItems] << profile_item
|
188
|
+
end
|
189
|
+
return data
|
190
|
+
rescue
|
191
|
+
raise AMEE::BadData.new("Couldn't load ProfileCategory batch response from V2 JSON data. Check that your URL is correct.")
|
192
|
+
end
|
193
|
+
|
178
194
|
def self.parse_xml_profile_category(category)
|
179
195
|
category_data = {}
|
180
196
|
category_data[:name] = category.elements['DataCategory'].elements['Name'].text
|
@@ -200,7 +216,7 @@ module AMEE
|
|
200
216
|
return category_data
|
201
217
|
end
|
202
218
|
|
203
|
-
def self.from_xml(xml)
|
219
|
+
def self.from_xml(xml, options)
|
204
220
|
# Parse XML
|
205
221
|
doc = REXML::Document.new(xml)
|
206
222
|
data = {}
|
@@ -280,12 +296,12 @@ module AMEE
|
|
280
296
|
return item_data
|
281
297
|
end
|
282
298
|
|
283
|
-
def self.from_v2_xml(xml)
|
299
|
+
def self.from_v2_xml(xml, options)
|
284
300
|
# Parse XML
|
285
301
|
doc = REXML::Document.new(xml)
|
286
302
|
data = {}
|
287
303
|
data[:profile_uid] = REXML::XPath.first(doc, "/Resources/ProfileCategoryResource/Profile/@uid").to_s
|
288
|
-
|
304
|
+
data[:profile_date] = options[:start_date]
|
289
305
|
data[:name] = REXML::XPath.first(doc, '/Resources/ProfileCategoryResource/DataCategory/Name').text
|
290
306
|
data[:path] = REXML::XPath.first(doc, '/Resources/ProfileCategoryResource/Path').text || ""
|
291
307
|
data[:total_amount] = REXML::XPath.first(doc, '/Resources/ProfileCategoryResource/TotalAmount').text.to_f rescue nil
|
@@ -314,12 +330,28 @@ module AMEE
|
|
314
330
|
raise AMEE::BadData.new("Couldn't load ProfileCategory from V2 XML data. Check that your URL is correct.")
|
315
331
|
end
|
316
332
|
|
317
|
-
def self.
|
333
|
+
def self.from_v2_batch_xml(xml)
|
334
|
+
# Parse XML
|
335
|
+
doc = REXML::Document.new(xml)
|
336
|
+
data = {}
|
337
|
+
data[:profileItems] = []
|
338
|
+
REXML::XPath.each(doc, '/Resources/ProfileItems/ProfileItem') do |child|
|
339
|
+
profile_item = {}
|
340
|
+
profile_item[:uri] = child.attributes['uri'].to_s
|
341
|
+
profile_item[:uid] = child.attributes['uid'].to_s
|
342
|
+
data[:profileItems] << profile_item
|
343
|
+
end
|
344
|
+
return data
|
345
|
+
rescue
|
346
|
+
raise AMEE::BadData.new("Couldn't load ProfileCategory batch response from V2 XML data. Check that your URL is correct.")
|
347
|
+
end
|
348
|
+
|
349
|
+
def self.from_v2_atom(response, options)
|
318
350
|
# Parse XML
|
319
351
|
doc = REXML::Document.new(response)
|
320
352
|
data = {}
|
321
353
|
data[:profile_uid] = REXML::XPath.first(doc, "/feed/@xml:base").to_s.match("/profiles/(.*?)/")[1]
|
322
|
-
|
354
|
+
data[:profile_date] = options[:start_date]
|
323
355
|
data[:name] = REXML::XPath.first(doc, '/feed/amee:name').text
|
324
356
|
data[:path] = REXML::XPath.first(doc, "/feed/@xml:base").to_s.match("/profiles/.*?(/.*)")[1]
|
325
357
|
data[:total_amount] = REXML::XPath.first(doc, '/feed/amee:totalAmount').text.to_f rescue nil
|
@@ -394,18 +426,18 @@ module AMEE
|
|
394
426
|
return history.reverse
|
395
427
|
end
|
396
428
|
|
397
|
-
def self.parse(connection, response)
|
429
|
+
def self.parse(connection, response, options)
|
398
430
|
# Parse data from response
|
399
431
|
if response.is_v2_json?
|
400
|
-
cat = Category.from_v2_json(response)
|
432
|
+
cat = Category.from_v2_json(response, options)
|
401
433
|
elsif response.is_json?
|
402
|
-
cat = Category.from_json(response)
|
434
|
+
cat = Category.from_json(response, options)
|
403
435
|
elsif response.is_v2_atom?
|
404
|
-
cat = Category.from_v2_atom(response)
|
436
|
+
cat = Category.from_v2_atom(response, options)
|
405
437
|
elsif response.is_v2_xml?
|
406
|
-
cat = Category.from_v2_xml(response)
|
438
|
+
cat = Category.from_v2_xml(response, options)
|
407
439
|
elsif response.is_xml?
|
408
|
-
cat = Category.from_xml(response)
|
440
|
+
cat = Category.from_xml(response, options)
|
409
441
|
end
|
410
442
|
# Store connection in object for future use
|
411
443
|
cat.connection = connection
|
@@ -413,7 +445,16 @@ module AMEE
|
|
413
445
|
return cat
|
414
446
|
end
|
415
447
|
|
416
|
-
|
448
|
+
def self.parse_batch(connection, response)
|
449
|
+
if response.is_v2_json?
|
450
|
+
return Category.from_v2_batch_json(response)
|
451
|
+
elsif response.is_v2_xml?
|
452
|
+
return Category.from_v2_batch_xml(response)
|
453
|
+
else
|
454
|
+
return self.parse(connection, response)
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
417
458
|
def self.get(connection, path, options = {})
|
418
459
|
unless options.is_a?(Hash)
|
419
460
|
raise AMEE::ArgumentError.new("Third argument must be a hash of options!")
|
@@ -424,17 +465,15 @@ module AMEE
|
|
424
465
|
elsif options[:start_date] && connection.version >= 2
|
425
466
|
options[:startDate] = options[:start_date].xmlschema
|
426
467
|
end
|
427
|
-
options.delete(:start_date)
|
428
468
|
if options[:end_date] && connection.version >= 2
|
429
469
|
options[:endDate] = options[:end_date].xmlschema
|
430
470
|
end
|
431
|
-
options.delete(:end_date)
|
432
471
|
if options[:duration] && connection.version >= 2
|
433
472
|
options[:duration] = "PT#{options[:duration] * 86400}S"
|
434
473
|
end
|
435
474
|
# Load data from path
|
436
475
|
response = connection.get(path, options).body
|
437
|
-
return Category.parse(connection, response)
|
476
|
+
return Category.parse(connection, response, options)
|
438
477
|
rescue
|
439
478
|
raise AMEE::BadData.new("Couldn't load ProfileCategory. Check that your URL is correct.")
|
440
479
|
end
|
data/lib/amee/profile_item.rb
CHANGED
@@ -299,7 +299,7 @@ module AMEE
|
|
299
299
|
response = connection.raw_post(category_path, post_data).body
|
300
300
|
# Send back a category object containing all the created items
|
301
301
|
unless response.empty?
|
302
|
-
return AMEE::Profile::Category.
|
302
|
+
return AMEE::Profile::Category.parse_batch(connection, response)
|
303
303
|
else
|
304
304
|
return true
|
305
305
|
end
|
data/lib/amee/rails.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
module AMEE
|
2
2
|
module Rails
|
3
3
|
|
4
|
+
def self.establish_connection(server, username, password)
|
5
|
+
# Connect
|
6
|
+
$amee = AMEE::Connection.new(server, username, password)
|
7
|
+
# Authenticate now to get it out of the way and to check settings
|
8
|
+
$amee.authenticate
|
9
|
+
end
|
10
|
+
|
4
11
|
def self.included(base)
|
5
12
|
base.extend ClassMethods
|
6
13
|
end
|
data/lib/amee/version.rb
CHANGED
data/rails/init.rb
CHANGED
@@ -7,9 +7,7 @@ if File.exist?(amee_config)
|
|
7
7
|
# Load config
|
8
8
|
$AMEE_CONFIG = YAML.load_file(amee_config)[RAILS_ENV]
|
9
9
|
# Create a global AMEE connection that we can use from anywhere in this app
|
10
|
-
|
11
|
-
# Authenticate now to get it out of the way and to check settings
|
12
|
-
$amee.authenticate
|
10
|
+
AMEE::Rails.establish_connection($AMEE_CONFIG['server'], $AMEE_CONFIG['username'], $AMEE_CONFIG['password'])
|
13
11
|
else
|
14
12
|
# Create an example AMEE config file and save it to config/amee.yml
|
15
13
|
example_config = {}
|
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: 2.0.
|
4
|
+
version: 2.0.18
|
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: 2009-
|
12
|
+
date: 2009-07-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|