Class: Stargate::Response::RowResponse

Inherits:
BasicResponse show all
Defined in:
lib/stargate/response/row_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BasicResponse

#parse, #verify_success

Constructor Details

#initialize(raw_data, method) ⇒ RowResponse

Returns a new instance of RowResponse.



6
7
8
9
# File 'lib/stargate/response/row_response.rb', line 6

def initialize(raw_data, method)
  @method = method
  super(raw_data)
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



4
5
6
# File 'lib/stargate/response/row_response.rb', line 4

def method
  @method
end

Instance Method Details

#parse_content(raw_data) ⇒ Object



11
12
13
14
15
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
41
42
43
44
# File 'lib/stargate/response/row_response.rb', line 11

def parse_content(raw_data)
  case @method
  when :show_row
    doc = JSON.parse(raw_data)
    rows = doc["Row"]

    model_rows = []
    rows.each do |row|
      rname = row["key"].strip.unpack("m").first
      count = row["Cell"].size
      columns = []

      row["Cell"].each do |col|
        name = col["column"].strip.unpack('m').first
        value = col["$"].strip.unpack('m').first rescue nil
        timestamp = col["timestamp"].to_i

        columns << Stargate::Model::Column.new(  :name => name,
                                              :value => value,
                                              :timestamp => timestamp)
      end

      model_rows << Stargate::Model::Row.new(:name => rname, :total_count => count, :columns => columns)
    end

    model_rows
  when :create_row
    verify_success(raw_data)
  when :delete_row
    verify_success(raw_data)
  else
    puts "method '#{@method}' not supported yet"
  end
end