Floppy-amee 2.0.5 → 2.0.6

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.
@@ -36,6 +36,7 @@ module AMEE
36
36
  end
37
37
 
38
38
  def version
39
+ authenticate if @version.nil?
39
40
  @version
40
41
  end
41
42
 
@@ -81,6 +82,19 @@ module AMEE
81
82
  do_request(post, format)
82
83
  end
83
84
 
85
+ def raw_post(path, body, options = {})
86
+ # Allow format override
87
+ format = options.delete(:format) || @format
88
+ # Clear cache
89
+ clear_cache
90
+ # Create POST request
91
+ post = Net::HTTP::Post.new(path)
92
+ post['Content-type'] = options[:content_type] || content_type(format)
93
+ post.body = body
94
+ # Send request
95
+ do_request(post, format)
96
+ end
97
+
84
98
  def put(path, data = {})
85
99
  # Allow format override
86
100
  format = data.delete(:format) || @format
@@ -97,6 +111,19 @@ module AMEE
97
111
  do_request(put, format)
98
112
  end
99
113
 
114
+ def raw_put(path, body, options = {})
115
+ # Allow format override
116
+ format = options.delete(:format) || @format
117
+ # Clear cache
118
+ clear_cache
119
+ # Create PUT request
120
+ put = Net::HTTP::Put.new(path)
121
+ put['Content-type'] = options[:content_type] || content_type(format)
122
+ put.body = body
123
+ # Send request
124
+ do_request(put, format)
125
+ end
126
+
100
127
  def delete(path)
101
128
  clear_cache
102
129
  # Create DELETE request
@@ -184,6 +211,8 @@ module AMEE
184
211
  response
185
212
  end
186
213
 
214
+ public
215
+
187
216
  def clear_cache
188
217
  if @enable_caching
189
218
  $cache = {}
@@ -7,6 +7,7 @@ module AMEE
7
7
  @choices = data[:choices]
8
8
  @label = data[:label]
9
9
  @item_definition = data[:item_definition]
10
+ @total_amount = data[:total_amount]
10
11
  super
11
12
  end
12
13
 
@@ -14,6 +15,7 @@ module AMEE
14
15
  attr_reader :choices
15
16
  attr_reader :label
16
17
  attr_reader :item_definition
18
+ attr_reader :total_amount
17
19
 
18
20
  def self.from_json(json)
19
21
  # Read JSON
@@ -26,6 +28,7 @@ module AMEE
26
28
  data[:path] = doc['path']
27
29
  data[:label] = doc['dataItem']['label']
28
30
  data[:item_definition] = doc['dataItem']['itemDefinition']['uid']
31
+ data[:total_amount] = doc['amountPerMonth']
29
32
  # Get values
30
33
  data[:values] = []
31
34
  doc['dataItem']['itemValues'].each do |value|
@@ -57,17 +60,18 @@ module AMEE
57
60
  data[:uid] = REXML::XPath.first(doc, "/Resources/DataItemResource/DataItem/@uid").to_s
58
61
  data[:created] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataItemResource/DataItem/@created").to_s)
59
62
  data[:modified] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataItemResource/DataItem/@modified").to_s)
60
- data[:name] = REXML::XPath.first(doc, '/Resources/DataItemResource/DataItem/Name').text
61
- data[:path] = REXML::XPath.first(doc, '/Resources/DataItemResource/Path').text
62
- data[:label] = REXML::XPath.first(doc, '/Resources/DataItemResource/DataItem/Label').text
63
+ data[:name] = (REXML::XPath.first(doc, '/Resources/DataItemResource/DataItem/Name') || REXML::XPath.first(doc, '/Resources/DataItemResource/DataItem/name')).text
64
+ data[:path] = (REXML::XPath.first(doc, '/Resources/DataItemResource/Path') || REXML::XPath.first(doc, '/Resources/DataItemResource/DataItem/path')).text
65
+ data[:label] = (REXML::XPath.first(doc, '/Resources/DataItemResource/DataItem/Label') || REXML::XPath.first(doc, '/Resources/DataItemResource/DataItem/label')).text
63
66
  data[:item_definition] = REXML::XPath.first(doc, '/Resources/DataItemResource/DataItem/ItemDefinition/@uid').to_s
67
+ data[:total_amount] = REXML::XPath.first(doc, '/Resources/DataItemResource/AmountPerMonth').text.to_f
64
68
  # Get values
65
69
  data[:values] = []
66
70
  REXML::XPath.each(doc, '/Resources/DataItemResource/DataItem/ItemValues/ItemValue') do |value|
67
71
  value_data = {}
68
- value_data[:name] = value.elements['Name'].text
69
- value_data[:path] = value.elements['Path'].text
70
- value_data[:value] = value.elements['Value'].text
72
+ value_data[:name] = (value.elements['Name'] || value.elements['name']).text
73
+ value_data[:path] = (value.elements['Path'] || value.elements['path']).text
74
+ value_data[:value] = (value.elements['Value'] || value.elements['value']).text
71
75
  value_data[:uid] = value.attributes['uid'].to_s
72
76
  data[:values] << value_data
73
77
  end
@@ -75,20 +79,20 @@ module AMEE
75
79
  data[:choices] = []
76
80
  REXML::XPath.each(doc, '/Resources/DataItemResource/Choices/Choices/Choice') do |choice|
77
81
  choice_data = {}
78
- choice_data[:name] = choice.elements['Name'].text
79
- choice_data[:value] = choice.elements['Value'].text || ""
82
+ choice_data[:name] = (choice.elements['Name']).text
83
+ choice_data[:value] = (choice.elements['Value']).text || ""
80
84
  data[:choices] << choice_data
81
85
  end
82
86
  # Create object
83
87
  Item.new(data)
84
- rescue
88
+ rescue
85
89
  raise AMEE::BadData.new("Couldn't load DataItem from XML. Check that your URL is correct.")
86
90
  end
87
91
 
88
92
 
89
- def self.get(connection, path)
93
+ def self.get(connection, path, options = {})
90
94
  # Load data from path
91
- response = connection.get(path)
95
+ response = connection.get(path, options)
92
96
  # Parse data from response
93
97
  if response.is_json?
94
98
  item = Item.from_json(response)
@@ -90,7 +90,7 @@ module AMEE
90
90
  doc = JSON.parse(json)
91
91
  data = {}
92
92
  data[:profile_uid] = doc['profile']['uid']
93
- data[:profile_date] = DateTime.strptime(doc['profileDate'], "%Y%m")
93
+ data[:profile_date] = DateTime.strptime(doc['profileDate'], "%Y%m") rescue nil
94
94
  data[:name] = doc['dataCategory']['name']
95
95
  data[:path] = doc['path']
96
96
  data[:total_amount] = doc['totalAmountPerMonth']
@@ -152,6 +152,8 @@ module AMEE
152
152
  case key.downcase
153
153
  when 'dataitemlabel', 'dataitemuid', 'name', 'path'
154
154
  item_data[key.to_sym] = value
155
+ when 'dataitem'
156
+ item_data[:dataItemUid] = element.attributes['uid']
155
157
  when 'validfrom'
156
158
  item_data[:validFrom] = DateTime.strptime(value, "%Y%m%d")
157
159
  when 'end'
@@ -221,6 +223,9 @@ module AMEE
221
223
  REXML::XPath.each(doc, '/Resources/ProfileCategoryResource/ProfileItem') do |item|
222
224
  data[:items] << parse_xml_profile_item(item)
223
225
  end
226
+ REXML::XPath.each(doc, '/Resources/ProfileCategoryResource/ProfileItems/ProfileItem') do |item|
227
+ data[:items] << parse_xml_profile_item(item)
228
+ end
224
229
  # Create object
225
230
  Category.new(data)
226
231
  rescue
@@ -295,6 +300,9 @@ module AMEE
295
300
  REXML::XPath.each(doc, '/Resources/ProfileCategoryResource/ProfileItem') do |item|
296
301
  data[:items] << parse_v2_xml_profile_item(item)
297
302
  end
303
+ REXML::XPath.each(doc, '/Resources/ProfileCategoryResource/ProfileItems/ProfileItem') do |item|
304
+ data[:items] << parse_v2_xml_profile_item(item)
305
+ end
298
306
  # Create object
299
307
  Category.new(data)
300
308
  rescue
@@ -283,6 +283,18 @@ 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_without_category(connection, category_path, items)
287
+ if connection.format == :json
288
+ post_data = ({:profileItems => items}).to_json
289
+ else
290
+ post_data = ({:ProfileItems => items}).to_xml(:root => "ProfileCategory", :skip_types => true, :skip_nil => true)
291
+ end
292
+ # Post to category
293
+ response = connection.raw_post(category_path, post_data)
294
+ # Send back a category object containing all the created items
295
+ AMEE::Profile::Category.parse(connection, response)
296
+ end
297
+
286
298
  def self.update(connection, path, options = {})
287
299
  response = connection.put(path, options)
288
300
  return Item.parse(connection, response)
data/lib/amee/version.rb CHANGED
@@ -3,7 +3,7 @@ module AMEE
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 2
5
5
  MINOR = 0
6
- TINY = 5
6
+ TINY = 6
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: 2.0.5
4
+ version: 2.0.6
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-02-27 00:00:00 -08:00
12
+ date: 2009-03-04 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency