Floppy-amee 2.0.2 → 2.0.3

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.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rexml/document'
2
+ require 'activesupport'
2
3
 
3
4
  # We don't NEED the JSON gem, but if it's available, use it.
4
5
  begin
@@ -40,9 +41,6 @@ require 'amee/profile_item'
40
41
  require 'amee/drill_down'
41
42
 
42
43
  class Date
43
- def amee2schema
44
- strftime("%Y-%m-%dT%H:%M+0000")
45
- end
46
44
  def amee1_date
47
45
  strftime("%Y%m%d")
48
46
  end
@@ -52,9 +50,6 @@ class Date
52
50
  end
53
51
 
54
52
  class Time
55
- def amee2schema
56
- strftime("%Y-%m-%dT%H:%M+0000")
57
- end
58
53
  def amee1_date
59
54
  strftime("%Y%m%d")
60
55
  end
@@ -307,18 +307,18 @@ module AMEE
307
307
  data = {}
308
308
  data[:profile_uid] = REXML::XPath.first(doc, "/feed/@xml:base").to_s.match("/profiles/(.*?)/")[1]
309
309
  # data[:profile_date] = DateTime.strptime(REXML::XPath.first(doc, "/Resources/ProfileCategoryResource/ProfileDate").text, "%Y%m")
310
- # data[:name] = REXML::XPath.first(doc, '/feed/title').text
310
+ data[:name] = REXML::XPath.first(doc, '/feed/amee:name').text
311
311
  data[:path] = REXML::XPath.first(doc, "/feed/@xml:base").to_s.match("/profiles/.*?(/.*)")[1]
312
312
  data[:total_amount] = REXML::XPath.first(doc, '/feed/amee:totalAmount').text.to_f rescue nil
313
313
  data[:total_amount_unit] = REXML::XPath.first(doc, '/feed/amee:totalAmount/@unit').to_s rescue nil
314
314
  data[:children] = []
315
- # REXML::XPath.each(doc, '/Resources/ProfileCategoryResource/ProfileCategories/DataCategory') do |child|
316
- # category_data = {}
317
- # category_data[:name] = child.elements['Name'].text
318
- # category_data[:path] = child.elements['Path'].text
315
+ REXML::XPath.each(doc, '/feed/amee:categories/amee:category') do |child|
316
+ category_data = {}
317
+ # category_data[:path] = child.text
318
+ category_data[:path] = child.text
319
319
  # category_data[:uid] = child.attributes['uid'].to_s
320
- # data[:children] << category_data
321
- # end
320
+ data[:children] << category_data
321
+ end
322
322
  # REXML::XPath.each(doc, '/Resources/ProfileCategoryResource/Children/ProfileCategories/ProfileCategory') do |child|
323
323
  # data[:children] << parse_xml_profile_category(child)
324
324
  # end
@@ -409,11 +409,11 @@ module AMEE
409
409
  if options[:start_date] && connection.version < 2
410
410
  options[:profileDate] = options[:start_date].amee1_month
411
411
  elsif options[:start_date] && connection.version >= 2
412
- options[:startDate] = options[:start_date].amee2schema
412
+ options[:startDate] = options[:start_date].xmlschema
413
413
  end
414
414
  options.delete(:start_date)
415
415
  if options[:end_date] && connection.version >= 2
416
- options[:endDate] = options[:end_date].amee2schema
416
+ options[:endDate] = options[:end_date].xmlschema
417
417
  end
418
418
  options.delete(:end_date)
419
419
  if options[:duration] && connection.version >= 2
@@ -425,7 +425,7 @@ module AMEE
425
425
  rescue
426
426
  raise AMEE::BadData.new("Couldn't load ProfileCategory. Check that your URL is correct.")
427
427
  end
428
-
428
+
429
429
  def child(child_path)
430
430
  AMEE::Profile::Category.get(connection, "#{full_path}/#{child_path}")
431
431
  end
@@ -217,11 +217,11 @@ module AMEE
217
217
  if options[:start_date] && category.connection.version < 2
218
218
  options[:profileDate] = options[:start_date].amee1_month
219
219
  elsif options[:start_date] && category.connection.version >= 2
220
- options[:startDate] = options[:start_date].amee2schema
220
+ options[:startDate] = options[:start_date].xmlschema
221
221
  end
222
222
  options.delete(:start_date)
223
223
  if options[:end_date] && category.connection.version >= 2
224
- options[:endDate] = options[:end_date].amee2schema
224
+ options[:endDate] = options[:end_date].xmlschema
225
225
  end
226
226
  options.delete(:end_date)
227
227
  if options[:duration] && category.connection.version >= 2
@@ -230,8 +230,8 @@ module AMEE
230
230
  # Load data from path
231
231
  response = connection.get(path, options)
232
232
  return Item.parse(connection, response)
233
- rescue
234
- raise AMEE::BadData.new("Couldn't load ProfileItem. Check that your URL is correct.")
233
+ # rescue
234
+ # raise AMEE::BadData.new("Couldn't load ProfileItem. Check that your URL is correct.")
235
235
  end
236
236
 
237
237
  def self.create(category, data_item_uid, options = {})
@@ -239,6 +239,9 @@ module AMEE
239
239
  end
240
240
 
241
241
  def self.create_without_category(connection, path, data_item_uid, options = {})
242
+ # Do we want to automatically fetch the item afterwards?
243
+ get_item = options.delete(:get_item)
244
+ get_item = true if get_item.nil?
242
245
  # Store format if set
243
246
  format = options[:format]
244
247
  unless options.is_a?(Hash)
@@ -248,11 +251,11 @@ module AMEE
248
251
  if options[:start_date] && connection.version < 2
249
252
  options[:profileDate] = options[:start_date].amee1_month
250
253
  elsif options[:start_date] && connection.version >= 2
251
- options[:startDate] = options[:start_date].amee2schema
254
+ options[:startDate] = options[:start_date].xmlschema
252
255
  end
253
256
  options.delete(:start_date)
254
257
  if options[:end_date] && connection.version >= 2
255
- options[:endDate] = options[:end_date].amee2schema
258
+ options[:endDate] = options[:end_date].xmlschema
256
259
  end
257
260
  options.delete(:end_date)
258
261
  if options[:duration] && connection.version >= 2
@@ -261,9 +264,20 @@ module AMEE
261
264
  # Send data to path
262
265
  options.merge! :dataItemUid => data_item_uid
263
266
  response = connection.post(path, options)
264
- category = Category.parse(connection, response)
265
- options.merge!(:format => format) if format
266
- return category.item(options)
267
+ if response['Location']
268
+ location = response['Location']
269
+ else
270
+ category = Category.parse(connection, response)
271
+ item = category.items.find{ |x| x[:name] == options[:name] || x[:dataItemUid] == data_item_uid }
272
+ location = category.full_path + "/" + item[:path]
273
+ end
274
+ if get_item == true
275
+ options = {}
276
+ options[:format] = format if format
277
+ return AMEE::Profile::Item.get(connection, location, options)
278
+ else
279
+ return location
280
+ end
267
281
  rescue
268
282
  raise AMEE::BadData.new("Couldn't create ProfileItem. Check that your information is correct.")
269
283
  end
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 = 2
6
+ TINY = 3
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.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-20 00:00:00 -08:00
12
+ date: 2009-02-26 00:00:00 -08:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
16
25
  description:
17
26
  email: james@floppy.org.uk
18
27
  executables: