Floppy-amee 0.4.25 → 0.4.26

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.
@@ -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
- puts "created item in #{category.name} OK"
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
@@ -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
- # Delete profile
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'].each do |child|
29
- category_data = {}
30
- category_data[:name] = child['name']
31
- category_data[:path] = child['path']
32
- category_data[:uid] = child['uid']
33
- data[:children] << category_data
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
- if doc['children']['profileItems']['rows']
37
- doc['children']['profileItems']['rows'].each do |item|
38
- item_data = {}
39
- item_data[:values] = {}
40
- item.each_pair do |key, value|
41
- case key
42
- when 'dataItemLabel', 'dataItemUid', 'name', 'path', 'uid'
43
- item_data[key.to_sym] = value
44
- when 'created', 'modified', 'label' # ignore these
45
- nil
46
- when 'validFrom'
47
- item_data[:validFrom] = DateTime.strptime(value, "%Y%m%d")
48
- when 'end'
49
- item_data[:end] = (value == "true")
50
- when 'amountPerMonth'
51
- item_data[:amountPerMonth] = value.to_f
52
- else
53
- item_data[:values][key.to_sym] = value
54
- end
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, '/Resources/ProfileCategoryResource/Children/ProfileItems/ProfileItem') do |item|
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 'dataItemLabel', 'dataItemUid', 'name', 'path'
93
+ case key.downcase
94
+ when 'dataitemlabel', 'dataitemuid', 'name', 'path'
91
95
  item_data[key.to_sym] = value
92
- when 'validFrom'
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 'amountPerMonth'
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.get(connection, path, for_date = Date.today, items_per_page = 10)
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
@@ -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
- return Item.parse(profile.connection, response)
107
- rescue
108
- raise AMEE::BadData.new("Couldn't create ProfileItem. Check that your information is correct.")
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
@@ -3,7 +3,7 @@ module AMEE
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
5
  MINOR = 4
6
- TINY = 25
6
+ TINY = 26
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
9
9
 
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.25
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-23 00:00:00 -08:00
12
+ date: 2009-01-28 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15