Floppy-amee 0.4.25 → 0.4.26
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/create_profile_item.rb +6 -2
- data/lib/amee/connection.rb +9 -0
- data/lib/amee/profile.rb +4 -1
- data/lib/amee/profile_category.rb +44 -34
- data/lib/amee/profile_item.rb +4 -3
- data/lib/amee/version.rb +1 -1
- metadata +2 -2
@@ -25,5 +25,9 @@ connection = AMEE::Connection.new(options[:server], options[:username], options[
|
|
25
25
|
# Create a new profile item
|
26
26
|
category = AMEE::Profile::Category.get(connection, ARGV[0])
|
27
27
|
puts "loaded category #{category.name}"
|
28
|
-
AMEE::Profile::Item.create(category, ARGV[1])
|
29
|
-
|
28
|
+
item = AMEE::Profile::Item.create(category, ARGV[1])
|
29
|
+
if item
|
30
|
+
puts "created item in #{category.name} OK"
|
31
|
+
else
|
32
|
+
puts "error creating item in #{category.name}"
|
33
|
+
end
|
data/lib/amee/connection.rb
CHANGED
@@ -18,8 +18,17 @@ module AMEE
|
|
18
18
|
end
|
19
19
|
# Make connection to server
|
20
20
|
@http = Net::HTTP.new(@server)
|
21
|
+
@http.read_timeout = 5
|
21
22
|
@http.set_debug_output($stdout) if enable_debug
|
22
23
|
end
|
24
|
+
|
25
|
+
def timeout
|
26
|
+
@http.read_timeout
|
27
|
+
end
|
28
|
+
|
29
|
+
def timeout=(t)
|
30
|
+
@http.read_timeout = t
|
31
|
+
end
|
23
32
|
|
24
33
|
def valid?
|
25
34
|
!((@username || @password) ? (@username.nil? || @password.nil? || @server.nil?) : @server.nil?)
|
data/lib/amee/profile.rb
CHANGED
@@ -86,8 +86,11 @@ module AMEE
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def self.delete(connection, uid)
|
89
|
-
#
|
89
|
+
# Deleting profiles takes a while... up the timeout to 60 seconds temporarily
|
90
|
+
t = connection.timeout
|
91
|
+
connection.timeout = 60
|
90
92
|
connection.delete("/profiles/#{uid}")
|
93
|
+
connection.timeout = t
|
91
94
|
end
|
92
95
|
|
93
96
|
end
|
@@ -25,36 +25,40 @@ module AMEE
|
|
25
25
|
data[:path] = doc['path']
|
26
26
|
data[:total_amount_per_month] = doc['totalAmountPerMonth']
|
27
27
|
data[:children] = []
|
28
|
-
doc['children']['dataCategories']
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
if doc['children'] && doc['children']['dataCategories']
|
29
|
+
doc['children']['dataCategories'].each do |child|
|
30
|
+
category_data = {}
|
31
|
+
category_data[:name] = child['name']
|
32
|
+
category_data[:path] = child['path']
|
33
|
+
category_data[:uid] = child['uid']
|
34
|
+
data[:children] << category_data
|
35
|
+
end
|
34
36
|
end
|
35
37
|
data[:items] = []
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
38
|
+
profile_items = []
|
39
|
+
profile_items.concat doc['children']['profileItems']['rows'] rescue nil
|
40
|
+
profile_items << doc['profileItem'] unless doc['profileItem'].nil?
|
41
|
+
profile_items.each do |item|
|
42
|
+
item_data = {}
|
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
|
55
58
|
end
|
56
|
-
data[:items] << item_data
|
57
59
|
end
|
60
|
+
item_data[:path] ||= item_data[:uid] # Fill in path if not retrieved from response
|
61
|
+
data[:items] << item_data
|
58
62
|
end
|
59
63
|
# Create object
|
60
64
|
Category.new(data)
|
@@ -80,26 +84,27 @@ module AMEE
|
|
80
84
|
data[:children] << category_data
|
81
85
|
end
|
82
86
|
data[:items] = []
|
83
|
-
REXML::XPath.each(doc, '
|
87
|
+
REXML::XPath.each(doc, '//ProfileItem') do |item|
|
84
88
|
item_data = {}
|
85
89
|
item_data[:values] = {}
|
86
90
|
item.elements.each do |element|
|
87
91
|
key = element.name
|
88
92
|
value = element.text
|
89
|
-
case key
|
90
|
-
when '
|
93
|
+
case key.downcase
|
94
|
+
when 'dataitemlabel', 'dataitemuid', 'name', 'path'
|
91
95
|
item_data[key.to_sym] = value
|
92
|
-
when '
|
96
|
+
when 'validfrom'
|
93
97
|
item_data[:validFrom] = DateTime.strptime(value, "%Y%m%d")
|
94
98
|
when 'end'
|
95
99
|
item_data[:end] = (value == "true")
|
96
|
-
when '
|
100
|
+
when 'amountpermonth'
|
97
101
|
item_data[:amountPerMonth] = value.to_f
|
98
102
|
else
|
99
103
|
item_data[:values][key.to_sym] = value
|
100
104
|
end
|
101
105
|
end
|
102
106
|
item_data[:uid] = item.attributes['uid'].to_s
|
107
|
+
item_data[:path] ||= item_data[:uid] # Fill in path if not retrieved from response
|
103
108
|
data[:items] << item_data
|
104
109
|
end
|
105
110
|
# Create object
|
@@ -133,9 +138,7 @@ module AMEE
|
|
133
138
|
return history.reverse
|
134
139
|
end
|
135
140
|
|
136
|
-
def self.
|
137
|
-
# Load data from path
|
138
|
-
response = connection.get(path, :profileDate => for_date.strftime("%Y%m"), :itemsPerPage => items_per_page)
|
141
|
+
def self.parse(connection, response)
|
139
142
|
# Parse data from response
|
140
143
|
if response.is_json?
|
141
144
|
cat = Category.from_json(response)
|
@@ -146,6 +149,13 @@ module AMEE
|
|
146
149
|
cat.connection = connection
|
147
150
|
# Done
|
148
151
|
return cat
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
def self.get(connection, path, for_date = Date.today, items_per_page = 10)
|
156
|
+
# Load data from path
|
157
|
+
response = connection.get(path, :profileDate => for_date.strftime("%Y%m"), :itemsPerPage => items_per_page)
|
158
|
+
return Category.parse(connection, response)
|
149
159
|
rescue
|
150
160
|
raise AMEE::BadData.new("Couldn't load ProfileCategory. Check that your URL is correct.")
|
151
161
|
end
|
data/lib/amee/profile_item.rb
CHANGED
@@ -103,9 +103,10 @@ module AMEE
|
|
103
103
|
# Send data to path
|
104
104
|
options.merge! :dataItemUid => data_item_uid
|
105
105
|
response = profile.connection.post(profile.full_path, options)
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
category = Category.parse(profile.connection, response)
|
107
|
+
return category.item(options)
|
108
|
+
#rescue
|
109
|
+
# raise AMEE::BadData.new("Couldn't create ProfileItem. Check that your information is correct.")
|
109
110
|
end
|
110
111
|
|
111
112
|
def update(options = {})
|
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.26
|
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-01-
|
12
|
+
date: 2009-01-28 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|