Sha256: b21a7b1d8364f76ae5487fdbdef7e76f19c98dae9d5436f53bbcd76c080cf672
Contents?: true
Size: 567 Bytes
Versions: 7
Compression:
Stored size: 567 Bytes
Contents
module Her module Middleware class ParseJSON < Faraday::Response::Middleware def parse_json(body = nil) body ||= '{}' message = "Response from the API must behave like a Hash or an Array (last JSON response was #{body.inspect})" json = begin MultiJson.load(body, :symbolize_keys => true) rescue MultiJson::LoadError raise Her::Errors::ParseError, message end raise Her::Errors::ParseError, message unless json.is_a?(Hash) or json.is_a?(Array) json end end end end
Version data entries
7 entries across 7 versions & 1 rubygems