class Fog::AWS::SimpleDB::Mock
Public Class Methods
data()
click to toggle source
# File lib/fog/aws/simpledb.rb, line 21 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :domains => {} } end end
new(options={})
click to toggle source
# File lib/fog/aws/simpledb.rb, line 33 def initialize(options={}) @use_iam_profile = options[:use_iam_profile] setup_credentials(options) end
reset()
click to toggle source
# File lib/fog/aws/simpledb.rb, line 29 def self.reset @data = nil end
Public Instance Methods
batch_put_attributes(domain_name, items, replace_attributes = Hash.new([]))
click to toggle source
# File lib/fog/aws/requests/simpledb/batch_put_attributes.rb, line 32 def batch_put_attributes(domain_name, items, replace_attributes = Hash.new([])) response = Excon::Response.new if self.data[:domains][domain_name] for item_name, attributes in items do for key, value in attributes do self.data[:domains][domain_name][item_name] ||= {} if replace_attributes[item_name] && replace_attributes[item_name].include?(key) self.data[:domains][domain_name][item_name][key.to_s] = [] else self.data[:domains][domain_name][item_name][key.to_s] ||= [] end self.data[:domains][domain_name][item_name][key.to_s] << value.to_s end end response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end
create_domain(domain_name)
click to toggle source
# File lib/fog/aws/requests/simpledb/create_domain.rb, line 27 def create_domain(domain_name) response = Excon::Response.new self.data[:domains][domain_name] = {} response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } response end
data()
click to toggle source
# File lib/fog/aws/simpledb.rb, line 38 def data self.class.data[@aws_access_key_id] end
delete_attributes(domain_name, item_name, attributes = nil)
click to toggle source
# File lib/fog/aws/requests/simpledb/delete_attributes.rb, line 35 def delete_attributes(domain_name, item_name, attributes = nil) response = Excon::Response.new if self.data[:domains][domain_name] if self.data[:domains][domain_name][item_name] if attributes for key, value in attributes if self.data[:domains][domain_name][item_name][key] if value.nil? || value.empty? self.data[:domains][domain_name][item_name].delete(key) else for v in value self.data[:domains][domain_name][item_name][key].delete(v) end end end end else self.data[:domains][domain_name][item_name].clear end end response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end
delete_domain(domain_name)
click to toggle source
# File lib/fog/aws/requests/simpledb/delete_domain.rb, line 27 def delete_domain(domain_name) response = Excon::Response.new if self.data[:domains].delete(domain_name) response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } end response end
domain_metadata(domain_name)
click to toggle source
# File lib/fog/aws/requests/simpledb/domain_metadata.rb, line 36 def domain_metadata(domain_name) response = Excon::Response.new if domain = self.data[:domains][domain_name] response.status = 200 attribute_names = [] attribute_values = [] for item in domain.values for key, values in item attribute_names << key for value in values attribute_values << value end end end response.body = { 'AttributeNameCount' => attribute_names.length, 'AttributeNamesSizeBytes' => attribute_names.join('').length, 'AttributeValueCount' => attribute_values.length, 'AttributeValuesSizeBytes' => attribute_values.join('').length, 'BoxUsage' => Fog::AWS::Mock.box_usage, 'ItemCount' => domain.keys.length, 'ItemNamesSizeBytes' => domain.keys.join('').length, 'RequestId' => Fog::AWS::Mock.request_id, 'Timestamp' => Time.now } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end
get_attributes(domain_name, item_name, options = {})
click to toggle source
# File lib/fog/aws/requests/simpledb/get_attributes.rb, line 47 def get_attributes(domain_name, item_name, options = {}) if options.is_a?(Array) Fog::Logger.deprecation("get_attributes with array attributes param is deprecated, use 'AttributeName' => attributes) instead [light_black](#{caller.first})[/]") options['AttributeName'] ||= options if options.is_a?(Array) end options['AttributeName'] ||= [] response = Excon::Response.new if self.data[:domains][domain_name] object = {} if !options['AttributeName'].empty? for attribute in options['AttributeName'] if self.data[:domains][domain_name].key?(item_name) && self.data[:domains][domain_name][item_name].key?(attribute) object[attribute] = self.data[:domains][domain_name][item_name][attribute] end end elsif self.data[:domains][domain_name][item_name] object = self.data[:domains][domain_name][item_name] end response.status = 200 response.body = { 'Attributes' => object, 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end
list_domains(options = {})
click to toggle source
# File lib/fog/aws/requests/simpledb/list_domains.rb, line 32 def list_domains(options = {}) response = Excon::Response.new keys = self.data[:domains].keys max = options['MaxNumberOfDomains'] || keys.size offset = options['NextToken'] || 0 domains = [] for key, value in self.data[:domains].keys[offset...max] domains << key end response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'Domains' => domains, 'RequestId' => Fog::AWS::Mock.request_id } if max < keys.size response.body['NextToken'] = max + 1 end response end
put_attributes(domain_name, item_name, attributes, options = {})
click to toggle source
# File lib/fog/aws/requests/simpledb/put_attributes.rb, line 39 def put_attributes(domain_name, item_name, attributes, options = {}) options[:expect] = {} unless options[:expect] options[:replace] = [] unless options[:replace] response = Excon::Response.new if self.data[:domains][domain_name] options[:expect].each do |ck, cv| if self.data[:domains][domain_name][item_name][ck] != [cv] response.status = 409 raise(Excon::Errors.status_error({:expects => 200}, response)) end end attributes.each do |key, value| self.data[:domains][domain_name][item_name] ||= {} self.data[:domains][domain_name][item_name][key.to_s] = [] unless self.data[:domains][domain_name][item_name][key.to_s] if options[:replace].include?(key.to_s) self.data[:domains][domain_name][item_name][key.to_s] = [*value].map {|x| x.to_s} else self.data[:domains][domain_name][item_name][key.to_s] += [*value].map {|x| x.to_s} end end response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, 'RequestId' => Fog::AWS::Mock.request_id } else response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end
reset_data()
click to toggle source
# File lib/fog/aws/simpledb.rb, line 42 def reset_data self.class.data.delete(@aws_access_key_id) end
setup_credentials(options)
click to toggle source
# File lib/fog/aws/simpledb.rb, line 46 def setup_credentials(options) @aws_access_key_id = options[:aws_access_key_id] end