Class: SimplyDB::Interface
- Inherits:
-
Object
- Object
- SimplyDB::Interface
- Defined in:
- lib/simplydb/interface.rb
Instance Attribute Summary collapse
-
#box_usage ⇒ Object
Returns the value of attribute box_usage.
-
#client ⇒ Object
Returns the value of attribute client.
-
#next_token ⇒ Object
Returns the value of attribute next_token.
-
#on_error ⇒ Object
Returns the value of attribute on_error.
-
#options ⇒ Object
Returns the value of attribute options.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
Instance Method Summary collapse
- #batch_put_attributes(name, items = {}) ⇒ Object
- #create_domain(name) ⇒ Object
- #delete_attributes(name, id, attributes = {}, expected = {}) ⇒ Object
- #delete_domain(name) ⇒ Object
- #domain_metadata(name) ⇒ Object
- #get_attributes(name, id, wanted_attributes = [], consistent_read = false) ⇒ Object
-
#initialize(options = {}) ⇒ Interface
constructor
A new instance of Interface.
- #list_domains ⇒ Object
- #put_attributes(name, id, attributes = {}, expected = {}, replace = false) ⇒ Object
- #select(expression, consistent_read = false, next_token = nil) ⇒ Object
Constructor Details
Instance Attribute Details
#box_usage ⇒ Object
Returns the value of attribute box_usage.
5 6 7 |
# File 'lib/simplydb/interface.rb', line 5 def box_usage @box_usage end |
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/simplydb/interface.rb', line 5 def client @client end |
#next_token ⇒ Object
Returns the value of attribute next_token.
5 6 7 |
# File 'lib/simplydb/interface.rb', line 5 def next_token @next_token end |
#on_error ⇒ Object
Returns the value of attribute on_error.
5 6 7 |
# File 'lib/simplydb/interface.rb', line 5 def on_error @on_error end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/simplydb/interface.rb', line 5 def @options end |
#request_id ⇒ Object
Returns the value of attribute request_id.
5 6 7 |
# File 'lib/simplydb/interface.rb', line 5 def request_id @request_id end |
Instance Method Details
#batch_put_attributes(name, items = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/simplydb/interface.rb', line 50 def batch_put_attributes(name, items = {}) params = {'DomainName' => name, 'ActionName' => 'BatchPutAttributes'} items.keys.each_with_index do |key, i| params["Item.#{i}.ItemName"] = key items[key].inject(0) do |j, (name,value)| value = [value] unless value.is_a?(Array) value.each do |v| params["Item.#{i}.Attribute.#{j}.Name"] = name params["Item.#{i}.Attribute.#{j}.Value"] = value j+=1 end j end end call(params) do |doc| doc.css("BatchPutAttributesResponse").length > 0 end end |
#create_domain(name) ⇒ Object
11 12 13 14 15 |
# File 'lib/simplydb/interface.rb', line 11 def create_domain(name) call({'Action' => 'CreateDomain', 'DomainName' => name}) do |doc| doc.css("CreateDomainResponse").length > 0 end end |
#delete_attributes(name, id, attributes = {}, expected = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/simplydb/interface.rb', line 69 def delete_attributes(name, id, attributes = {}, expected = {}) params = define_attributes(attributes, expected) params.merge!({ 'DomainName' => name, 'ItemName' => id, 'Action' => 'DeleteAttributes' }) call(params) do |doc| doc.css("DeleteAttributesResponse").length > 0 end end |
#delete_domain(name) ⇒ Object
17 18 19 20 21 |
# File 'lib/simplydb/interface.rb', line 17 def delete_domain(name) call({'Action' => 'DeleteDomain', 'DomainName' => name}) do |doc| doc.css("DeleteDomainResponse").length > 0 end end |
#domain_metadata(name) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/simplydb/interface.rb', line 29 def (name) call({'Action' => 'DomainMetadata','DomainName' => name}) do |doc| doc.css("DomainMetadataResult").first.children.inject({}) do |memo, child| memo[child.name] = child.text memo end end end |
#get_attributes(name, id, wanted_attributes = [], consistent_read = false) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/simplydb/interface.rb', line 81 def get_attributes(name, id, wanted_attributes = [], consistent_read = false) params = { 'Action' => 'GetAttributes', 'DomainName' => name, 'ItemName' => id, 'ConsistentRead' => consistent_read.to_s, } wanted_attributes.each_with_index {|name, index| params["AttributeName.#{index}"] = name} call(params) do |doc| doc.css("Attribute").inject({}) do |memo, attribute| name = attribute.css("Name").first.text value = attribute.css("Value").first.text if memo.has_key?(name) memo[name] = [memo[name]] unless memo[name].is_a?(Array) memo[name] << value else memo[name] = value end memo end end end |
#list_domains ⇒ Object
23 24 25 26 27 |
# File 'lib/simplydb/interface.rb', line 23 def list_domains call({'Action' => 'ListDomains'}) do |doc| doc.css('DomainName').collect{|d| d.text} end end |
#put_attributes(name, id, attributes = {}, expected = {}, replace = false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/simplydb/interface.rb', line 38 def put_attributes(name, id, attributes = {}, expected = {}, replace = false) params = define_attributes(attributes, expected, replace) params.merge!({ 'DomainName' => name, 'ItemName' => id, 'Action' => 'PutAttributes' }) call(params) do |doc| doc.css("PutAttributesResponse").length > 0 end end |
#select(expression, consistent_read = false, next_token = nil) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/simplydb/interface.rb', line 105 def select(expression, consistent_read = false, next_token = nil) params = { 'Action' => 'Select', 'SelectExpression' => expression, 'ConsistentRead' => consistent_read.to_s, } params['NextToken'] = next_token unless next_token.nil? call(params) do |doc| doc.css("SelectResponse SelectResult Item").collect do |element| item_name = element.css("Name").first.text item = element.css("Attribute").inject({}) do |attributes, attribute| attribute_name = attribute.css("Name").first.text attribute_value = attribute.css("Value").first.text if attributes.has_key?(attribute_name) attributes[attribute_name] = [attributes[attribute_name]] unless attributes[attribute_name].is_a?(Array) attributes[attribute_name] << attribute_value else attributes[attribute_name] = attribute_value end attributes end {item_name => item} end end end |