Module: Stargate::Operation::RowOperation
- Included in:
- Client
- Defined in:
- lib/stargate/operation/row_operation.rb
Constant Summary collapse
- Converter =
{ '&' => '&', '<' => '<', '>' => '>', "'" => ''', '"' => '"' }
Instance Method Summary collapse
- #create_row(table_name, name, timestamp = nil, columns = nil) ⇒ Object
- #delete_row(table_name, name, timestamp = nil, columns = nil) ⇒ Object
- #row_timestamps(table_name, name) ⇒ Object
- #show_row(table_name, name, timestamp = nil, columns = nil, options = { }) ⇒ Object
Instance Method Details
#create_row(table_name, name, timestamp = nil, columns = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/stargate/operation/row_operation.rb', line 42 def create_row(table_name, name, = nil, columns = nil) begin request = Request::RowRequest.new(table_name, name, ) data = [] if columns if columns.instance_of? Array data = columns elsif columns.instance_of? Hash data = [columns] else raise StandardError, "Only Array or Hash data accepted" end end xml_data = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><CellSet>" xml_data << "<Row key='#{[name].pack('m') rescue ''}'>" data.each do |d| escape_name = d[:name].gsub(/[&<>'"]/) { |match| Converter[match] } xml_data << "<Cell " xml_data << "timestamp='#{timestamp}' " if xml_data << "column='#{[escape_name].pack('m') rescue ''}'>" xml_data << "#{[d[:value]].pack("m") rescue ''}" xml_data << "</Cell>" end xml_data << "</Row></CellSet>" Response::RowResponse.new(post_response(request.create(data.map{|col| col[:name]}), xml_data), :create_row).parse rescue Net::ProtocolError => e if e.to_s.include?("Table") raise TableNotFoundError, "Table '#{table_name}' Not Found" elsif e.to_s.include?("Row") raise RowNotFoundError, "Row '#{name}' Not Found" else raise StandardError, "Error encountered while trying to create row: #{e.message}" end end end |
#delete_row(table_name, name, timestamp = nil, columns = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/stargate/operation/row_operation.rb', line 80 def delete_row(table_name, name, = nil, columns = nil) begin request = Request::RowRequest.new(table_name, name, ) Response::RowResponse.new(delete_response(request.delete(columns)), :delete_row).parse rescue Net::ProtocolError => e if e.to_s.include?("Table") raise TableNotFoundError, "Table '#{table_name}' Not Found" elsif e.to_s.include?("Row") raise RowNotFoundError, "Row '#{name}' Not Found" end end end |
#row_timestamps(table_name, name) ⇒ Object
12 13 14 |
# File 'lib/stargate/operation/row_operation.rb', line 12 def (table_name, name) raise NotImplementedError, "Currently not supported in Stargate client" end |
#show_row(table_name, name, timestamp = nil, columns = nil, options = { }) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/stargate/operation/row_operation.rb', line 16 def show_row(table_name, name, = nil, columns = nil, = { }) begin [:version] ||= 1 request = Request::RowRequest.new(table_name, name, ) rows = Response::RowResponse.new(get(request.show(columns, )), :show_row).parse if rows.size == 1 row = rows.first row.table_name = table_name row else rows.each do |row| row.table_name = table_name end rows end rescue Net::ProtocolError => e # TODO: Use better handling instead of this. if e.to_s.include?("Table") raise TableNotFoundError, "Table '#{table_name}' Not Found" elsif e.to_s.include?("404") raise RowNotFoundError, "Row '#{name}' Not Found" end end end |