Module: Tapyrus::RPC

Defined in:
lib/tapyrus/rpc.rb,
lib/tapyrus/rpc/http_server.rb,
lib/tapyrus/rpc/request_handler.rb,
lib/tapyrus/rpc/tapyrus_core_client.rb

Defined Under Namespace

Modules: RequestHandler Classes: Error, HttpServer, TapyrusCoreClient

Class Method Summary collapse

Class Method Details

.convert_floats_to_strings(obj) ⇒ Object

Convert float value



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/tapyrus/rpc/tapyrus_core_client.rb', line 127

def convert_floats_to_strings(obj)
  case obj
  when Float
    obj.to_s
  when Hash
    obj.transform_values { |v| convert_floats_to_strings(v) }
  when Array
    obj.map { |item| convert_floats_to_strings(item) }
  else
    obj
  end
end

.response_body2json(body) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/tapyrus/rpc/tapyrus_core_client.rb', line 116

def response_body2json(body)
  json_data =
    JSON.parse(
      body.gsub(/\\u([\da-fA-F]{4})/) do
        [$1].pack("H*").unpack("n*").pack("U*").encode("ISO-8859-1").force_encoding("UTF-8")
      end
    )
  convert_floats_to_strings(json_data)
end