Class: TingYun::Support::Serialize::Marshaller

Inherits:
Object
  • Object
show all
Defined in:
lib/ting_yun/support/serialize/marshaller.rb

Direct Known Subclasses

JsonMarshaller

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.human_readable?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/ting_yun/support/serialize/marshaller.rb', line 42

def self.human_readable?
  false
end

Instance Method Details

#default_encoderObject



38
39
40
# File 'lib/ting_yun/support/serialize/marshaller.rb', line 38

def default_encoder
  Encoders::Identity
end

#parsed_error(error) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ting_yun/support/serialize/marshaller.rb', line 10

def parsed_error(error)
  error_code = error['errorCode']
  error_message = error['errorMessage']
  case error_code
    when 460
      raise TingYun::Support::Exception::LicenseException.new("#{error_code}: #{error_message}")
    when 461
      raise TingYun::Support::Exception::InvalidDataTokenException.new("#{error_code}: #{error_message}")
    when 462
      raise TingYun::Support::Exception::InvalidDataException.new("#{error_code}: #{error_message}")
    when 470
      raise TingYun::Support::Exception::ExpiredConfigurationException.new("#{error_code}: #{error_message}")
  end
end

#prepare(data, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ting_yun/support/serialize/marshaller.rb', line 25

def prepare(data, options={})
  encoder = options[:encoder] || default_encoder
  if data.respond_to?(:to_collector_array)
    data.to_collector_array(encoder)
  elsif data.kind_of?(Array)
    data.map { |element| prepare(element, options) }
  elsif data.kind_of?(Hash)
    data.each {|_k,_v| data[_k]=prepare(_v, options)}
  else
    data
  end
end

#return_value_for_testing(data) ⇒ Object



46
47
48
# File 'lib/ting_yun/support/serialize/marshaller.rb', line 46

def return_value_for_testing(data)
  return_value(data)
end