Sha256: 3eec05b49b6560a301f50dda8d9bd27df1c0d0b4ee33ed314ad9c912566f09d3
Contents?: true
Size: 715 Bytes
Versions: 1
Compression:
Stored size: 715 Bytes
Contents
module BrainstemAdaptor module Parsers module ArrayParser # Parse irregular endpoints that return an array of objects instead of the standard JSON response def self.parse(response_data, collection_name) raise InvalidResponseError, "collection name is not specified" unless collection_name { "count" => response_data.count, "results" => response_data.map do |obj| { "key" => collection_name, "id" => obj["id"].to_s } end, collection_name => response_data.reduce({}) do |hash, obj| hash[obj["id"].to_s] = obj hash end } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
brainstem-adaptor-0.0.4 | lib/brainstem_adaptor/parsers/array_parser.rb |