incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r1136804 - in /incubator/deltacloud/trunk/server: lib/deltacloud/helpers/conversion_helper.rb lib/deltacloud/models/bucket.rb server.rb
Date Fri, 17 Jun 2011 08:30:26 GMT
Author: marios
Date: Fri Jun 17 08:30:26 2011
New Revision: 1136804

URL: http://svn.apache.org/viewvc?rev=1136804&view=rev
Log:
Improve json support for blobs

Signed-off-by: marios <marios@redhat.com>

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/helpers/conversion_helper.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/models/bucket.rb
    incubator/deltacloud/trunk/server/server.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/conversion_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/conversion_helper.rb?rev=1136804&r1=1136803&r2=1136804&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/conversion_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/conversion_helper.rb Fri Jun
17 08:30:26 2011
@@ -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

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/models/bucket.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/models/bucket.rb?rev=1136804&r1=1136803&r2=1136804&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/models/bucket.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/models/bucket.rb Fri Jun 17 08:30:26
2011
@@ -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

Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=1136804&r1=1136803&r2=1136804&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Fri Jun 17 08:30:26 2011
@@ -714,7 +714,7 @@ put "#{Sinatra::UrlForHelper::DEFAULT_UR
     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
   elsif(env["BLOB_FAIL"])
     report_error(500) #OK?
@@ -805,7 +805,7 @@ get "#{Sinatra::UrlForHelper::DEFAULT_UR
     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)



Mime
View raw message