deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@redhat.com
Subject [PATCH 2/3] CIMI base model: add 'parse' method
Date Wed, 29 Aug 2012 23:37:45 GMT
From: David Lutterkort <lutter@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


Mime
View raw message