Floppy-amee 2.0.10 → 2.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/amee.rb +1 -0
- data/lib/amee/profile_item.rb +10 -2
- data/lib/amee/profile_item_value.rb +106 -0
- data/lib/amee/version.rb +1 -1
- metadata +3 -2
data/lib/amee.rb
CHANGED
data/lib/amee/profile_item.rb
CHANGED
@@ -296,7 +296,11 @@ module AMEE
|
|
296
296
|
# Post to category
|
297
297
|
response = connection.raw_post(category_path, post_data).body
|
298
298
|
# Send back a category object containing all the created items
|
299
|
-
|
299
|
+
unless response.empty?
|
300
|
+
return AMEE::Profile::Category.parse(connection, response)
|
301
|
+
else
|
302
|
+
return true
|
303
|
+
end
|
300
304
|
end
|
301
305
|
|
302
306
|
def self.update(connection, path, options = {})
|
@@ -333,7 +337,11 @@ module AMEE
|
|
333
337
|
# Post to category
|
334
338
|
response = connection.raw_put(category_path, put_data).body
|
335
339
|
# Send back a category object containing all the created items
|
336
|
-
|
340
|
+
unless response.empty?
|
341
|
+
return AMEE::Profile::Category.parse(connection, response)
|
342
|
+
else
|
343
|
+
return true
|
344
|
+
end
|
337
345
|
end
|
338
346
|
|
339
347
|
def self.delete(connection, path)
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module AMEE
|
2
|
+
module Profile
|
3
|
+
class ItemValue < AMEE::Profile::Object
|
4
|
+
|
5
|
+
def initialize(data = {})
|
6
|
+
@value = data ? data[:value] : nil
|
7
|
+
@type = data ? data[:type] : nil
|
8
|
+
@unit = data ? data[:unit] : nil
|
9
|
+
@per_unit = data ? data[:per_unit] : nil
|
10
|
+
@from_profile = data ? data[:from_profile] : nil
|
11
|
+
@from_data = data ? data[:from_data] : nil
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :type
|
16
|
+
attr_accessor :unit
|
17
|
+
attr_accessor :per_unit
|
18
|
+
|
19
|
+
def value
|
20
|
+
case type
|
21
|
+
when "DECIMAL"
|
22
|
+
@value.to_f
|
23
|
+
else
|
24
|
+
@value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def value=(val)
|
29
|
+
@value = val
|
30
|
+
end
|
31
|
+
|
32
|
+
def from_profile?
|
33
|
+
@from_profile
|
34
|
+
end
|
35
|
+
|
36
|
+
def from_data?
|
37
|
+
@from_data
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.from_json(json, path)
|
41
|
+
# Read JSON
|
42
|
+
doc = JSON.parse(json)['itemValue']
|
43
|
+
data = {}
|
44
|
+
data[:uid] = doc['uid']
|
45
|
+
data[:created] = DateTime.parse(doc['created'])
|
46
|
+
data[:modified] = DateTime.parse(doc['modified'])
|
47
|
+
data[:name] = doc['name']
|
48
|
+
data[:path] = path.gsub(/^\/profiles/, '')
|
49
|
+
data[:value] = doc['value']
|
50
|
+
data[:unit] = doc['unit']
|
51
|
+
data[:per_unit] = doc['perUnit']
|
52
|
+
data[:type] = doc['itemValueDefinition']['valueDefinition']['valueType']
|
53
|
+
# Create object
|
54
|
+
ItemValue.new(data)
|
55
|
+
rescue
|
56
|
+
raise AMEE::BadData.new("Couldn't load ProfileItemValue from JSON. Check that your URL is correct.")
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.from_xml(xml, path)
|
60
|
+
# Read XML
|
61
|
+
doc = REXML::Document.new(xml)
|
62
|
+
data = {}
|
63
|
+
data[:uid] = REXML::XPath.first(doc, "/Resources/ProfileItemValueResource/ItemValue/@uid").to_s
|
64
|
+
data[:created] = DateTime.parse(REXML::XPath.first(doc, "/Resources/ProfileItemValueResource/ItemValue/@Created").to_s)
|
65
|
+
data[:modified] = DateTime.parse(REXML::XPath.first(doc, "/Resources/ProfileItemValueResource/ItemValue/@Modified").to_s)
|
66
|
+
data[:name] = REXML::XPath.first(doc, '/Resources/ProfileItemValueResource/ItemValue/Name').text
|
67
|
+
data[:path] = path.gsub(/^\/profiles/, '')
|
68
|
+
data[:value] = REXML::XPath.first(doc, '/Resources/ProfileItemValueResource/ItemValue/Value').text
|
69
|
+
data[:unit] = REXML::XPath.first(doc, '/Resources/ProfileItemValueResource/ItemValue/Unit').text rescue nil
|
70
|
+
data[:per_unit] = REXML::XPath.first(doc, '/Resources/ProfileItemValueResource/ItemValue/PerUnit').text rescue nil
|
71
|
+
data[:type] = REXML::XPath.first(doc, '/Resources/ProfileItemValueResource/ItemValue/ItemValueDefinition/ValueDefinition/ValueType').text
|
72
|
+
data[:from_profile] = REXML::XPath.first(doc, '/Resources/ProfileItemValueResource/ItemValue/ItemValueDefinition/FromProfile').text == "true" ? true : false
|
73
|
+
data[:from_data] = REXML::XPath.first(doc, '/Resources/ProfileItemValueResource/ItemValue/ItemValueDefinition/FromData').text == "true" ? true : false
|
74
|
+
# Create object
|
75
|
+
ItemValue.new(data)
|
76
|
+
rescue
|
77
|
+
raise AMEE::BadData.new("Couldn't load ProfileItemValue from XML. Check that your URL is correct.")
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.get(connection, path)
|
81
|
+
# Load Profile from path
|
82
|
+
response = connection.get(path).body
|
83
|
+
# Parse data from response
|
84
|
+
if response.is_json?
|
85
|
+
value = ItemValue.from_json(response, path)
|
86
|
+
else
|
87
|
+
value = ItemValue.from_xml(response, path)
|
88
|
+
end
|
89
|
+
# Store connection in object for future use
|
90
|
+
value.connection = connection
|
91
|
+
# Done
|
92
|
+
return value
|
93
|
+
rescue
|
94
|
+
raise AMEE::BadData.new("Couldn't load ProfileItemValue. Check that your URL is correct.")
|
95
|
+
end
|
96
|
+
|
97
|
+
def save!
|
98
|
+
options = {:value => value}
|
99
|
+
options[:unit] = unit if unit
|
100
|
+
options[:perUnit] = per_unit if per_unit
|
101
|
+
response = @connection.put(full_path, options).body
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
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.11
|
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-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- lib/amee/profile_object.rb
|
42
42
|
- lib/amee/profile_category.rb
|
43
43
|
- lib/amee/profile_item.rb
|
44
|
+
- lib/amee/profile_item_value.rb
|
44
45
|
- lib/amee/version.rb
|
45
46
|
- lib/amee/data_category.rb
|
46
47
|
- lib/amee/data_item_value.rb
|