module OandaAPI::Streaming::Adapters::Generic

Uses the JSON library. This parser does not handle multiple json objects in a json stream

unless the objects are separated with whitespace.

Constants

DELIMITER

A delimiter for separating multiple json objects in a stream.

MULTI_OBJECT_DELIMITER

Public Instance Methods

parse(string) click to toggle source

Deserializes a stream of JSON objects. @param [String] string serialized json. @return [Array<Hash>] an array of hashes.

# 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