Floppy-amee 2.0.7 → 2.0.8
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/connection.rb +3 -3
- data/lib/amee/data_category.rb +11 -7
- data/lib/amee/data_item.rb +2 -2
- data/lib/amee/data_item_value.rb +2 -2
- data/lib/amee/drill_down.rb +1 -1
- data/lib/amee/profile.rb +2 -2
- data/lib/amee/profile_category.rb +1 -1
- data/lib/amee/profile_item.rb +34 -4
- data/lib/amee/version.rb +1 -1
- metadata +2 -2
data/lib/amee/connection.rb
CHANGED
@@ -171,7 +171,7 @@ module AMEE
|
|
171
171
|
|
172
172
|
def response_ok?(response)
|
173
173
|
case response.code
|
174
|
-
when '200'
|
174
|
+
when '200', '201'
|
175
175
|
return true
|
176
176
|
when '403'
|
177
177
|
raise AMEE::PermissionDenied.new("You do not have permission to perform the requested operation. AMEE Response: #{response.body}")
|
@@ -190,8 +190,8 @@ module AMEE
|
|
190
190
|
begin
|
191
191
|
response = send_request(request, format)
|
192
192
|
end while !response_ok?(response)
|
193
|
-
# Return
|
194
|
-
return response
|
193
|
+
# Return response
|
194
|
+
return response
|
195
195
|
rescue SocketError
|
196
196
|
raise AMEE::ConnectionFailed.new("Connection failed. Check server name or network connection.")
|
197
197
|
ensure
|
data/lib/amee/data_category.rb
CHANGED
@@ -34,9 +34,9 @@ module AMEE
|
|
34
34
|
if doc['children']['dataItems']['rows']
|
35
35
|
doc['children']['dataItems']['rows'].each do |item|
|
36
36
|
item_data = {}
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
item.each_pair do |key, value|
|
38
|
+
item_data[key.to_sym] = value
|
39
|
+
end
|
40
40
|
data[:items] << item_data
|
41
41
|
end
|
42
42
|
end
|
@@ -67,8 +67,12 @@ module AMEE
|
|
67
67
|
REXML::XPath.each(doc, '/Resources/DataCategoryResource//Children/DataItems/DataItem') do |item|
|
68
68
|
item_data = {}
|
69
69
|
item_data[:uid] = item.attributes['uid'].to_s
|
70
|
-
|
71
|
-
|
70
|
+
item.elements.each do |element|
|
71
|
+
item_data[element.name.to_sym] = element.text
|
72
|
+
end
|
73
|
+
if item_data[:path].nil?
|
74
|
+
item_data[:path] = item_data[:uid]
|
75
|
+
end
|
72
76
|
data[:items] << item_data
|
73
77
|
end
|
74
78
|
# Create object
|
@@ -79,7 +83,7 @@ module AMEE
|
|
79
83
|
|
80
84
|
def self.get(connection, path, items_per_page = 10)
|
81
85
|
# Load data from path
|
82
|
-
response = connection.get(path, :itemsPerPage => items_per_page)
|
86
|
+
response = connection.get(path, :itemsPerPage => items_per_page).body
|
83
87
|
# Parse data from response
|
84
88
|
if response.is_json?
|
85
89
|
cat = Category.from_json(response)
|
@@ -108,4 +112,4 @@ module AMEE
|
|
108
112
|
|
109
113
|
end
|
110
114
|
end
|
111
|
-
end
|
115
|
+
end
|
data/lib/amee/data_item.rb
CHANGED
@@ -92,7 +92,7 @@ module AMEE
|
|
92
92
|
|
93
93
|
def self.get(connection, path, options = {})
|
94
94
|
# Load data from path
|
95
|
-
response = connection.get(path, options)
|
95
|
+
response = connection.get(path, options).body
|
96
96
|
# Parse data from response
|
97
97
|
if response.is_json?
|
98
98
|
item = Item.from_json(response)
|
@@ -108,7 +108,7 @@ module AMEE
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def update(options = {})
|
111
|
-
connection.put(full_path, options)
|
111
|
+
response = connection.put(full_path, options).body
|
112
112
|
rescue
|
113
113
|
raise AMEE::BadData.new("Couldn't update DataItem. Check that your information is correct.")
|
114
114
|
end
|
data/lib/amee/data_item_value.rb
CHANGED
@@ -71,7 +71,7 @@ module AMEE
|
|
71
71
|
|
72
72
|
def self.get(connection, path)
|
73
73
|
# Load data from path
|
74
|
-
response = connection.get(path)
|
74
|
+
response = connection.get(path).body
|
75
75
|
# Parse data from response
|
76
76
|
data = {}
|
77
77
|
if response.is_json?
|
@@ -88,7 +88,7 @@ module AMEE
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def save!
|
91
|
-
response = @connection.put(full_path, :value => value)
|
91
|
+
response = @connection.put(full_path, :value => value).body
|
92
92
|
end
|
93
93
|
|
94
94
|
end
|
data/lib/amee/drill_down.rb
CHANGED
data/lib/amee/profile.rb
CHANGED
@@ -4,7 +4,7 @@ module AMEE
|
|
4
4
|
|
5
5
|
def self.list(connection)
|
6
6
|
# Load data from path
|
7
|
-
response = connection.get('/profiles')
|
7
|
+
response = connection.get('/profiles').body
|
8
8
|
# Parse data from response
|
9
9
|
profiles = []
|
10
10
|
if response.is_json?
|
@@ -48,7 +48,7 @@ module AMEE
|
|
48
48
|
|
49
49
|
def self.create(connection)
|
50
50
|
# Create new profile
|
51
|
-
response = connection.post('/profiles', :profile => true)
|
51
|
+
response = connection.post('/profiles', :profile => true).body
|
52
52
|
# Parse data from response
|
53
53
|
if response.is_json?
|
54
54
|
# Read JSON
|
@@ -425,7 +425,7 @@ module AMEE
|
|
425
425
|
options[:duration] = "PT#{options[:duration] * 86400}S"
|
426
426
|
end
|
427
427
|
# Load data from path
|
428
|
-
response = connection.get(path, options)
|
428
|
+
response = connection.get(path, options).body
|
429
429
|
return Category.parse(connection, response)
|
430
430
|
rescue
|
431
431
|
raise AMEE::BadData.new("Couldn't load ProfileCategory. Check that your URL is correct.")
|
data/lib/amee/profile_item.rb
CHANGED
@@ -228,7 +228,7 @@ module AMEE
|
|
228
228
|
options[:duration] = "PT#{options[:duration] * 86400}S"
|
229
229
|
end
|
230
230
|
# Load data from path
|
231
|
-
response = connection.get(path, options)
|
231
|
+
response = connection.get(path, options).body
|
232
232
|
return Item.parse(connection, response)
|
233
233
|
rescue
|
234
234
|
raise AMEE::BadData.new("Couldn't load ProfileItem. Check that your URL is correct.")
|
@@ -265,9 +265,9 @@ module AMEE
|
|
265
265
|
options.merge! :dataItemUid => data_item_uid
|
266
266
|
response = connection.post(path, options)
|
267
267
|
if response['Location']
|
268
|
-
location = response['Location']
|
268
|
+
location = response['Location'].match("http://.*?(/.*)")[1]
|
269
269
|
else
|
270
|
-
category = Category.parse(connection, response)
|
270
|
+
category = Category.parse(connection, response.body)
|
271
271
|
location = category.full_path + "/" + category.items[0][:path]
|
272
272
|
end
|
273
273
|
if get_item == true
|
@@ -283,6 +283,10 @@ module AMEE
|
|
283
283
|
raise AMEE::BadData.new("Couldn't create ProfileItem. Check that your information is correct.")
|
284
284
|
end
|
285
285
|
|
286
|
+
def self.create_batch(category, items)
|
287
|
+
create_batch_without_category(category.connection, category.full_path, items)
|
288
|
+
end
|
289
|
+
|
286
290
|
def self.create_batch_without_category(connection, category_path, items)
|
287
291
|
if connection.format == :json
|
288
292
|
post_data = ({:profileItems => items}).to_json
|
@@ -296,8 +300,18 @@ module AMEE
|
|
296
300
|
end
|
297
301
|
|
298
302
|
def self.update(connection, path, options = {})
|
303
|
+
# Do we want to automatically fetch the item afterwards?
|
304
|
+
get_item = options.delete(:get_item)
|
305
|
+
get_item = true if get_item.nil?
|
306
|
+
# Go
|
299
307
|
response = connection.put(path, options)
|
300
|
-
|
308
|
+
if get_item
|
309
|
+
if response.body.empty?
|
310
|
+
return Item.get(connection, path)
|
311
|
+
else
|
312
|
+
return Item.parse(connection, response.body)
|
313
|
+
end
|
314
|
+
end
|
301
315
|
rescue
|
302
316
|
raise AMEE::BadData.new("Couldn't update ProfileItem. Check that your information is correct.")
|
303
317
|
end
|
@@ -306,6 +320,22 @@ module AMEE
|
|
306
320
|
AMEE::Profile::Item.update(connection, full_path, options)
|
307
321
|
end
|
308
322
|
|
323
|
+
def self.update_batch(category, items)
|
324
|
+
update_batch_without_category(category.connection, category.full_path, items)
|
325
|
+
end
|
326
|
+
|
327
|
+
def self.update_batch_without_category(connection, category_path, items)
|
328
|
+
if connection.format == :json
|
329
|
+
put_data = ({:profileItems => items}).to_json
|
330
|
+
else
|
331
|
+
put_data = ({:ProfileItems => items}).to_xml(:root => "ProfileCategory", :skip_types => true, :skip_nil => true)
|
332
|
+
end
|
333
|
+
# Post to category
|
334
|
+
response = connection.raw_put(category_path, put_data)
|
335
|
+
# Send back a category object containing all the created items
|
336
|
+
AMEE::Profile::Category.parse(connection, response)
|
337
|
+
end
|
338
|
+
|
309
339
|
def self.delete(connection, path)
|
310
340
|
connection.delete(path)
|
311
341
|
rescue
|
data/lib/amee/version.rb
CHANGED
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.8
|
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-03-
|
12
|
+
date: 2009-03-10 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|