Sha256: 49f0c4ac73662f853b1b625a07bdc45b2c4440ae6156ac7d2554f132d2c62f44

Contents?: true

Size: 915 Bytes

Versions: 5

Compression:

Stored size: 915 Bytes

Contents

module OandaAPI
  module Streaming
    #
    # Everything related to `Streaming::Adapters`
    module Adapters
      #
      # Uses the JSON library. This parser does not handle multiple json objects in a json stream
      #  unless the objects are separated with whitespace.
      module Generic
        extend self

        # A delimiter for separating multiple json objects in a stream.
        DELIMITER = "<oanda_api::delimiter>"
        MULTI_OBJECT_DELIMITER = "}#{DELIMITER}{"

        # Deserializes a stream of JSON objects.
        # @param [String] string serialized json.
        # @return [Array<Hash>] an array of hashes.
        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
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
oanda_api-0.9.6 lib/oanda_api/streaming/adapters/generic.rb
oanda_api-0.9.5 lib/oanda_api/streaming/adapters/generic.rb
oanda_api-0.9.4 lib/oanda_api/streaming/adapters/generic.rb
oanda_api-0.9.3 lib/oanda_api/streaming/adapters/generic.rb
oanda_api-0.9.2 lib/oanda_api/streaming/adapters/generic.rb