lib/amee/data_item_value.rb in amee-2.0.35 vs lib/amee/data_item_value.rb in amee-2.2.0
- old
+ new
@@ -28,15 +28,15 @@
end
def from_profile?
@from_profile
end
-
+
def from_data?
@from_data
end
-
+
attr_accessor :start_date
attr_accessor :uid
def uid_path
# create a path which is safe for DIVHs by using the UID if one is avai
@@ -63,14 +63,14 @@
data[:value] = doc['value']
data[:type] = doc['itemValueDefinition']['valueDefinition']['valueType']
data[:start_date] = DateTime.parse(doc['startDate']) rescue nil
# Create object
ItemValue.new(data)
- rescue
+ rescue
raise AMEE::BadData.new("Couldn't load DataItemValue from JSON. Check that your URL is correct.\n#{json}")
end
-
+
def self.from_xml(xml, path)
# Read XML
doc = xml.is_a?(String) ? REXML::Document.new(xml) : xml
data = {}
if REXML::XPath.match(doc,"descendant-or-self::ItemValue").length>1
@@ -133,11 +133,11 @@
ItemValue.create(data_item,
@path.split(/\//).pop.to_sym => value,:get_item=>false)
end
end
- def self.parse(connection, response, path)
+ def self.parse(connection, response, path)
if response.is_json?
value = ItemValue.from_json(response, path)
else
value = ItemValue.from_xml(response, path)
end
@@ -146,30 +146,30 @@
# Done
return value
rescue
raise AMEE::BadData.new("Couldn't load DataItemValue. Check that your URL is correct.\n#{response}")
end
-
+
def self.create(data_item, options = {})
# Do we want to automatically fetch the item afterwards?
get_item = options.delete(:get_item)
get_item = true if get_item.nil?
# Store format if set
format = options[:format]
unless options.is_a?(Hash)
raise AMEE::ArgumentError.new("Third argument must be a hash of options!")
end
-
+
# Set startDate
if (options[:start_date])
options[:startDate] = options[:start_date].xmlschema
options.delete(:start_date)
end
response = data_item.connection.post(data_item.full_path, options)
- location = response['Location'].match("http://.*?(/.*)")[1]
+ location = response['Location'].match("https??://.*?(/.*)")[1]
if get_item == true
get_options = {}
get_options[:format] = format if format
return AMEE::Data::ItemValue.get(data_item.connection, location)
else
@@ -198,20 +198,20 @@
end
end
rescue
raise AMEE::BadData.new("Couldn't update DataItemValue. Check that your information is correct.\n#{response}")
end
-
+
def update(options = {})
AMEE::Data::ItemValue.update(connection, full_path, options)
end
def self.delete(connection, path)
connection.delete(path)
rescue
raise AMEE::BadData.new("Couldn't delete DataItemValue. Check that your information is correct.")
- end
-
+ end
+
end
end
end