incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH 3/3] Improve json support for blobs
Date Fri, 10 Jun 2011 14:43:56 GMT
From: marios <marios@redhat.com>


Signed-off-by: marios <marios@redhat.com>
---
 server/lib/deltacloud/helpers/conversion_helper.rb |    8 ++++++--
 server/lib/deltacloud/models/bucket.rb             |    6 ++++--
 server/server.rb                                   |    2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/server/lib/deltacloud/helpers/conversion_helper.rb b/server/lib/deltacloud/helpers/conversion_helper.rb
index 9a33482..4afbc0e 100644
--- a/server/lib/deltacloud/helpers/conversion_helper.rb
+++ b/server/lib/deltacloud/helpers/conversion_helper.rb
@@ -19,7 +19,7 @@ require 'deltacloud/base_driver'
 module ConversionHelper
 
   def convert_to_json(type, obj)
-    if ( [ :image, :realm, :instance, :storage_volume, :storage_snapshot, :hardware_profile,
:key, :bucket, :address ].include?( type ) )
+    if ( [ :image, :realm, :instance, :storage_volume, :storage_snapshot, :hardware_profile,
:key, :bucket, :blob, :firewall, :load_balancer, :address ].include?( type ) )
       if Array.eql?(obj.class)
         data = obj.collect do |o|
           o.to_hash.merge({ :href => self.send(:"#{type}_url", type.eql?(:hardware_profile)
? o.name : o.id ) })
@@ -27,7 +27,11 @@ module ConversionHelper
         type = type.to_s.pluralize
       else
         data = obj.to_hash
-        data.merge!({ :href => self.send(:"#{type}_url", data[:id]) })
+        if type == :blob
+          data.merge!({ :href => self.send(:"bucket_url", "#{data[:bucket]}/#{data[:id]}"
) })
+        else
+          data.merge!({ :href => self.send(:"#{type}_url", data[:id]) })
+        end
       end
       return { :"#{type}" => data }.to_json
     end
diff --git a/server/lib/deltacloud/models/bucket.rb b/server/lib/deltacloud/models/bucket.rb
index bef36ac..d7c984b 100644
--- a/server/lib/deltacloud/models/bucket.rb
+++ b/server/lib/deltacloud/models/bucket.rb
@@ -24,8 +24,10 @@ class Bucket < BaseModel
 
   def to_hash
     h = self.to_hash_original
-    h[:blob_list] = self.blob_list.collect { |blob| { :id => blob,
-      :href => "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/buckets/#{self.id}/#{blob.id}"}}
+    unless blob_list.nil?
+      h[:blob_list] = self.blob_list.collect { |blob| { :id => blob,
+        :href => "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/buckets/#{self.id}/#{blob}"}}
+    end
     return h
   end
 end
diff --git a/server/server.rb b/server/server.rb
index ae23263..6e4342f 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -776,7 +776,7 @@ get "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/buckets/:bucket/:blob"
do
     respond_to do |format|
       format.html { haml :"blobs/show" }
       format.xml { haml :"blobs/show" }
-      format.json { convert_to_json(blobs, @blob) }
+      format.json { convert_to_json(:blob, @blob) }
       end
   else
       report_error(404)
-- 
1.7.3.4


Mime
View raw message