lib/amee/profile_item.rb in Floppy-amee-2.0.7 vs lib/amee/profile_item.rb in Floppy-amee-2.0.8
- old
+ new
@@ -226,11 +226,11 @@
options.delete(:end_date)
if options[:duration] && category.connection.version >= 2
options[:duration] = "PT#{options[:duration] * 86400}S"
end
# Load data from path
- response = connection.get(path, options)
+ response = connection.get(path, options).body
return Item.parse(connection, response)
rescue
raise AMEE::BadData.new("Couldn't load ProfileItem. Check that your URL is correct.")
end
@@ -263,13 +263,13 @@
end
# Send data to path
options.merge! :dataItemUid => data_item_uid
response = connection.post(path, options)
if response['Location']
- location = response['Location']
+ location = response['Location'].match("http://.*?(/.*)")[1]
else
- category = Category.parse(connection, response)
+ category = Category.parse(connection, response.body)
location = category.full_path + "/" + category.items[0][:path]
end
if get_item == true
get_options = {}
get_options[:returnUnit] = options[:returnUnit] if options[:returnUnit]
@@ -281,10 +281,14 @@
end
rescue
raise AMEE::BadData.new("Couldn't create ProfileItem. Check that your information is correct.")
end
+ def self.create_batch(category, items)
+ create_batch_without_category(category.connection, category.full_path, items)
+ end
+
def self.create_batch_without_category(connection, category_path, items)
if connection.format == :json
post_data = ({:profileItems => items}).to_json
else
post_data = ({:ProfileItems => items}).to_xml(:root => "ProfileCategory", :skip_types => true, :skip_nil => true)
@@ -294,17 +298,43 @@
# Send back a category object containing all the created items
AMEE::Profile::Category.parse(connection, response)
end
def self.update(connection, path, options = {})
+ # Do we want to automatically fetch the item afterwards?
+ get_item = options.delete(:get_item)
+ get_item = true if get_item.nil?
+ # Go
response = connection.put(path, options)
- return Item.parse(connection, response)
+ if get_item
+ if response.body.empty?
+ return Item.get(connection, path)
+ else
+ return Item.parse(connection, response.body)
+ end
+ end
rescue
raise AMEE::BadData.new("Couldn't update ProfileItem. Check that your information is correct.")
end
def update(options = {})
AMEE::Profile::Item.update(connection, full_path, options)
+ end
+
+ def self.update_batch(category, items)
+ update_batch_without_category(category.connection, category.full_path, items)
+ end
+
+ def self.update_batch_without_category(connection, category_path, items)
+ if connection.format == :json
+ put_data = ({:profileItems => items}).to_json
+ else
+ put_data = ({:ProfileItems => items}).to_xml(:root => "ProfileCategory", :skip_types => true, :skip_nil => true)
+ end
+ # Post to category
+ response = connection.raw_put(category_path, put_data)
+ # Send back a category object containing all the created items
+ AMEE::Profile::Category.parse(connection, response)
end
def self.delete(connection, path)
connection.delete(path)
rescue