Module: OandaAPI::Streaming::Adapters::Generic
Overview
Uses the JSON library. This parser does not handle multiple json objects in a json stream unless the objects are separated with whitespace.
Constant Summary collapse
- DELIMITER =
A delimiter for separating multiple json objects in a stream.
"<oanda_api::delimiter>"
- MULTI_OBJECT_DELIMITER =
"}#{DELIMITER}{"
Instance Method Summary collapse
-
#parse(string) ⇒ Array<Hash>
Deserializes a stream of JSON objects.
Instance Method Details
#parse(string) ⇒ Array<Hash>
Deserializes a stream of JSON objects.
19 20 21 22 23 24 25 |
# File 'lib/oanda_api/streaming/adapters/generic.rb', line 19 def parse(string) string.strip! return [] if string.empty? string.gsub(/}\s*{/, MULTI_OBJECT_DELIMITER).split(DELIMITER).map do |json| JSON.parse json, symbolize_names: true end end |