Class: Amazon::SDB::Base
- Inherits:
-
Object
- Object
- Amazon::SDB::Base
- Defined in:
- lib/amazon_sdb/base.rb
Overview
The Amazon::SDS::Base class is the top-level interface class for your SDS interactions. It allows you to set global configuration settings, to manage Domain objects. If you are working within a particular domain you can also just use the domain initializer directly for that domain.
Class Method Summary collapse
-
.float_precision ⇒ Object
The number of digits after the decimal points to use by default.
-
.float_precision=(num) ⇒ Object
Set the #float_precision.
-
.number_padding ⇒ Object
Since all SDS supports only lexical comparisons, it’s necessary to pad numbers with extra digits when saving them to SDS.
-
.number_padding=(num) ⇒ Object
Change the number padding.
Instance Method Summary collapse
-
#box_usage ⇒ Object
Returns the Box Usage accumulated since the beginning of the session.
-
#create_domain(name) ⇒ Object
Creates a domain.
-
#delete_domain!(name) ⇒ Object
Deletes a domain.
-
#domain(name) ⇒ Object
Returns a domain object for SimpleDB.
-
#domains ⇒ Object
Retrieves a list of domains in your SDS database.
-
#initialize(aws_access_key, aws_secret_key) ⇒ Base
constructor
The base is initialized with 2 parameters from your Amazon Web Services account: *
aws_access_key
- Your AWS Access Key *aws_secret_key
- Your AWS Secret Key. -
#reset_usage! ⇒ Object
Resets the box usage accumulated within the current session.
Constructor Details
#initialize(aws_access_key, aws_secret_key) ⇒ Base
The base is initialized with 2 parameters from your Amazon Web Services account:
-
aws_access_key
- Your AWS Access Key -
aws_secret_key
- Your AWS Secret Key
15 16 17 18 19 |
# File 'lib/amazon_sdb/base.rb', line 15 def initialize(aws_access_key, aws_secret_key) @access_key = aws_access_key @secret_key = aws_secret_key @usage = Usage.new end |
Class Method Details
.float_precision ⇒ Object
The number of digits after the decimal points to use by default
38 39 40 |
# File 'lib/amazon_sdb/base.rb', line 38 def self.float_precision return @@float_precision end |
.float_precision=(num) ⇒ Object
Set the #float_precision
44 45 46 |
# File 'lib/amazon_sdb/base.rb', line 44 def self.float_precision=(num) return @@float_precision end |
.number_padding ⇒ Object
Since all SDS supports only lexical comparisons, it’s necessary to pad numbers with extra digits when saving them to SDS. Under lexical matching, 23 > 123. But if we pad it sufficiently 000000023 < 000000123. By default, this is set to the ungodly large value of 32 digits, but you can adjust it lower if this is too much. On reading from SDS, such numbers are auto-coerced back, so it’s probably not necessary to change.
26 27 28 |
# File 'lib/amazon_sdb/base.rb', line 26 def self.number_padding return @@number_padding end |
.number_padding=(num) ⇒ Object
Change the number padding
32 33 34 |
# File 'lib/amazon_sdb/base.rb', line 32 def self.number_padding=(num) @@number_padding = num end |
Instance Method Details
#box_usage ⇒ Object
Returns the Box Usage accumulated since the beginning of the session. Box Usage represents computation time and is one of the parameters in your monthly SimpleDB bill. As an alternative, when passed a block (no parameters yielded), it returns the box usage only for the operations within the block.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/amazon_sdb/base.rb', line 52 def box_usage unless block_given? @usage.box_usage else # return the usage of the actions in the block usage1 = @usage.box_usage yield usage2 = @usage.box_usage return usage2 - usage1 end end |
#create_domain(name) ⇒ Object
Creates a domain. This operation is idempotent, but it is slow and if you are sure the domain already exists, you might want to use the #domain method instead. Each SimpleDB account is allowed up to 100 domains; a LimitError will be raised if you attempt to create more.
107 108 109 110 111 |
# File 'lib/amazon_sdb/base.rb', line 107 def create_domain(name) sdb_query({:Action => 'CreateDomain', 'DomainName' => name}) do |h| domain(name) end end |
#delete_domain!(name) ⇒ Object
Deletes a domain. Running this command multiple times or on a domain that does not exist will NOT return an error.
115 116 117 |
# File 'lib/amazon_sdb/base.rb', line 115 def delete_domain!(name) sdb_query({:Action => 'DeleteDomain', 'DomainName' => name}) end |
#domain(name) ⇒ Object
Returns a domain object for SimpleDB. Assumes the domain already exists, so a ParameterError (NoSuchDomain) might occur if it’s not there. This method is useful for getting a domain object without having to incur the operational costs of querying all domains.
99 100 101 |
# File 'lib/amazon_sdb/base.rb', line 99 def domain(name) Domain.new(self, name) end |
#domains ⇒ Object
Retrieves a list of domains in your SDS database. Each entry is a Domain object.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/amazon_sdb/base.rb', line 72 def domains domains = [] nextToken = nil = {:Action => 'ListDomains'} continue = true while continue = .dup [:NextToken] = nextToken unless nextToken.nil? sdb_query() do |h| h.search('//DomainName').each {|e| domains << Domain.new(self, e.innerText)} mt = h.at('//NextToken') if mt nextToken = mt.innerText else continue = false end end end domains end |
#reset_usage! ⇒ Object
Resets the box usage accumulated within the current session. Not sure why you’d need to do this, but it’s provided.
66 67 68 |
# File 'lib/amazon_sdb/base.rb', line 66 def reset_usage! @usage.reset! end |