Floppy-amee 0.4.28 → 0.4.29
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_item_value.rb +1 -1
- data/lib/amee/profile_category.rb +116 -53
- data/lib/amee/version.rb +1 -1
- metadata +2 -2
data/lib/amee/data_item_value.rb
CHANGED
|
@@ -65,7 +65,7 @@ module AMEE
|
|
|
65
65
|
data[:from_data] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/ItemValueDefinition/FromData').text == "true" ? true : false
|
|
66
66
|
# Create object
|
|
67
67
|
ItemValue.new(data)
|
|
68
|
-
rescue
|
|
68
|
+
rescue
|
|
69
69
|
raise AMEE::BadData.new("Couldn't load DataItemValue from XML. Check that your URL is correct.")
|
|
70
70
|
end
|
|
71
71
|
|
|
@@ -15,6 +15,55 @@ module AMEE
|
|
|
15
15
|
attr_reader :items
|
|
16
16
|
attr_reader :total_amount_per_month
|
|
17
17
|
|
|
18
|
+
def self.parse_json_profile_item(item)
|
|
19
|
+
item_data = {}
|
|
20
|
+
item_data[:values] = {}
|
|
21
|
+
item.each_pair do |key, value|
|
|
22
|
+
case key
|
|
23
|
+
when 'dataItemLabel', 'dataItemUid', 'name', 'path', 'uid'
|
|
24
|
+
item_data[key.to_sym] = value
|
|
25
|
+
when 'created', 'modified', 'label' # ignore these
|
|
26
|
+
nil
|
|
27
|
+
when 'validFrom'
|
|
28
|
+
item_data[:validFrom] = DateTime.strptime(value, "%Y%m%d")
|
|
29
|
+
when 'end'
|
|
30
|
+
item_data[:end] = (value == "true")
|
|
31
|
+
when 'amountPerMonth'
|
|
32
|
+
item_data[:amountPerMonth] = value.to_f
|
|
33
|
+
else
|
|
34
|
+
item_data[:values][key.to_sym] = value
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
item_data[:path] ||= item_data[:uid] # Fill in path if not retrieved from response
|
|
38
|
+
return item_data
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.parse_json_profile_category(category)
|
|
42
|
+
datacat = category['dataCategory'] ? category['dataCategory'] : category
|
|
43
|
+
category_data = {}
|
|
44
|
+
category_data[:name] = datacat['name']
|
|
45
|
+
category_data[:path] = datacat['path']
|
|
46
|
+
category_data[:uid] = datacat['uid']
|
|
47
|
+
category_data[:totalAmountPerMonth] = category['totalAmountPerMonth'].to_f
|
|
48
|
+
category_data[:children] = []
|
|
49
|
+
category_data[:items] = []
|
|
50
|
+
if category['children']
|
|
51
|
+
category['children'].each do |child|
|
|
52
|
+
if child[0] == 'dataCategories'
|
|
53
|
+
child[1].each do |child_cat|
|
|
54
|
+
category_data[:children] << parse_json_profile_category(child_cat)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
if child[0] == 'profileItems' && child[1]['rows']
|
|
58
|
+
child[1]['rows'].each do |child_item|
|
|
59
|
+
category_data[:items] << parse_json_profile_item(child_item)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
return category_data
|
|
65
|
+
end
|
|
66
|
+
|
|
18
67
|
def self.from_json(json)
|
|
19
68
|
# Parse json
|
|
20
69
|
doc = JSON.parse(json)
|
|
@@ -27,11 +76,7 @@ module AMEE
|
|
|
27
76
|
data[:children] = []
|
|
28
77
|
if doc['children'] && doc['children']['dataCategories']
|
|
29
78
|
doc['children']['dataCategories'].each do |child|
|
|
30
|
-
|
|
31
|
-
category_data[:name] = child['name']
|
|
32
|
-
category_data[:path] = child['path']
|
|
33
|
-
category_data[:uid] = child['uid']
|
|
34
|
-
data[:children] << category_data
|
|
79
|
+
data[:children] << parse_json_profile_category(child)
|
|
35
80
|
end
|
|
36
81
|
end
|
|
37
82
|
data[:items] = []
|
|
@@ -39,31 +84,61 @@ module AMEE
|
|
|
39
84
|
profile_items.concat doc['children']['profileItems']['rows'] rescue nil
|
|
40
85
|
profile_items << doc['profileItem'] unless doc['profileItem'].nil?
|
|
41
86
|
profile_items.each do |item|
|
|
42
|
-
|
|
43
|
-
item_data[:values] = {}
|
|
44
|
-
item.each_pair do |key, value|
|
|
45
|
-
case key
|
|
46
|
-
when 'dataItemLabel', 'dataItemUid', 'name', 'path', 'uid'
|
|
47
|
-
item_data[key.to_sym] = value
|
|
48
|
-
when 'created', 'modified', 'label' # ignore these
|
|
49
|
-
nil
|
|
50
|
-
when 'validFrom'
|
|
51
|
-
item_data[:validFrom] = DateTime.strptime(value, "%Y%m%d")
|
|
52
|
-
when 'end'
|
|
53
|
-
item_data[:end] = (value == "true")
|
|
54
|
-
when 'amountPerMonth'
|
|
55
|
-
item_data[:amountPerMonth] = value.to_f
|
|
56
|
-
else
|
|
57
|
-
item_data[:values][key.to_sym] = value
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
item_data[:path] ||= item_data[:uid] # Fill in path if not retrieved from response
|
|
61
|
-
data[:items] << item_data
|
|
87
|
+
data[:items] << parse_json_profile_item(item)
|
|
62
88
|
end
|
|
63
89
|
# Create object
|
|
64
90
|
Category.new(data)
|
|
65
|
-
rescue
|
|
66
|
-
|
|
91
|
+
#rescue
|
|
92
|
+
# raise AMEE::BadData.new("Couldn't load ProfileCategory from JSON data. Check that your URL is correct.")
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def self.parse_xml_profile_item(item)
|
|
96
|
+
item_data = {}
|
|
97
|
+
item_data[:values] = {}
|
|
98
|
+
item.elements.each do |element|
|
|
99
|
+
key = element.name
|
|
100
|
+
value = element.text
|
|
101
|
+
case key.downcase
|
|
102
|
+
when 'dataitemlabel', 'dataitemuid', 'name', 'path'
|
|
103
|
+
item_data[key.to_sym] = value
|
|
104
|
+
when 'validfrom'
|
|
105
|
+
item_data[:validFrom] = DateTime.strptime(value, "%Y%m%d")
|
|
106
|
+
when 'end'
|
|
107
|
+
item_data[:end] = (value == "true")
|
|
108
|
+
when 'amountpermonth'
|
|
109
|
+
item_data[:amountPerMonth] = value.to_f
|
|
110
|
+
else
|
|
111
|
+
item_data[:values][key.to_sym] = value
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
item_data[:uid] = item.attributes['uid'].to_s
|
|
115
|
+
item_data[:path] ||= item_data[:uid] # Fill in path if not retrieved from response
|
|
116
|
+
return item_data
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def self.parse_xml_profile_category(category)
|
|
120
|
+
category_data = {}
|
|
121
|
+
category_data[:name] = category.elements['DataCategory'].elements['Name'].text
|
|
122
|
+
category_data[:path] = category.elements['DataCategory'].elements['Path'].text
|
|
123
|
+
category_data[:uid] = category.elements['DataCategory'].attributes['uid'].to_s
|
|
124
|
+
category_data[:totalAmountPerMonth] = category.elements['TotalAmountPerMonth'].text.to_f rescue nil
|
|
125
|
+
category_data[:children] = []
|
|
126
|
+
category_data[:items] = []
|
|
127
|
+
if category.elements['Children']
|
|
128
|
+
category.elements['Children'].each do |child|
|
|
129
|
+
if child.name == 'ProfileCategories'
|
|
130
|
+
child.each do |child_cat|
|
|
131
|
+
category_data[:children] << parse_xml_profile_category(child_cat)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
if child.name == 'ProfileItems'
|
|
135
|
+
child.each do |child_item|
|
|
136
|
+
category_data[:items] << parse_xml_profile_item(child_item)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
return category_data
|
|
67
142
|
end
|
|
68
143
|
|
|
69
144
|
def self.from_xml(xml)
|
|
@@ -83,29 +158,15 @@ module AMEE
|
|
|
83
158
|
category_data[:uid] = child.attributes['uid'].to_s
|
|
84
159
|
data[:children] << category_data
|
|
85
160
|
end
|
|
161
|
+
REXML::XPath.each(doc, '/Resources/ProfileCategoryResource/Children/ProfileCategories/ProfileCategory') do |child|
|
|
162
|
+
data[:children] << parse_xml_profile_category(child)
|
|
163
|
+
end
|
|
86
164
|
data[:items] = []
|
|
87
|
-
REXML::XPath.each(doc, '
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
value = element.text
|
|
93
|
-
case key.downcase
|
|
94
|
-
when 'dataitemlabel', 'dataitemuid', 'name', 'path'
|
|
95
|
-
item_data[key.to_sym] = value
|
|
96
|
-
when 'validfrom'
|
|
97
|
-
item_data[:validFrom] = DateTime.strptime(value, "%Y%m%d")
|
|
98
|
-
when 'end'
|
|
99
|
-
item_data[:end] = (value == "true")
|
|
100
|
-
when 'amountpermonth'
|
|
101
|
-
item_data[:amountPerMonth] = value.to_f
|
|
102
|
-
else
|
|
103
|
-
item_data[:values][key.to_sym] = value
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
item_data[:uid] = item.attributes['uid'].to_s
|
|
107
|
-
item_data[:path] ||= item_data[:uid] # Fill in path if not retrieved from response
|
|
108
|
-
data[:items] << item_data
|
|
165
|
+
REXML::XPath.each(doc, '/Resources/ProfileCategoryResource/Children/ProfileItems/ProfileItem') do |item|
|
|
166
|
+
data[:items] << parse_xml_profile_item(item)
|
|
167
|
+
end
|
|
168
|
+
REXML::XPath.each(doc, '/Resources/ProfileCategoryResource/ProfileItem') do |item|
|
|
169
|
+
data[:items] << parse_xml_profile_item(item)
|
|
109
170
|
end
|
|
110
171
|
# Create object
|
|
111
172
|
Category.new(data)
|
|
@@ -152,12 +213,14 @@ module AMEE
|
|
|
152
213
|
end
|
|
153
214
|
|
|
154
215
|
|
|
155
|
-
def self.get(connection, path, for_date = Date.today, items_per_page = 10)
|
|
216
|
+
def self.get(connection, path, for_date = Date.today, items_per_page = 10, recurse = false)
|
|
156
217
|
# Load data from path
|
|
157
|
-
|
|
218
|
+
options = {:profileDate => for_date.strftime("%Y%m"), :itemsPerPage => items_per_page}
|
|
219
|
+
options[:recurse] = true if recurse == true
|
|
220
|
+
response = connection.get(path, options)
|
|
158
221
|
return Category.parse(connection, response)
|
|
159
|
-
rescue
|
|
160
|
-
|
|
222
|
+
#rescue
|
|
223
|
+
# raise AMEE::BadData.new("Couldn't load ProfileCategory. Check that your URL is correct.")
|
|
161
224
|
end
|
|
162
225
|
|
|
163
226
|
def child(child_path)
|
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: 0.4.
|
|
4
|
+
version: 0.4.29
|
|
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-02-02 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|