You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2012/08/30 01:37:45 UTC

[PATCH 2/3] CIMI base model: add 'parse' method

From: David Lutterkort <lu...@redhat.com>

Dispatch between from_xml and from_json depending on content type
---
 server/lib/cimi/models/base.rb |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/server/lib/cimi/models/base.rb b/server/lib/cimi/models/base.rb
index 9e4b286..b375ce0 100644
--- a/server/lib/cimi/models/base.rb
+++ b/server/lib/cimi/models/base.rb
@@ -168,6 +168,16 @@ class CIMI::Model::Base
     model
   end
 
+  def self.parse(text, content_type)
+    if content_type == "application/xml"
+      from_xml(text)
+    elsif content_type == "application/json"
+      from_json(text)
+    else
+      raise "Can not parse content type #{content_type}"
+    end
+  end
+
   #
   # Serialize
   #
-- 
1.7.7.6