Class: Fog::AWS::SimpleDB

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/aws/simpledb.rb,
lib/fog/aws/requests/simpledb/select.rb,
lib/fog/aws/requests/simpledb/list_domains.rb,
lib/fog/aws/requests/simpledb/create_domain.rb,
lib/fog/aws/requests/simpledb/delete_domain.rb,
lib/fog/aws/requests/simpledb/get_attributes.rb,
lib/fog/aws/requests/simpledb/put_attributes.rb,
lib/fog/aws/requests/simpledb/domain_metadata.rb,
lib/fog/aws/requests/simpledb/delete_attributes.rb,
lib/fog/aws/requests/simpledb/batch_put_attributes.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SimpleDB

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.



47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/aws/simpledb.rb', line 47

def initialize(options={})
  @aws_access_key_id      = options[:aws_access_key_id]
  @aws_secret_access_key  = options[:aws_secret_access_key]
  @hmac       = HMAC::SHA256.new(@aws_secret_access_key)
  @host       = options[:host]      || 'sdb.amazonaws.com'
  @nil_string = options[:nil_string]|| 'nil'
  @port       = options[:port]      || 443
  @scheme     = options[:scheme]    || 'https'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
end

Class Method Details

.reloadObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/aws/simpledb.rb', line 5

def self.reload
  current_directory = File.dirname(__FILE__)
  load "#{current_directory}/../connection.rb"
  load "#{current_directory}/../parser.rb"
  load "#{current_directory}/../response.rb"

  parsers_directory = "#{current_directory}/parsers/simpledb"
  load "#{parsers_directory}/basic.rb"
  load "#{parsers_directory}/domain_metadata.rb"
  load "#{parsers_directory}/get_attributes.rb"
  load "#{parsers_directory}/list_domains.rb"
  load "#{parsers_directory}/select.rb"

  requests_directory = "#{current_directory}/requests/simpledb"
  load "#{requests_directory}/batch_put_attributes.rb"
  load "#{requests_directory}/create_domain.rb"
  load "#{requests_directory}/delete_attributes.rb"
  load "#{requests_directory}/delete_domain.rb"
  load "#{requests_directory}/domain_metadata.rb"
  load "#{requests_directory}/get_attributes.rb"
  load "#{requests_directory}/list_domains.rb"
  load "#{requests_directory}/put_attributes.rb"
  load "#{requests_directory}/select.rb"
end

Instance Method Details

#batch_put_attributes(domain_name, items, replace_attributes = Hash.new([])) ⇒ Object

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<~Fog::AWS::Response>:

    • body<~Hash>:

      • ‘BoxUsage’

      • ‘RequestId’



22
23
24
25
26
27
# 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
  }.merge!(encode_batch_attributes(items, replace_attributes)), Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string))
end

#create_domain(domain_name) ⇒ Object

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<~Fog::AWS::Response>:

    • body<~Hash>:

      • ‘BoxUsage’

      • ‘RequestId’



16
17
18
19
20
21
# File 'lib/fog/aws/requests/simpledb/create_domain.rb', line 16

def create_domain(domain_name)
  request({
    'Action' => 'CreateDomain',
    'DomainName' => domain_name
  }, Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string))
end

#delete_attributes(domain_name, item_name, attributes = nil) ⇒ Object

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<~Fog::AWS::Response>:

    • body<~Hash>:

      • ‘BoxUsage’

      • ‘RequestId’



24
25
26
27
28
29
30
# 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
  }.merge!(encode_attributes(attributes)), Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string))
end

#delete_domain(domain_name) ⇒ Object

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<~Fog::AWS::Response>:

    • body<~Hash>:

      • ‘BoxUsage’

      • ‘RequestId’



16
17
18
19
20
21
# File 'lib/fog/aws/requests/simpledb/delete_domain.rb', line 16

def delete_domain(domain_name)
  request({
    'Action' => 'DeleteDomain',
    'DomainName' => domain_name
  }, Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string))
end

#domain_metadata(domain_name) ⇒ Object

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<~Fog::AWS::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

      • ‘ItemCount’ - number of items in domain

      • ‘ItemNameSizeBytes’ - total size of item names in domain, in bytes

      • ‘Timestamp’ - last update time for metadata.



21
22
23
24
25
26
# File 'lib/fog/aws/requests/simpledb/domain_metadata.rb', line 21

def (domain_name)
  request({
    'Action' => 'DomainMetadata',
    'DomainName' => domain_name
  }, Fog::Parsers::AWS::SimpleDB::DomainMetadata.new(@nil_string))
end

#get_attributes(domain_name, item_name, attributes = nil) ⇒ Object

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 return from the item. Defaults to nil, 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.

Returns

  • response<~Fog::AWS::Response>:

    • body<~Hash>:

      • ‘Attributes’ - list of attribute name/values for the item

      • ‘BoxUsage’

      • ‘RequestId’



25
26
27
28
29
30
31
# File 'lib/fog/aws/requests/simpledb/get_attributes.rb', line 25

def get_attributes(domain_name, item_name, attributes = nil)
  request({
    'Action' => 'GetAttributes',
    'DomainName' => domain_name,
    'ItemName' => item_name,
  }.merge!(encode_attribute_names(attributes)), Fog::Parsers::AWS::SimpleDB::GetAttributes.new(@nil_string))
end

#list_domains(options = {}) ⇒ Object

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<~Fog::AWS::Response>:

    • body<~Hash>:

      • ‘BoxUsage’

      • ‘Domains’ - array of domain names.

      • ‘NextToken’ - offset to start with if there are are more domains to list

      • ‘RequestId’



20
21
22
23
24
25
26
# File 'lib/fog/aws/requests/simpledb/list_domains.rb', line 20

def list_domains(options = {})
  request({
    'Action' => 'ListDomains',
    'MaxNumberOfDomains' => options['MaxNumberOfDomains'],
    'NextToken' => options['NextToken']
  }, Fog::Parsers::AWS::SimpleDB::ListDomains.new(@nil_string))
end

#put_attributes(domain_name, item_name, attributes, replace_attributes = []) ⇒ Object

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.

Returns

  • response<~Fog::AWS::Response>:

    • body<~Hash>:

      • ‘BoxUsage’

      • ‘RequestId’



23
24
25
# File 'lib/fog/aws/requests/simpledb/put_attributes.rb', line 23

def put_attributes(domain_name, item_name, attributes, replace_attributes = [])
  batch_put_attributes(domain_name, { item_name => attributes }, { item_name => replace_attributes })
end

#select(select_expression, next_token = nil) ⇒ Object

Select item data from SimpleDB

Parameters

  • select_expression<~String> - Expression to query domain with.

  • next_token<~String> - Offset token to start list, defaults to nil.

Returns

  • response<~Fog::AWS::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



19
20
21
22
23
24
25
# File 'lib/fog/aws/requests/simpledb/select.rb', line 19

def select(select_expression, next_token = nil)
  request({
    'Action' => 'Select',
    'NextToken' => next_token,
    'SelectExpression' => select_expression
  }, Fog::Parsers::AWS::SimpleDB::Select.new(@nil_string))
end