class Fog::Storage::Softlayer::Mock

Public Instance Methods

copy_object(source_container, source_object, target_container, target_object, options={}) click to toggle source
# File lib/fog/softlayer/requests/storage/copy_object.rb, line 5
def copy_object(source_container, source_object, target_container, target_object, options={})
  response = Excon::Response.new
  if @containers[source_container].nil? || @containers[source_container][source_object].nil? || @containers[target_container].nil?
    response.body = '<html><h1>Not Found</h1><p>The resource could not be found.</p></html>'
    response.status = 404
  else # Success
    @containers[target_container][target_object] = @containers[source_container][source_object]
    response.body = ''
    response.status = 201
  end
  response
end
delete_container(name) click to toggle source
# File lib/fog/softlayer/requests/storage/delete_container.rb, line 5
def delete_container(name)
  response = Excon::Response.new
  if @containers[name].nil? # Container doesn't exist.
    response.body = '<html><h1>Not Found</h1><p>The resource could not be found.</p></html>'
    response.status = 404
  elsif @containers[name].length > 0  # Container not empty
    response.body = '<html><h1>Conflict</h1><p>There was a conflict when trying to complete your request.</p></html>'
    response.status = 409
  else # Success
    response.body = ''
    response.status = 204
  end
  response
end
delete_object(container, object) click to toggle source
# File lib/fog/softlayer/requests/storage/delete_object.rb, line 6
def delete_object(container, object)
  response = Excon::Response.new
  if @containers[container].nil? || @containers[container][object].nil? # Container or object doesn't exist.
    response.body = '<html><h1>Not Found</h1><p>The resource could not be found.</p></html>'
    response.status = 404
  else # Success
    response.body = ''
    response.status = 204
  end
  response
end
get_container(container, options = {}) click to toggle source
# File lib/fog/softlayer/requests/storage/get_container.rb, line 5
def get_container(container, options = {})
  if @containers[container]
    response = Excon::Response.new
    response.body = @containers[container].map do |name, object|
      {
          'hash' => object.respond_to?(:to_s) ? Digest::MD5.hexdigest(object.to_s) : 'e4d909c290d0fb1ca068ffaddf22cbd0',
          'last_modified' => Time.now,
          'bytes' => Memory.analyze(container).bytes,
          'content/type' => 'application/json'
      }
    end
    response.status = 200
    response
  else
    response = Excon::Response.new
    response.body = '<html><h1>Not Found</h1><p>The resource could not be found.</p></html>'
    response.status = 404
    response.headers = {"Content-Length"=>"70", "Content-Type"=>"text/html; charset=UTF-8", "X-Trans-Id"=>"abcdefghijklmnopqrstuvwx-0123456789", "Date"=>Time.now}
    response
  end
end
get_containers(options = {}) click to toggle source
# File lib/fog/softlayer/requests/storage/get_containers.rb, line 5
def get_containers(options = {})
  response = Excon::Response.new
  response.body = _format_containers(@containers)
  response.status = 200
  response
end
get_object(container, object, &block) click to toggle source
# File lib/fog/softlayer/requests/storage/get_object.rb, line 5
def get_object(container, object, &block)
  if @containers[container] && @containers[container][object]
    response = Excon::Response.new
    response.body = @containers[container][object]
    response.status = 200
    response
  else
    response = Excon::Response.new
    response.body = '<html><h1>Not Found</h1><p>The resource could not be found.</p></html>'
    response.status = 404
    response.headers = {"Content-Length"=>"70", "Content-Type"=>"text/html; charset=UTF-8", "X-Trans-Id"=>"abcdefghijklmnopqrstuvwx-0123456789", "Date"=>Time.now}
    response
  end
end
get_object_https_url(container, object, expires, options = {}) click to toggle source
# File lib/fog/softlayer/requests/storage/get_object_https_url.rb, line 5
def get_object_https_url(container, object, expires, options = {})
  "https://cluster.objectstorage.softlayer.net:443/v1/AUTH_abcdefghijklmnopqrstuvwxyz/#{container}/#{object}?temp_url_sig=1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a&temp_url_expires=1111111111111"
end
put_container(name, public=false) click to toggle source
# File lib/fog/softlayer/requests/storage/put_container.rb, line 5
def put_container(name, public=false)
  @containers[name] = {} unless @containers[name]
  response = Excon::Response.new
  response.body = ''
  response.status = 201
  response
end
put_object(container, object, data, options = {}, &block) click to toggle source
# File lib/fog/softlayer/requests/storage/put_object.rb, line 5
def put_object(container, object, data, options = {}, &block)
  if @containers[container]
    @containers[container][object] = data
    response = Excon::Response.new
    response.body = ''
    response.status = 201
    response.headers = {"Last-Modified"=>Time.now, "Content-Length"=>0}
    response
  else
    response = Excon::Response.new
    response.body = '<html><h1>Not Found</h1><p>The resource could not be found.</p></html>'
    response.status = 404
    response.headers = {"Content-Length"=>"70", "Content-Type"=>"text/html; charset=UTF-8", "X-Trans-Id"=>"abcdefghijklmnopqrstuvwx-0123456789", "Date"=>Time.now}
    response
  end
end

Private Instance Methods

_format_containers(containers) click to toggle source
# File lib/fog/softlayer/requests/storage/get_containers.rb, line 14
def _format_containers(containers)
  containers.map do |name, container|
    meta = Memory.analyze(container)
    {'count' => container.length, 'bytes' => meta.bytes, 'name' => name}
  end
end