class Fog::AWS::SimpleDB::Real
Public Class Methods
Initialize connection to SimpleDB
Notes¶ ↑
options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection
Examples¶ ↑
sdb = SimpleDB.new( :aws_access_key_id => your_aws_access_key_id, :aws_secret_access_key => your_aws_secret_access_key )
Parameters¶ ↑
-
options<~Hash> - config arguments for connection. Defaults to {}.
Returns¶ ↑
-
SimpleDB
object with connection to aws.
# File lib/fog/aws/simpledb.rb, line 70 def initialize(options={}) @use_iam_profile = options[:use_iam_profile] setup_credentials(options) @connection_options = options[:connection_options] || {} @nil_string = options[:nil_string]|| 'nil' @instrumentor = options[:instrumentor] @instrumentor_name = options[:instrumentor_name] || 'fog.aws.simpledb' options[:region] ||= 'us-east-1' @host = options[:host] || case options[:region] when 'us-east-1' 'sdb.amazonaws.com' else "sdb.#{options[:region]}.amazonaws.com" end @path = options[:path] || '/' @persistent = options[:persistent] || false @port = options[:port] || 443 @scheme = options[:scheme] || 'https' @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options) end
Public Instance Methods
Put items attributes into a SimpleDB
domain
Parameters¶ ↑
-
domain_name<~String> - Name of domain. Must be between 3 and 255 of the following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
-
items<~Hash> - Keys are the items names and may use any UTF-8 characters valid in xml. Control characters and sequences not allowed in xml are not valid. Can be up to 1024 bytes long. Values are the attributes to add to the given item and may use any UTF-8 characters valid in xml. Control characters and sequences not allowed in xml are not valid. Each name and value can be up to 1024 bytes long.
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'BoxUsage'
-
'RequestId'
-
-
# File lib/fog/aws/requests/simpledb/batch_put_attributes.rb, line 22 def batch_put_attributes(domain_name, items, replace_attributes = Hash.new([])) request({ 'Action' => 'BatchPutAttributes', 'DomainName' => domain_name, :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string) }.merge!(encode_batch_attributes(items, replace_attributes))) end
Create a SimpleDB
domain
Parameters¶ ↑
- domain_name<~String>
-
Name of domain. Must be between 3 and 255 of the
following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'BoxUsage'
-
'RequestId'
-
-
# File lib/fog/aws/requests/simpledb/create_domain.rb, line 16 def create_domain(domain_name) request( 'Action' => 'CreateDomain', 'DomainName' => domain_name, :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string) ) end
List metadata for SimpleDB
domain
Parameters¶ ↑
-
domain_name<~String> - Name of domain. Must be between 3 and 255 of the following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
-
item_name<~String> - Name of the item. May use any UTF-8 characters valid in xml. Control characters and sequences not allowed in xml are not valid. Can be up to 1024 bytes long.
-
attributes<~Hash> - Name/value pairs to remove from the item. Defaults to nil, which will delete the entire item. Attribute names and values may use any UTF-8 characters valid in xml. Control characters and sequences not allowed in xml are not valid. Each name and value can be up to 1024 bytes long.
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'BoxUsage'
-
'RequestId'
-
-
# File lib/fog/aws/requests/simpledb/delete_attributes.rb, line 24 def delete_attributes(domain_name, item_name, attributes = nil) request({ 'Action' => 'DeleteAttributes', 'DomainName' => domain_name, 'ItemName' => item_name, :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string) }.merge!(encode_attributes(attributes))) end
Delete a SimpleDB
domain
Parameters¶ ↑
- domain_name<~String>
-
Name of domain. Must be between 3 and 255 of the
following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'BoxUsage'
-
'RequestId'
-
-
# File lib/fog/aws/requests/simpledb/delete_domain.rb, line 16 def delete_domain(domain_name) request( 'Action' => 'DeleteDomain', 'DomainName' => domain_name, :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string) ) end
List metadata for SimpleDB
domain
Parameters¶ ↑
-
domain_name<~String> - Name of domain. Must be between 3 and 255 of the
following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'AttributeNameCount' - number of unique attribute names in domain
-
'AttributeNamesSizeBytes' - total size of unique attribute names, in bytes
-
'AttributeValueCount' - number of all name/value pairs in domain
-
'AttributeValuesSizeBytes' - total size of attributes, in bytes
-
'BoxUsage'
-
'ItemCount' - number of items in domain
-
'ItemNameSizeBytes' - total size of item names in domain, in bytes
-
'RequestId'
-
'Timestamp' - last update time for metadata.
-
-
# File lib/fog/aws/requests/simpledb/domain_metadata.rb, line 25 def domain_metadata(domain_name) request( 'Action' => 'DomainMetadata', 'DomainName' => domain_name, :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::DomainMetadata.new(@nil_string) ) end
List metadata for SimpleDB
domain
Parameters¶ ↑
-
domain_name<~String> - Name of domain. Must be between 3 and 255 of the following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
-
item_name<~String> - Name of the item. May use any UTF-8 characters valid in xml. Control characters and sequences not allowed in xml are not valid. Can be up to 1024 bytes long.
-
options<~Hash>:
-
AttributeName<~Array> - Attributes to return from the item. Defaults to {}, which will return all attributes. Attribute names and values may use any UTF-8 characters valid in xml. Control characters and sequences not allowed in xml are not valid. Each name and value can be up to 1024 bytes long.
-
ConsistentRead<~Boolean> - When set to true, ensures most recent data is returned. Defaults to false.
-
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'Attributes' - list of attribute name/values for the item
-
'BoxUsage'
-
'RequestId'
-
-
# File lib/fog/aws/requests/simpledb/get_attributes.rb, line 29 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} end options['AttributeName'] ||= [] request({ 'Action' => 'GetAttributes', 'ConsistentRead' => !!options['ConsistentRead'], 'DomainName' => domain_name, 'ItemName' => item_name, :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::GetAttributes.new(@nil_string) }.merge!(encode_attribute_names(options['AttributeName']))) end
List SimpleDB
domains
Parameters¶ ↑
-
options<~Hash> - options, defaults to {}
-
'MaxNumberOfDomains'<~Integer> - number of domains to return between 1 and 100, defaults to 100
-
'NextToken'<~String> - Offset token to start listing, defaults to nil
-
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'BoxUsage'
-
'Domains' - array of domain names.
-
'NextToken' - offset to start with if there are are more domains to list
-
'RequestId'
-
-
# File lib/fog/aws/requests/simpledb/list_domains.rb, line 22 def list_domains(options = {}) request({ 'Action' => 'ListDomains', :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::ListDomains.new(@nil_string) }.merge!(options)) end
Put item attributes into a SimpleDB
domain
Parameters¶ ↑
-
domain_name<~String> - Name of domain. Must be between 3 and 255 of the
following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
-
item_name<~String> - Name of the item. May use any UTF-8 characters valid in xml. Control characters and sequences not allowed in xml are not valid. Can be up to 1024 bytes long.
-
attributes<~Hash> - Name/value pairs to add to the item. Attribute names and values may use any UTF-8 characters valid in xml. Control characters and sequences not allowed in xml are not valid. Each name and value can be up to 1024 bytes long.
-
options<~Hash> - Accepts the following keys. :replace => [Array of keys to replace] :expect => {name/value pairs for performing conditional put}
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'BoxUsage'
-
'RequestId'
-
-
# File lib/fog/aws/requests/simpledb/put_attributes.rb, line 26 def put_attributes(domain_name, item_name, attributes, options = {}) options[:expect] = {} unless options[:expect] options[:replace] = [] unless options[:replace] request({ 'Action' => 'PutAttributes', 'DomainName' => domain_name, 'ItemName' => item_name, :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string) }.merge!(encode_attributes(attributes, options[:replace], options[:expect]))) end
Select item data from SimpleDB
Parameters¶ ↑
-
select_expression<~String> - Expression to query domain with.
-
options<~Hash>:
-
ConsistentRead<~Boolean> - When set to true, ensures most recent data is returned. Defaults to false.
-
NextToken<~String> - Offset token to start list, defaults to nil.
-
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'BoxUsage'<~Float>
-
'RequestId'<~String>
-
'Items'<~Hash> - list of attribute name/values for the items formatted as { 'item_name' => { 'attribute_name' => ['attribute_value'] }}
-
'NextToken'<~String> - offset to start with if there are are more domains to list
-
-
# File lib/fog/aws/requests/simpledb/select.rb, line 23 def select(select_expression, options = {}) if options.is_a?(String) Fog::Logger.deprecation("get_attributes with string next_token param is deprecated, use 'AttributeName' => attributes) instead [light_black](#{caller.first})[/]") options = {'NextToken' => options} end options['NextToken'] ||= nil request( 'Action' => 'Select', 'ConsistentRead' => !!options['ConsistentRead'], 'NextToken' => options['NextToken'], 'SelectExpression' => select_expression, :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::Select.new(@nil_string) ) end
Private Instance Methods
# File lib/fog/aws/simpledb.rb, line 188 def _request(body, idempotent, parser) @connection.request({ :body => body, :expects => 200, :headers => { 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8' }, :idempotent => idempotent, :method => 'POST', :parser => parser }) end
# File lib/fog/aws/simpledb.rb, line 129 def encode_attribute_names(attributes) Fog::AWS.indexed_param('AttributeName', attributes.map {|attribute| attributes.to_s}) end
# File lib/fog/aws/simpledb.rb, line 103 def encode_attributes(attributes, replace_attributes = [], expected_attributes = {}) encoded_attributes = {} if attributes expected_attributes.keys.each_with_index do |exkey, index| for value in Array(expected_attributes[exkey]) encoded_attributes["Expected.#{index}.Name"] = exkey.to_s encoded_attributes["Expected.#{index}.Value"] = sdb_encode(value) end end index = 0 for key in attributes.keys for value in Array(attributes[key]) encoded_attributes["Attribute.#{index}.Name"] = key.to_s if replace_attributes.include?(key) encoded_attributes["Attribute.#{index}.Replace"] = 'true' end encoded_attributes["Attribute.#{index}.Value"] = sdb_encode(value) index += 1 end end end encoded_attributes end
# File lib/fog/aws/simpledb.rb, line 133 def encode_batch_attributes(items, replace_attributes = Hash.new([])) encoded_attributes = {} if items item_index = 0 for item_key in items.keys encoded_attributes["Item.#{item_index}.ItemName"] = item_key.to_s attribute_index = 0 for attribute_key in items[item_key].keys for value in Array(items[item_key][attribute_key]) encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Name"] = attribute_key.to_s if replace_attributes[item_key].include?(attribute_key) encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Replace"] = 'true' end encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Value"] = sdb_encode(value) attribute_index += 1 end end item_index += 1 end end encoded_attributes end
# File lib/fog/aws/simpledb.rb, line 156 def reload @connection.reset end
# File lib/fog/aws/simpledb.rb, line 160 def request(params) refresh_credentials_if_expired idempotent = params.delete(:idempotent) parser = params.delete(:parser) body = Fog::AWS.signed_params( params, { :aws_access_key_id => @aws_access_key_id, :aws_session_token => @aws_session_token, :hmac => @hmac, :host => @host, :path => @path, :port => @port, :version => '2009-04-15' } ) if @instrumentor @instrumentor.instrument("#{@instrumentor_name}.request", params) do _request(body, idempotent, parser) end else _request(body, idempotent, parser) end end
# File lib/fog/aws/simpledb.rb, line 199 def sdb_encode(value) if value.nil? @nil_string else value.to_s end end
# File lib/fog/aws/simpledb.rb, line 94 def setup_credentials(options) @aws_access_key_id = options[:aws_access_key_id] @aws_secret_access_key = options[:aws_secret_access_key] @aws_session_token = options[:aws_session_token] @aws_credentials_expire_at = options[:aws_credentials_expire_at] @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) end