Object
# File lib/fog/rackspace/storage.rb, line 79 def initialize(options={}) require 'mime/types' require 'multi_json' @rackspace_api_key = options[:rackspace_api_key] @rackspace_username = options[:rackspace_username] @rackspace_cdn_ssl = options[:rackspace_cdn_ssl] @rackspace_auth_url = options[:rackspace_auth_url] @connection_options = options[:connection_options] || {} credentials = Fog::Rackspace.authenticate(options, @connection_options) @auth_token = credentials['X-Auth-Token'] uri = URI.parse(credentials['X-Storage-Url']) @host = options[:rackspace_servicenet] == true ? "snet-#{uri.host}" : uri.host @path = uri.path @persistent = options[:persistent] || false @port = uri.port @scheme = uri.scheme Excon.ssl_verify_peer = false if options[:rackspace_servicenet] == true @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end
Delete an existing container
name<~String> - Name of container to delete
# File lib/fog/rackspace/requests/storage/delete_container.rb, line 11 def delete_container(name) request( :expects => 204, :method => 'DELETE', :path => Fog::Rackspace.escape(name) ) end
Delete an existing container
container<~String> - Name of container to delete
object<~String> - Name of object to delete
# File lib/fog/rackspace/requests/storage/delete_object.rb, line 12 def delete_object(container, object) request( :expects => 204, :method => 'DELETE', :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" ) end
Get details for container and total bytes stored
container<~String> - Name of container to retrieve info for
options<~String>:
'limit'<~String> - Maximum number of objects to return
'marker'<~String> - Only return objects whose name is greater than marker
'prefix'<~String> - Limits results to those starting with prefix
'path'<~String> - Return objects nested in the pseudo path
response<~Excon::Response>:
headers<~Hash>:
'X-Account-Container-Count'<~String> - Count of containers
'X-Account-Bytes-Used'<~String> - Bytes used
body<~Array>:
'bytes'<~Integer> - Number of bytes used by container
'count'<~Integer> - Number of items in container
'name'<~String> - Name of container
item<~Hash>:
'bytes'<~String> - Size of object
'content_type'<~String> Content-Type of object
'hash'<~String> - Hash of object (etag?)
'last_modified'<~String> - Last modified timestamp
'name'<~String> - Name of object
# File lib/fog/rackspace/requests/storage/get_container.rb, line 31 def get_container(container, options = {}) options = options.reject {|key, value| value.nil?} request( :expects => 200, :method => 'GET', :path => Fog::Rackspace.escape(container), :query => {'format' => 'json'}.merge!(options) ) end
List existing storage containers
options<~Hash>:
'limit'<~Integer> - Upper limit to number of results returned
'marker'<~String> - Only return objects with name greater than this value
response<~Excon::Response>:
body<~Array>:
container<~Hash>:
'bytes'<~Integer>: - Number of bytes used by container
'count'<~Integer>: - Number of items in container
'name'<~String>: - Name of container
# File lib/fog/rackspace/requests/storage/get_containers.rb, line 20 def get_containers(options = {}) options = options.reject {|key, value| value.nil?} request( :expects => [200, 204], :method => 'GET', :path => '', :query => {'format' => 'json'}.merge!(options) ) end
Get details for object
container<~String> - Name of container to look in
object<~String> - Name of object to look for
# File lib/fog/rackspace/requests/storage/get_object.rb, line 12 def get_object(container, object, &block) request({ :block => block, :expects => 200, :method => 'GET', :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" }, false, &block) end
List number of objects and total bytes stored
container<~String> - Name of container to retrieve info for
response<~Excon::Response>:
headers<~Hash>:
'X-Container-Object-Count'<~String> - Count of containers
'X-Container-Bytes-Used'<~String> - Bytes used
# File lib/fog/rackspace/requests/storage/head_container.rb, line 16 def head_container(container) request( :expects => 204, :method => 'HEAD', :path => Fog::Rackspace.escape(container), :query => {'format' => 'json'} ) end
List number of containers and total bytes stored
response<~Excon::Response>:
headers<~Hash>:
'X-Account-Container-Count'<~String> - Count of containers
'X-Account-Bytes-Used'<~String> - Bytes used
# File lib/fog/rackspace/requests/storage/head_containers.rb, line 13 def head_containers request( :expects => 204, :method => 'HEAD', :path => '', :query => {'format' => 'json'} ) end
Get headers for object
container<~String> - Name of container to look in
object<~String> - Name of object to look for
# File lib/fog/rackspace/requests/storage/head_object.rb, line 12 def head_object(container, object) request({ :expects => 200, :method => 'HEAD', :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" }, false) end
Create a new container
name<~String> - Name for container, should be < 256 bytes and must not contain '/'
# File lib/fog/rackspace/requests/storage/put_container.rb, line 11 def put_container(name) request( :expects => [201, 202], :method => 'PUT', :path => Fog::Rackspace.escape(name) ) end
Create a new object
container<~String> - Name for container, should be < 256 bytes and must not contain '/'
object<~String> - Name for object
data<~String|File> - data to upload
options<~Hash> - config headers for object. Defaults to {}.
# File lib/fog/rackspace/requests/storage/put_object.rb, line 14 def put_object(container, object, data, options = {}) data = Fog::Storage.parse_data(data) headers = data[:headers].merge!(options) request( :body => data[:body], :expects => 201, :headers => headers, :method => 'PUT', :path => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" ) end
Create a new object
container<~String> - Name for container, should be < 256 bytes and must not contain '/'
object<~String> - Name for object
# File lib/fog/rackspace/requests/storage/put_object_manifest.rb, line 12 def put_object_manifest(container, object) path = "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}" request( :expects => 201, :headers => {'X-Object-Manifest' => path}, :method => 'PUT', :path => path ) end
# File lib/fog/rackspace/storage.rb, line 100 def reload @connection.reset end
# File lib/fog/rackspace/storage.rb, line 104 def request(params, parse_json = true, &block) begin response = @connection.request(params.merge!({ :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :host => @host, :path => "#{@path}/#{params[:path]}", }), &block) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Storage::Rackspace::NotFound.slurp(error) else error end end if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %{application/json} response.body = MultiJson.decode(response.body) end response end
Generated with the Darkfish Rdoc Generator 2.