Class: Fog::Storage::Softlayer::Mock
- Inherits:
-
Object
- Object
- Fog::Storage::Softlayer::Mock
- Includes:
- Integrity
- Defined in:
- lib/fog/softlayer/storage.rb,
lib/fog/softlayer/requests/storage/get_object.rb,
lib/fog/softlayer/requests/storage/put_object.rb,
lib/fog/softlayer/requests/storage/copy_object.rb,
lib/fog/softlayer/requests/storage/delete_object.rb,
lib/fog/softlayer/requests/storage/get_container.rb,
lib/fog/softlayer/requests/storage/put_container.rb,
lib/fog/softlayer/requests/storage/get_containers.rb,
lib/fog/softlayer/requests/storage/delete_container.rb,
lib/fog/softlayer/requests/storage/get_object_https_url.rb more...
Class Method Summary collapse
Instance Method Summary collapse
- #change_account(account) ⇒ Object
- #copy_object(source_container, source_object, target_container, target_object, options = {}) ⇒ Object
- #data ⇒ Object
- #delete_container(name) ⇒ Object
- #delete_object(container, object) ⇒ Object
- #get_container(container, options = {}) ⇒ Object
- #get_containers(options = {}) ⇒ Object
- #get_object(container, object, &block) ⇒ Object
- #get_object_https_url(container, object, expires, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #put_container(name, public = false) ⇒ Object
- #put_object(container, object, data, options = {}, &block) ⇒ Object
- #reset_account_name ⇒ Object
- #reset_data ⇒ Object
Methods included from Integrity
Constructor Details
permalink #initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
59 60 61 62 63 64 65 |
# File 'lib/fog/softlayer/storage.rb', line 59 def initialize(={}) @softlayer_api_key = [:softlayer_api_key] @softlayer_username = [:softlayer_username] validate_username! @softlayer_username @path = '/v1/AUTH_1234' @containers = {} end |
Class Method Details
permalink .data ⇒ Object
[View source]
49 50 51 52 53 |
# File 'lib/fog/softlayer/storage.rb', line 49 def self.data @data ||= Hash.new do |hash, key| hash[key] = {} end end |
permalink .reset ⇒ Object
[View source]
55 56 57 |
# File 'lib/fog/softlayer/storage.rb', line 55 def self.reset @data = nil end |
Instance Method Details
permalink #change_account(account) ⇒ Object
[View source]
75 76 77 78 79 |
# File 'lib/fog/softlayer/storage.rb', line 75 def change_account(account) @original_path ||= @path version_string = @original_path.split('/')[1] @path = "/#{version_string}/#{account}" end |
permalink #copy_object(source_container, source_object, target_container, target_object, options = {}) ⇒ Object
[View source]
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/softlayer/requests/storage/copy_object.rb', line 5 def copy_object(source_container, source_object, target_container, target_object, ={}) 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 |
permalink #data ⇒ Object
[View source]
67 68 69 |
# File 'lib/fog/softlayer/storage.rb', line 67 def data self.class.data[@softlayer_username] end |
permalink #delete_container(name) ⇒ Object
[View source]
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |
permalink #delete_object(container, object) ⇒ Object
[View source]
6 7 8 9 10 11 12 13 14 15 16 |
# 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 |
permalink #get_container(container, options = {}) ⇒ Object
[View source]
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/softlayer/requests/storage/get_container.rb', line 5 def get_container(container, = {}) 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 |
permalink #get_containers(options = {}) ⇒ Object
[View source]
5 6 7 8 9 10 |
# File 'lib/fog/softlayer/requests/storage/get_containers.rb', line 5 def get_containers( = {}) response = Excon::Response.new response.body = _format_containers(@containers) response.status = 200 response end |
permalink #get_object(container, object, &block) ⇒ Object
[View source]
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |
permalink #get_object_https_url(container, object, expires, options = {}) ⇒ Object
[View source]
5 6 7 |
# File 'lib/fog/softlayer/requests/storage/get_object_https_url.rb', line 5 def get_object_https_url(container, object, expires, = {}) "https://cluster.objectstorage.softlayer.net:443/v1/AUTH_abcdefghijklmnopqrstuvwxyz/#{container}/#{object}?temp_url_sig=1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a&temp_url_expires=1111111111111" end |
permalink #put_container(name, public = false) ⇒ Object
[View source]
5 6 7 8 9 10 11 |
# 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 |
permalink #put_object(container, object, data, options = {}, &block) ⇒ Object
[View source]
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/softlayer/requests/storage/put_object.rb', line 5 def put_object(container, object, data, = {}, &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 |
permalink #reset_account_name ⇒ Object
[View source]
81 82 83 |
# File 'lib/fog/softlayer/storage.rb', line 81 def reset_account_name @path = @original_path end |
permalink #reset_data ⇒ Object
[View source]
71 72 73 |
# File 'lib/fog/softlayer/storage.rb', line 71 def reset_data self.class.data.delete(@softlayer_username) end |