class DTK::Common::Response

Public Class Methods

new(hash={}) click to toggle source
Calls superclass method
# File lib/response.rb, line 60
def initialize(hash={})
  super()
  replace(hash)
end

Public Instance Methods

add_data_value!(key,value) click to toggle source
# File lib/response.rb, line 124
def add_data_value!(key,value)
  data()[key.to_s] = value
  self
end
data(*data_keys) click to toggle source
# File lib/response.rb, line 84
def data(*data_keys)
  data = self[DataField]
  case data_keys.size
   when 0 then data||{}
   when 1 then data && data[internal_key_form(data_keys.first)]
   else data_keys.map{|key|data && data[internal_key_form(key)]}.compact
  end
end
data_hash_form(*data_keys) click to toggle source
# File lib/response.rb, line 93
def data_hash_form(*data_keys)
  ret = Hash.new
  unless data = self[DataField]
    return ret
  end

  if data_keys.size == 0
    data.inject(Hash.new){|h,(k,v)|h.merge(external_key_form(k) => v)}
  else
    data_keys.each do |k|
      if v = data[internal_key_form(k)]
        ret.merge!(external_key_form(k) => v)
      end
    end
    ret
  end
end
data_ret_and_remove!(*data_keys) click to toggle source
# File lib/response.rb, line 119
def data_ret_and_remove!(*data_keys)
  data = data()
  data_keys.map{|key|data.delete(internal_key_form(key))}
end
error_message() click to toggle source
# File lib/response.rb, line 76
def error_message
  self["errors"] ? (self["errors"].map { |e| e["message"]}).join(', ') : nil
end
ok?() click to toggle source
# File lib/response.rb, line 64
def ok?()
  self[StatusField] == StatusOK
end
set_data(*data_values) click to toggle source
# File lib/response.rb, line 111
def set_data(*data_values)
  self[DataField]=data_values
end
set_data_hash(data_hash) click to toggle source
# File lib/response.rb, line 115
def set_data_hash(data_hash)
  self[DataField]=data_hash
end
validation_actions() click to toggle source
# File lib/response.rb, line 80
def validation_actions
  return self[ValidationField]['actions_needed']
end
validation_message() click to toggle source
# File lib/response.rb, line 72
def validation_message
  self[ValidationField]['message']
end
validation_response?() click to toggle source
# File lib/response.rb, line 68
def validation_response?
  !self[ValidationField].nil?
end

Private Instance Methods

external_key_form(key) click to toggle source
# File lib/response.rb, line 132
def external_key_form(key)
  key.to_sym
end
internal_key_form(key) click to toggle source
# File lib/response.rb, line 129
def internal_key_form(key)
  key.to_s
end