Sha256: b97f1b5caa6cfcffee6d4c7488116c4d1fbe867bafc88ec031f4a9d8b917f618

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 KB

Contents

module Fog
  module Storage
    class Aliyun
      class Real
        # List existing storage containers
        #
        # ==== Parameters
        # * options<~Hash>:
        #   * 'maxKeys'<~Integer> - Upper limit to number of results returned
        #   * 'marker'<~String> - Only return objects with name greater than this value
        #
        # ==== Returns
        #
        def get_containers(options = {})
          options = options.reject {|key, value| value.nil?}
          bucket = options[:bucket]
          bucket ||= @aliyun_oss_bucket
          prefix = options[:prefix]
          marker = options[:marker]
          maxKeys = options[:maxKeys]
          delimiter = '/'

          path = ""
          if prefix
            path+="?prefix="+prefix
            if marker
              path+="&marker="+marker
            end
            if maxKeys
              path+="&max-keys="+maxKeys
            end
            if delimiter
              path+="&delimiter="+delimiter
            end

          elsif marker
            path+="?marker="+marker
            if maxKeys
              path+="&max-keys="+maxKeys
            end
            if delimiter
              path+="&delimiter="+delimiter
            end

          elsif maxKeys
            path+="?max-keys="+maxKeys
            if delimiter
              path+="&delimiter="+delimiter
            end

          elsif delimiter
            path+="?delimiter="+delimiter
          end

          location = get_bucket_location(bucket)
          endpoint = "http://"+location+".aliyuncs.com"
          resource = bucket+'/'
          ret = request(
              :expects  => [200, 203, 400],
              :method   => 'GET',
              :path     => path,
              :resource => resource,
              :bucket => bucket
          )
          xml = ret.data[:body]
          result = XmlSimple.xml_in(xml)["CommonPrefixes"]
        end
      end

      class Mock
        def get_containers(options = {})
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fog-aliyun-0.1.0 lib/fog/aliyun/requests/storage/get_containers.rb
fog-aliyun-0.0.7 lib/fog/aliyun/requests/storage/get_containers.rb